     [Answers](https://scrapfly.io/blog)   /  [http](https://scrapfly.io/blog/tag/http)   /  [How to use proxies with Python httpx?](https://scrapfly.io/blog/answers/how-to-use-proxies-python-httpx)   # How to use proxies with Python httpx?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Apr 18, 2026 1 min read [\#http](https://scrapfly.io/blog/tag/http) [\#httpx](https://scrapfly.io/blog/tag/httpx) [\#python](https://scrapfly.io/blog/tag/python) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-python-httpx "Share on LinkedIn")    

 

 

Python's [httpx](https://pypi.org/project/httpx/) HTTP client package supports both HTTP and SOCKS5 proxies. Here's how to use proxies with httpx:

python```python
import httpx
from urllib.parse import quote

# proxy pattern is:
# scheme://username:password@IP:PORT
# For example:
# no auth HTTP proxy:
my_proxy = "http://160.11.12.13:1020"
# or socks5
my_proxy = "http://160.11.12.13:1020|socks5"
# proxy with authentication
my_proxy = "http://my_username:my_password@160.11.12.13:1020"
# note: that username and password should be url quoted if they contain URL sensitive characters like "@":
my_proxy = f"http://{quote('foo@bar.com')}:{quote('password@123')}@160.11.12.13:1020"

proxies = {
    # this proxy will be applied to all http:// urls
    'http://': 'http://160.11.12.13:1020',
    # this proxy will be applied to all https:// urls (not the S)
    'https://': 'http://160.11.12.13:1020',
    # we can also use proxy only for specific pages
    'https://httpbin.dev': 'http://160.11.12.13:1020',
}

with httpx.Client(proxies=proxies) as client:
    r = client.get("https://httpbin.dev/ip")
# or async
async with httpx.AsyncClient(proxies=proxies) as client:
    r = await client.get("https://httpbin.dev/ip")
```



Note that proxy can also be set through the standard `*_PROXY` environment variables:

shell```shell
$ export HTTP_PROXY="http://160.11.12.13:1020"
$ export HTTPS_PROXY="http://160.11.12.13:1020"
$ export ALL_PROXY="socks://160.11.12.13:1020"
$ python
import httpx
# this will use the proxies we set
with httpx.Client() as client:
    r = client.get("https://httpbin.dev/ip")
```



When web scraping, it's best to rotate proxies for each request. For that see our article: [How to Rotate Proxies in Web Scraping](https://scrapfly.io/blog/posts/how-to-rotate-proxies-in-web-scraping)

[How to Web Scrape with HTTPX and PythonIntro to using Python's httpx library for web scraping. Proxy and user agent rotation and common web scraping challenges, tips and tricks.](https://scrapfly.io/blog/posts/web-scraping-with-python-httpx)



 

    



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-python-httpx) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-python-httpx) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-python-httpx) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-python-httpx) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-python-httpx) 



 ## Related Articles

 [  

 python httpx 

### How to Web Scrape with HTTPX and Python

Intro to using Python's httpx library for web scraping. Proxy and user agent rotation and common web scraping challenges...

 

 ](https://scrapfly.io/blog/posts/web-scraping-with-python-httpx) [     

 proxies 

### SOCKS5 vs HTTP Proxy: Key Differences and When to Use Each

A deep dive into the key differences between HTTPS and SOCKS proxies, helping you choose the right protocol for your web...

 

 ](https://scrapfly.io/blog/posts/https-vs-socks-proxies) [  

 http 

### What is HTTP 409 Error? (Conflict)

HTTP status code 409 generally means a conflict or mismatch with the server state. Learn why it happens and how to avoid...

 

 ](https://scrapfly.io/blog/posts/what-is-http-409-status-code-conflict) 

  ## Related Questions

- [ Q Python httpx vs requests vs aiohttp - key differences ](https://scrapfly.io/blog/answers/httpx-vs-requests-vs-aiohttp)
- [ Q HTTP vs HTTPS in web scraping ? ](https://scrapfly.io/blog/answers/http-vs-https-in-web-scraping)
- [ Q What are SOCKS5 proxies and how they compare to HTTP proxies? ](https://scrapfly.io/blog/answers/what-are-socks5-proxies-in-web-scraping)
- [ Q How to use proxies with PHP Guzzle? ](https://scrapfly.io/blog/answers/how-to-use-proxies-php-guzzle)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)