Skip to main content

ProxyConfiguration

apify.ProxyConfiguration

Configures a connection to a proxy server with the provided options.

Proxy servers are used to prevent target websites from blocking your crawlers based on IP address rate limits or blacklists. The default servers used by this class are managed by Apify Proxy. To be able to use Apify Proxy, you need an Apify account and access to the selected proxies. If you provide no configuration option, the proxies will be managed automatically using a smart algorithm.

If you want to use your own proxies, use the proxy_urls or new_url_function constructor options. Your list of proxy URLs will be rotated by the configuration, if this option is provided.

Index

Methods

initialize

  • async initialize(): None
  • Load the Apify Proxy password if the API token is provided and check access to Apify Proxy and provided proxy groups.

    Only called if Apify Proxy configuration is used. Also checks if country has access to Apify Proxy groups if the country code is provided.

    You should use the Actor.create_proxy_configuration function to create a pre-initialized ProxyConfiguration instance instead of calling this manually.


    Returns None

new_proxy_info

  • Create a new ProxyInfo object.

    Use it if you want to work with a rich representation of a proxy URL. If you need the URL string only, use ProxyConfiguration.new_url.


    Parameters

    • session_id: int | str | None = None

      Represents the identifier of a proxy session (https://docs.apify.com/proxy#sessions). All the HTTP requests going through the proxy with the same session identifier will use the same target proxy server (i.e. the same IP address). The identifier must not be longer than 50 characters and include only the following: 0-9, a-z, A-Z, ".", "_" and "~".

    Returns ProxyInfo

    Dictionary that represents information about the proxy and its configuration.

new_url

  • async new_url(session_id): str
  • Return a new proxy URL based on provided configuration options and the sessionId parameter.


    Parameters

    • session_id: int | str | None = None

      Represents the identifier of a proxy session (https://docs.apify.com/proxy#sessions). All the HTTP requests going through the proxy with the same session identifier will use the same target proxy server (i.e. the same IP address). The identifier must not be longer than 50 characters and include only the following: 0-9, a-z, A-Z, ".", "_" and "~".

    Returns str

    A string with a proxy URL, including authentication credentials and port number. For example, `http