Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 3.02 KB

README.md

File metadata and controls

67 lines (46 loc) · 3.02 KB

proxy302

Official Proxy302 SDK for Python: add residential proxies to your own product. Python 3.9+, standard library only, typed.

The API key is your wallet: keep it on your server. Never ship it in a client.

pip install proxy302
import os
from proxy302 import Proxy302

sdk = Proxy302(os.environ["PROXY302_API_KEY"], lang="en")  # "<key id>:<secret>"

print(sdk.get_balance())
proxy = sdk.get_dynamic_proxy("US")
print(proxy.connection.url)  # http://user:pass@host:port

Methods

Method What it does
get_account(), get_balance() Account and wallet (PTC, 1 PTC = US$1)
list_countries(name=None), list_states(country), list_cities(state_id), list_isps(country) Places you can choose
get_prices() Prices for this account: per GB, traffic packages, static IP plans
get_dynamic_proxy(country, ...) A ready connection: reuses a matching proxy of the account, or creates one
create_dynamic_proxy(country, idempotency_key=..., ...) One proxy per end user: the same key returns the same proxy until it is deleted
rotate_ip(token_ids) New IP for sticky dynamic proxies
buy_static_ip(country, days=..., ...) Buys one static IP (charges the wallet)
renew_static_ip(token_id, days=..., ...), set_auto_renew(token_id, on) Renewal (charges the wallet), auto-renewal on or off
list_proxies(kind=..., ...), get_proxy(token_id) My proxies
get_traffic(), get_usage(days=...), get_proxy_usage(token_id) Remaining traffic, usage per day, usage of one proxy
request(method, path, query, body) Any other open API call

Dynamic options: state, city, isp (premium line), line (budget, premium), protocol (http, socks5), session (sticky, rotating), session_minutes (budget line), billing (auto, package, wallet).

Orders are never placed twice

Purchases and renewals take an idempotency_key (generated when left out; returned with the result and on the error). Queries are repeated after a network failure; purchases and renewals never are. If one ends without an answer, call again with the same key: you are not charged twice.

from proxy302 import new_idempotency_key

key = new_idempotency_key("order")  # save it with your order first
ip = sdk.buy_static_ip("US", days=30, idempotency_key=key)

Errors

Every failure is a Proxy302Error with code (for example insufficient_balance), message, next_step (one sentence for the user), retryable, and for logs api_code and api_message. Messages are Chinese by default; pass lang="en" for English.

Your own domain

Point a CNAME at our entry domain, then connection strings carry your domain. Only the host name changes.

Proxy302(api_key, entry_domains={"proxy.proxy302.com": "ip.your-domain.com"})

Not in this version

Top-ups, UI components, calls from a web page, sub-accounts, revenue accounting, read-only keys, and a traffic cap per proxy (not supported in this version).

MIT