Skip to main content

Provider-neutral proxy leases for Python applications.

Project description

cmdop-proxy

cmdop-proxy gives Python applications one provider-neutral contract for acquiring and using bounded proxy leases. It is a client library, not a proxy server and not a scraping framework.

The package intentionally separates two responsibilities:

  • a broker selects and leases an endpoint;
  • the application sends traffic directly through that endpoint with its native HTTP client.

Provider management APIs and account keys do not belong in this package.

Install

pip install cmdop-proxy

SOCKS5 support is installed by default.

Managed production proxy

The normal consumer API does not require a broker URL, pool, provider or target profile. The library reads CMDOP_PROXY_TOKEN or the Docker secret /run/secrets/cmdop_proxy_token, then owns lease, renewal and release:

from cmdop_proxy import ProxySession

async with await ProxySession.open() as proxy:
    async with proxy.async_httpx_client(timeout=30) as client:
        response = await client.get("https://example.com/")

Static/offline use

import asyncio
from datetime import timedelta

from cmdop_proxy import (
    AcquireRequest,
    IdentityMode,
    ProxyEndpoint,
    ProxyProtocol,
    StaticBroker,
    create_async_client,
)


async def main() -> None:
    broker = StaticBroker(
        pools={
            "parser": [
                ProxyEndpoint(
                    endpoint_id="local-1",
                    host="127.0.0.1",
                    port=8080,
                    protocol=ProxyProtocol.HTTP,
                    username="user",
                    password="secret",
                )
            ]
        }
    )
    lease = await broker.acquire(
        AcquireRequest(
            pool="parser",
            purpose="source-acquisition",
            target="example",
            protocols=(ProxyProtocol.HTTP,),
            identity_mode=IdentityMode.FIXED,
            affinity="account-primary",
            ttl=timedelta(minutes=15),
        ),
        idempotency_key="run-001",
    )

    async with create_async_client(lease, timeout=30) as client:
        response = await client.get("https://example.com/")
        response.raise_for_status()


asyncio.run(main())

StaticBroker is deterministic, process-local and network-free. It is useful for tests, local deployments and as the reference semantics for remote broker contract tests. It does not persist leases across process restarts.

Security properties

  • Credentials never appear in endpoint or lease repr output.
  • Proxy URLs percent-encode user information.
  • The library does not set HTTP_PROXY, HTTPS_PROXY or any other global environment variable.
  • Observations are typed categories and cannot carry response bodies, cookies, headers or arbitrary error messages.
  • A renewal preserves identity or fails; it never silently changes endpoint.

Applications should keep leases in memory and persist only the lease ID when a remote broker supports lease recovery.

Cloudflare control plane

CloudflareBroker implements the same async contract over the versioned proxy.sdkrouter.com API. The workload receives only its broker token; provider management keys stay in Worker secrets.

from cmdop_proxy import CloudflareBroker

async with CloudflareBroker(
    token=workload_token,
) as broker:
    lease = await broker.acquire(request, idempotency_key="parser-run-001")

The broker token is excluded from repr, remote error messages are mapped to stable typed exceptions, and arbitrary response bodies are never copied into exceptions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmdop_proxy-0.1.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmdop_proxy-0.1.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file cmdop_proxy-0.1.1.tar.gz.

File metadata

  • Download URL: cmdop_proxy-0.1.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for cmdop_proxy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 53a42cac3f5d430834c9c10dcafee2dfed1b351bc8e1e1424c4f5a2fd22cf21a
MD5 32ae81fe340776024e17dc5955c6720c
BLAKE2b-256 87b198b7cf356cf41dba640e112ad5d06ffebd2b9afca97af503de199f91e978

See more details on using hashes here.

File details

Details for the file cmdop_proxy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cmdop_proxy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for cmdop_proxy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3104ddedaed69bca2327ce4d7227c7dd54b7dd62b1165e7c64ad8b5022b6f23e
MD5 76ab478ccddabb78accf6ea91b42e53c
BLAKE2b-256 98d91bcab63d6ac2f91b3f15efaf86749f9169999cc88ad5353c8177126f1aa2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page