Before you start
Nefo offers residential proxies in 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials for free in the dashboard proxy generator; only routed traffic consumes your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).
The requests library reads proxy URLs directly, so no extra dependency is needed for HTTP. For SOCKS5, install requests[socks].
- Python 3.9+ with the requests library installed
- requests[socks] installed if you want SOCKS5
- A Nefo account with prepaid bandwidth
- A username/password from /dashboard/generator
- Your target country token
Python requests proxies dict example
Build the proxies dict and pass it to your call:
For SOCKS5, change the scheme and port: socks5h://USERNAME-country-us:[email protected]:11000. The socks5h scheme resolves DNS through the proxy. Swap the country token to target any of 227 countries.
import requests
proxies = {
'http': 'http://USERNAME-country-us:[email protected]:9000',
'https': 'http://USERNAME-country-us:[email protected]:9000',
}
r = requests.get('https://api.ipify.org', proxies=proxies)
print(r.text)Python requests rotating vs sticky proxies
Rotating sessions give a new residential IP per request: HTTP port 9000 or SOCKS5 port 11000. Ideal for spreading many small requests across exits.
Sticky sessions keep one IP from 1 minute up to 24 hours: HTTP port 10000 or SOCKS5 port 12000. Add a token like USERNAME-country-us-session-job5-lifetime-30 and reuse a requests.Session() to keep cookies and IP aligned for a stateful workflow.
Geo-targeting in the requests proxy username
Targeting is driven by username tokens: country across 227 countries, US state and city, or ASN/ISP within a country. Only the username string changes between regions, keeping your code stable.
Fetch data lawfully, respect each site's terms of service, and stay within applicable law and reasonable request rates.
Frequently asked questions
Yes. Install requests[socks] (PySocks) to use socks5h URLs on port 11000 or 12000. Plain HTTP proxies on ports 9000 and 10000 need no extra package.
Use port 10000 with a session token such as USERNAME-country-us-session-abc-lifetime-30 and a shared requests.Session(), so cookies and the IP persist together for up to 24 hours.
socks5h resolves DNS through the proxy instead of locally, which keeps lookups on the residential exit and avoids leaking your real resolver.
Both the http and https keys of the proxies dict must be set. If you only set one, requests to the other scheme go out directly. Verify with https://api.ipify.org through the same dict.
Add state and city tokens to the username. Nefo supports US targeting down to state and city, plus ASN or ISP within a country. See US city-targeted proxies.
Yes. Generating credentials is free; only the traffic you route through the proxy consumes prepaid bandwidth.