Skip to content

QuickProxy

For faster use cases where caching is not required, the swiftshadow.QuickProxy function is the best choice. Unlike the ProxyInterface class, QuickProxy does not cache proxies, making it lightweight and ideal for one-off or quick operations.

swiftshadow.QuickProxy(countries=[], protocol='http')

This function is a faster alternative to ProxyInterface class. No caching is done.

Parameters:

Name Type Description Default
countries list[str]

ISO 3166-2 Two letter country codes to filter proxies.

[]
protocol Literal['http', 'https']

HTTP/HTTPS protocol to filter proxies.

'http'

Returns:

Name Type Description
proxyObject Proxy

A working proxy object if found or else None.

Source code in swiftshadow/__init__.py
def QuickProxy(
    countries: list[str] = [], protocol: Literal["http", "https"] = "http"
) -> Proxy | None:
    """
    This function is a faster alternative to `ProxyInterface` class.
    No caching is done.

    Args:
        countries: ISO 3166-2 Two letter country codes to filter proxies.
        protocol: HTTP/HTTPS protocol to filter proxies.

    Returns:
        proxyObject (Proxy): A working proxy object if found or else None.
    """
    for provider in Providers:
        if protocol not in provider.protocols:
            continue
        if (len(countries) != 0) and (not provider.countryFilter):
            continue
        try:
            return run(provider.providerFunction(countries, protocol))[0]
        except Exception:
            continue
    return None

You can use filters just like in the ProxyInterface class. This includes filtering by country and protocol.

Parameters

  • countries (list[str]): A list of two-letter country codes to filter proxies by country. Defaults to an empty list (no filtering).
  • protocol (Literal["http", "https"]): The protocol to filter proxies by. Defaults to "http".

Returns

  • Proxy | None: A Proxy object if a valid proxy is found, otherwise None.

Example

from swiftshadow import QuickProxy

# Get a random HTTP proxy
proxy = QuickProxy()
print(proxy.as_string())

# Get an HTTPS proxy from the US or India
proxy = QuickProxy(countries=["US", "IN"], protocol="https")
print(proxy.as_string())

Note

Since QuickProxy does not cache proxies, it may take slightly longer to fetch a proxy compared to ProxyInterface when used repeatedly. However, it is faster for single-use scenarios.

Warning

If no proxies match the provided filters, QuickProxy will return None. Always check the return value before using it.


For more advanced use cases, such as caching and automatic rotation, consider using the ProxyInterface class.