Skip to content

Repository files navigation

Proxy Examples

Example code for using proxy servers in different programming languages. Currently we have examples for these languages:

  • Python
  • JavaScript / Node.js
  • Ruby
  • PHP

Python Proxy Examples

Installation:

pip install -r python/requirements.txt

pycurl needs libcurl and curl-config (for example Debian/Ubuntu: libcurl4-openssl-dev). The test runner skips pycurl-* examples when pycurl is not installed, and skips scrapy-proxy when import scrapy fails (for example a broken cryptography / cffi install).

Running Examples:

# Required: Set your proxy URLexport PROXY_URL='http://user:pass@proxy.example.com:8080'# Optional: Target URL (default: https://api.ipify.org?format=json)export TEST_URL='https://httpbin.org/ip'# Optional: Print one response headerexport RESPONSE_HEADER='X-ProxyMesh-IP'# Single example
python python/requests-proxy.py
# All examples as tests
python python/run_tests.py
# Specific examples (substring match, like the JS runner)
python python/run_tests.py requests httpx

Examples:

LibraryExampleDescription
requestsrequests-proxy.pyBasic GET with proxies=
requestsrequests-session-proxy.pySession with pooled connections
urllib3urllib3-proxy.pyProxyManager
aiohttpaiohttp-proxy.pyAsync client, proxy= on the request
httpxhttpx-proxy.pySync client, proxy= on the client
httpxhttpx-async-proxy.pyAsync client
pycurlpycurl-proxy.pylibcurl via setopt (PROXY, WRITEDATA, etc.)
cloudscrapercloudscraper-proxy.pyRequests-based scraper with proxies
autoscraperautoscraper-proxy.pyOffline html= demo (matches upstream tests); README shows request_args + proxies for live URLs
Scrapyscrapy-proxy.pyscrapy runspider with meta['proxy']

Other Python scripts

Note: Like the Ruby, JavaScript, and PHP examples here, these scripts use each library's normal proxy options only. Most of them do not send custom headers on the HTTPS CONNECT tunnel or surface proxy CONNECT response headers. For that, see python-proxy-headers or scrapy-proxy-headers.

JavaScript / Node.js Proxy Examples

Installation:

cd javascript
npm install

Running Examples:

# Required: Set your proxy URLexport PROXY_URL='http://user:pass@proxy.example.com:8080'# Run a single example
node javascript/axios-proxy.js
# Run all examples as tests
node javascript/run_tests.js
# Run specific examples
node javascript/run_tests.js axios got

Examples:

LibraryExampleDescription
axiosaxios-proxy.jsPopular promise-based HTTP client
node-fetchnode-fetch-proxy.jsFetch API for Node.js
gotgot-proxy.jsHuman-friendly HTTP client
undiciundici-proxy.jsFast HTTP client (powers Node.js fetch)
superagentsuperagent-proxy.jsFlexible HTTP client
needleneedle-proxy.jsLean HTTP client
puppeteerpuppeteer-proxy.jsHeadless Chrome automation
playwrightplaywright-proxy.jsBrowser automation
cheeriocheerio-proxy.jsHTML parsing with node-fetch
kyky-proxy.jsFetch wrapper (node-fetch + agent)
wretchwretch-proxy.jsFetch wrapper (polyfill)
make-fetch-happenmake-fetch-happen-proxy.jsnpm-style fetch
typed-rest-clienttyped-rest-client-proxy.jsREST client (built-in proxy option)

Note: None of these libraries currently support sending custom headers to the proxy during HTTPS CONNECT tunneling or reading proxy response headers. See javascript-proxy-headers for extension modules that add this capability.

Ruby Proxy Examples

These examples use Bundler. Install Ruby development headers and libcurl first so native extensions can compile (Debian/Ubuntu: ruby-dev and libcurl4-openssl-dev; Fedora: ruby-devel and libcurl-devel).

cd ruby
bundle install

Running examples:

# Required: set your proxy URLexport PROXY_URL='http://user:pass@proxy.example.com:8080'# Optional: target URL (default: https://api.ipify.org?format=json)export TEST_URL='https://httpbin.org/ip'# Optional: print one response headerexport RESPONSE_HEADER='X-ProxyMesh-IP'# Single example (from ruby/)
bundle exec ruby faraday-proxy.rb
# All examples as tests
bundle exec ruby run_tests.rb
# Specific examples
bundle exec ruby run_tests.rb faraday typhoeus

Examples:

LibraryExampleDescription
Net::HTTP (stdlib)net-http-proxy.rbLow-level HTTP with proxy (Net::HTTP.new + proxy host/port/user/pass)
Faradayfaraday-proxy.rbMiddleware-style client; Faraday.new(proxy: url)
HTTPartyhttparty-proxy.rbSimple API; http_proxyaddr / http_proxyport / credentials
HTTP.rbhttp-rb-proxy.rbLightweight DSL; proxy via HTTP.via(host, port, user, pass)
RestClientrest-client-proxy.rbSimple REST API; proxy via RestClient.proxy = url
Typhoeustyphoeus-proxy.rblibcurl via Ethon; proxy: URL on the request
Exconexcon-proxy.rbFast client; Excon.get(url, proxy: url)
HTTPClienthttpclient-proxy.rbLWP-like client; pass full proxy URL to HTTPClient.new
Mechanizemechanize-proxy.rbCrawling / forms; set_proxy(host, port, user, password)
Nokogirinokogiri-proxy.rbParse HTML after a proxied Net::HTTP fetch

Libraries above are actively maintained on RubyGems (releases within the last year as of early 2026). Like most high-level Ruby HTTP clients, they do not expose custom headers on the HTTPS CONNECT tunnel to the proxy or proxy response headers; for ProxyMesh-style custom proxy headers, lower-level clients or a dedicated helper library may be required.

PHP Proxy Examples

Installation:

cd php
composer install

Running Examples:

# Required: Set your proxy URLexport PROXY_URL='http://user:pass@proxy.example.com:8080'# Run a single example
php php/guzzle_proxy.php
# Run all examples as tests
php php/run_tests.php

Examples:

LibraryExampleDescription
cURLcurl_proxy.phpPHP's built-in HTTP client (libcurl)
Guzzleguzzle_proxy.phpMost popular PHP HTTP client
Symfony HttpClientsymfony_http_client_proxy.phpModern PSR-18 HTTP client
Buzzbuzz_proxy.phpSimple PSR-18 HTTP client
PHP Streamsstreams_proxy.phpBuilt-in PHP streams (file_get_contents)
Amp HTTPamphp_proxy.phpAsync HTTP client

Note: See php-proxy-headers for extensions that add custom proxy header support.

These examples use Bundler. Install Ruby development headers and libcurl first so native extensions can compile (Debian/Ubuntu: ruby-dev and libcurl4-openssl-dev; Fedora: ruby-devel and libcurl-devel).

cd ruby
bundle install

Running examples:

# Required: set your proxy URLexport PROXY_URL='http://user:pass@proxy.example.com:8080'# Optional: target URL (default: https://api.ipify.org?format=json)export TEST_URL='https://httpbin.org/ip'# Optional: print one response headerexport RESPONSE_HEADER='X-ProxyMesh-IP'# Single example (from ruby/)
bundle exec ruby faraday-proxy.rb
# All examples as tests
bundle exec ruby run_tests.rb
# Specific examples
bundle exec ruby run_tests.rb faraday typhoeus

Examples:

LibraryExampleDescription
Net::HTTP (stdlib)net-http-proxy.rbLow-level HTTP with proxy (Net::HTTP.new + proxy host/port/user/pass)
Faradayfaraday-proxy.rbMiddleware-style client; Faraday.new(proxy: url)
HTTPartyhttparty-proxy.rbSimple API; http_proxyaddr / http_proxyport / credentials
HTTP.rbhttp-rb-proxy.rbLightweight DSL; proxy via HTTP.via(host, port, user, pass)
RestClientrest-client-proxy.rbSimple REST API; proxy via RestClient.proxy = url
Typhoeustyphoeus-proxy.rblibcurl via Ethon; proxy: URL on the request
Exconexcon-proxy.rbFast client; Excon.get(url, proxy: url)
HTTPClienthttpclient-proxy.rbLWP-like client; pass full proxy URL to HTTPClient.new
Mechanizemechanize-proxy.rbCrawling / forms; set_proxy(host, port, user, password)
Nokogirinokogiri-proxy.rbParse HTML after a proxied Net::HTTP fetch

Libraries above are actively maintained on RubyGems (releases within the last year as of early 2026). Like most high-level Ruby HTTP clients, they do not expose custom headers on the HTTPS CONNECT tunnel to the proxy or proxy response headers; for ProxyMesh-style custom proxy headers, lower-level clients or a dedicated helper library may be required.

Related Documentation

More examples and language-specific proxy-header tooling:

Python

JavaScript / Node.js

Ruby

  • Ruby examples in this repository: ruby/

Contributing

Contributions are welcome for all supported languages in this repository (Python, JavaScript, Ruby, and PHP), as well as new language examples.

When opening a Pull Request:

  • Follow the existing file naming and environment variable patterns (PROXY_URL, TEST_URL, and optional response/proxy header variables).
  • Include runnable examples and update the language section in this README.
  • Add or update the language test runner (run_tests) where applicable.

About

Example code for using proxy servers in different programming languages

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages