What is HTTPX?

HTTPX library is a Python tool that lets you send web requests. It supports both regular and async requests, works with HTTP/1.1 and HTTP/2, and handles things like redirects, timeouts, and cookies out of the box.

It’s a great choice for web scraping or working with APIs, especially when speed and reliability matter. HTTPX also works well with proxy services like Oxylabs, making it easy to hide your IP and avoid blocks when accessing websites at scale.

How to Set Your Proxy With HTTPX in Python

Here’s a simple HTTPX script you can build on by adding proxy settings.

import httpx

r = httpx.get("https://httpbin.io/ip")

print(r.text)

This snippet sends a single request to HTTPbin (a test site that shows your IP) and prints the response. Since there’s no proxy server connected yet, it shows your real IP, making it easy to spot any changes you apply.

How to set up Residential Proxies

Type: HTTP, HTTPS, or SOCKS5

If you want to set up proxies where authentication is necessary (meaning, they're not from a free proxy list), your proxy URL will look like this: 

http://<username>:<password>@<server>:<port_number>

To set up Residential Proxies, just enter the following details:

<username>: your username
<password>: your password

Server: pr.oxylabs.io

Port number: 7777

import httpx

    # define your proxy settings
proxy_url = "http://<username>:<password>@pr.oxylabs.io:7777"
 
# create a client with the specified proxy and credentials
with httpx.Client(proxy=proxy_url) as client:
    # make requests using the client
    r = client.get("https://httpbin.io/ip")
 
print(r.text)

Run the code, and you’ll see the new IP address printed in your terminal. 

You can also use country-specific entries. For example, entering ca-pr.oxylabs.io under host and 30000 under port will acquire a Canadian exit node. Please refer to our documentation for a complete list of country-specific entry nodes or if you need a sticky session.

How to set up SOCKS5 proxies

Since Oxylabs Residential Proxies (and other different proxy types) support SOCKS5, keep in mind that using this protocol requires an extra third-party library to be installed first. 

If HTTPS/HTTP proxy integration is not enough and you find yourself needing SOCKS5 for your setup, you can add support with a quick pip install:

$ pip install httpx[socks]

Once that’s done, you can configure your HTTPX client to route requests through a SOCKS proxy:

import httpx

proxy_url = "socks5://<username>:<password>@<server>:<port_number>"

with httpx.Client(proxy=proxy_url) as client:

    r = client.get("https://httpbin.io/ip")

print(r.text)

Just take note that now the proxy_url part has socks5 instead of http in the url.

Other proxy types

Datacenter proxies

Type: HTTP, HTTPS, or SOCKS5

<username>: your username
<password>: your password

Server: dc.oxylabs.io

Port number: 8001

proxy_url = "http://<username>:<password>@dc.oxylabs.io:8000"

For the Pay-per-IP subscription, the port corresponds to the sequential number assigned to an IP address from the provided list. Hence, port 8001 uses the first IP address on your list. See our Datacenter Proxy List documentation for further details.

For the Pay-per-traffic subscription, port 8001 randomly selects an IP address but remains consistent throughout a session. You can also specify geo-location, such as the US, in the user authentication string: user-USERNAME-country-US:PASSWORD. For more details, see our IP control documentation.

If you’re thinking of using HTTPX with proxies, you can start with free proxies from Oxylabs – just sign up on the Dashboard to claim Datacenter Proxies at no cost.

Enterprise Dedicated Datacenter Proxies

Type: HTTP or SOCKS5

<username>: your username
<password>: your password
Server: a specific IP address (e.g., 1.2.3.4)
Port number: 60000

proxy_url = "http://<username>:<password>@1.2.3.4:60000"

For Enterprise Dedicated Datacenter Proxies, you’ll have to choose an IP from the acquired list. Visit our Enterprise Proxy Lists documentation for more details.

Self-Service Dedicated Datacenter Proxies

Type: HTTP, HTTPS, or SOCKS5
<username>: your username
<password>: your password
Server: ddc.oxylabs.io
Port number: 8001

proxy_url = "http://<username>:<password>@ddc.oxylabs.io:8001"

For Self-Service Dedicated Datacenter Proxies, the port indicates the sequential number of an IP address from the acquired list. Check our Self-Service Proxy Lists documentation for more details.

Mobile proxies

Type: HTTP, HTTPS, or SOCKS5

<username>: your username
<password>: your password
Server: pr.oxylabs.io
Port number: 7777

proxy_url = "http://<username>:<password>@pr.oxylabs.io:7777"

Mobile Proxies work by routing internet traffic through mobile devices, such as smartphones or tablets. Take a look at our Mobile Proxies documentation to explore more advanced control features.

ISP proxies

Type: HTTP, HTTPS, or SOCKS5

<username>: your username
<password>: your password
Server: isp.oxylabs.io
Port number: 8001

proxy_url = "http://<username>:<password>@isp.oxylabs.io:8001"

ISP Proxies are IP addresses hosted on a data center but registered under ISPs (Internet Service Providers). Check our ISP Proxies documentation for more control options.

Wrap up

The an HTTPX proxy integration ensures smoother, more anonymous web requests – perfect for scaling scraping or automation tasks.

Take a look at our other integrations if you want to learn how to set up proxies for various operating systems, data extraction tools, and browsers. Additionally, take a look at our blog, where you can find plenty of educational articles, such as:

HTTPX vs Requests vs AIOHTTP

How to Run a Python Script

Python Web Scraping Tutorial: Step-By-Step

Best Proxy Providers

If you have questions regarding Oxylabs proxies, whether free proxies or paid proxy servers, please contact us via the live chat on our homepage or email us for more information.

Please be aware that this is a third-party tool not owned or controlled by Oxylabs. Each third-party provider is responsible for its own software and services. Consequently, Oxylabs will have no liability or responsibility to you regarding those services. Please carefully review the third party's policies and practices and/or conduct due diligence before accessing or using third-party services.

Get the latest news from data gathering world

I'm interested