ProxyProviders Models

class proxyproviders.models.proxy.ProxyFormat(*values)[source]

Bases: Enum

Supported proxy output formats.

REQUESTS = 'requests'

Requests format, for use in requests library HTTP calls

CURL = 'curl'

CURL format, for use in curl commands

HTTPX = 'httpx'

HTTPX format, for use in httpx library HTTP calls

AIOHTTP = 'aiohttp'

AIOHTTP format, for use in aiohttp library HTTP calls

URL = 'url'

URL format, for use in URL strings

class proxyproviders.models.proxy.Proxy(id: str, username: str, password: str, proxy_address: str, port: int, country_code: str | None = None, city_name: str | None = None, created_at: datetime | None = None, protocols: List[str] | None = None)[source]

Bases: object

Our shared data model for a proxy object across all providers.

id: str

A unique identifier for the proxy

username: str

The username required for authenticating with the proxy

password: str

The password required for authenticating with the proxy

proxy_address: str

The IP address or domain name of the proxy

port: int

The port number through which the proxy connection is established

country_code: str | None = None

The country code where the proxy is located, e.g., ‘US’, ‘FR’. Optional

city_name: str | None = None

The city name where the proxy is located, e.g., ‘New York’, ‘Paris’. Optional

created_at: datetime | None = None

The timestamp when the proxy was created. Optional

protocols: List[str] | None = None

A list of connection protocols supported by the proxy, e.g., [‘http’, ‘https’]

to_url(protocol: str = 'http') str[source]

Convert proxy to URL format for use with HTTP clients.

Parameters:

protocol – The protocol to use in the URL (default: ‘http’)

Returns:

Proxy URL in format ‘protocol://username:password@host:port’

Example

>>> proxy.to_url()
'http://user:pass@192.168.1.1:8080'
>>> proxy.to_url('https')
'https://user:pass@192.168.1.1:8080'
format(format_type: ProxyFormat | str = ProxyFormat.URL, **kwargs) str | Dict[str, str] | List[str][source]

Format proxy for different HTTP clients and tools.

Parameters:
  • format_type – Output format (default: URL string)

  • kwargs – Format-specific options

Returns:

Formatted proxy data

Examples

>>> proxy.format()  # Default URL string
'http://user:pass@192.168.1.1:8080'
>>> proxy.format(ProxyFormat.REQUESTS)
{'http': 'http://user:pass@192.168.1.1:8080', 'https': 'http://user:pass@192.168.1.1:8080'}
>>> proxy.format('curl')  # String also works
['-x', 'http://user:pass@192.168.1.1:8080']
>>> proxy.format(ProxyFormat.HTTPX)
{'http://': 'http://user:pass@192.168.1.1:8080', 'https://': 'http://user:pass@192.168.1.1:8080'}