Skip to main content
Version: 0.2

ProxyConfiguration

{"content": ["Configures a connection to a proxy server with the provided options.\n\nProxy servers are used to prevent target websites from blocking your crawlers based on IP address rate limits or blacklists.\nThe default servers used by this class are managed by Apify Proxy.\nTo be able to use Apify Proxy, you need an Apify account and access to the selected proxies. If you provide no configuration option,\nthe proxies will be managed automatically using a smart algorithm.\n\nIf you want to use your own proxies, use the proxy_urls or new_url_function constructor options.\nYour list of proxy URLs will be rotated by the configuration, if this option is provided."]}

Index

Constructors

__init__

  • __init__(*, password, groups, country_code, proxy_urls, new_url_function, _actor_config, _apify_client): None
  • {"content": ["Create a ProxyConfiguration instance. It is highly recommended to use Actor.create_proxy_configuration() instead of this.\n\nArgs:\n password (str, optional): Password for the Apify Proxy. If not provided, will use os.environ['APIFY_PROXY_PASSWORD'], if available.\n groups (list of str, optional): Proxy groups which the Apify Proxy should use, if provided.\n country_code (str, optional): Country which the Apify Proxy should use, if provided.\n proxy_urls (list of str, optional): Custom proxy server URLs which should be rotated through.\n new_url_function (Callable, optional): Function which returns a custom proxy URL to be used."]}


    Parameters

    • keyword-onlypassword: Optional[str] = None
    • keyword-onlygroups: Optional[List[str]] = None
    • keyword-onlycountry_code: Optional[str] = None
    • keyword-onlyproxy_urls: Optional[List[str]] = None
    • keyword-onlynew_url_function: Optional[Union[Callable[[Optional[str]], str], Callable[[Optional[str]], Awaitable[str]]]] = None
    • keyword-only_actor_config: Optional[Configuration] = None
    • keyword-only_apify_client: Optional[ApifyClientAsync] = None

    Returns None

Methods

initialize

  • async initialize(): None
  • {"content": ["Load the Apify Proxy password if the API token is provided and check access to Apify Proxy and provided proxy groups.\n\nOnly called if Apify Proxy configuration is used.\nAlso checks if country has access to Apify Proxy groups if the country code is provided.\n\nYou should use the Actor.create_proxy_configuration function\nto create a pre-initialized ProxyConfiguration instance instead of calling this manually."]}


    Returns None

new_url

  • async new_url(session_id): str
  • {"content": ["Return a new proxy URL based on provided configuration options and the sessionId parameter.\n\nArgs:\n session_id (int or str, optional): Represents the identifier of a proxy session (https://docs.apify.com/proxy#sessions).\n All the HTTP requests going through the proxy with the same session identifier\n will use the same target proxy server (i.e. the same IP address).\n The identifier must not be longer than 50 characters and include only the following: 0-9, a-z, A-Z, \".\", \"_\" and \"~\".\n\nReturns:\n str: A string with a proxy URL, including authentication credentials and port number.\n For example, http://bob:password123@proxy.example.com:8000"]}


    Parameters

    • session_id: Optional[Union[int, str]] = None

    Returns str

new_proxy_info

  • async new_proxy_info(session_id): ProxyInfo
  • {"content": ["Create a new ProxyInfo object.\n\nUse it if you want to work with a rich representation of a proxy URL.\nIf you need the URL string only, use ProxyConfiguration.new_url.\n\nArgs:\n session_id (int or str, optional): Represents the identifier of a proxy session (https://docs.apify.com/proxy#sessions).\n All the HTTP requests going through the proxy with the same session identifier\n will use the same target proxy server (i.e. the same IP address).\n The identifier must not be longer than 50 characters and include only the following: 0-9, a-z, A-Z, \".\", \"_\" and \"~\".\n\nReturns:\n ProxyInfo: Dictionary that represents information about the proxy and its configuration."]}


    Parameters

    • session_id: Optional[Union[int, str]] = None

    Returns ProxyInfo