proxylayer 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proxylayer-0.1.0/PKG-INFO +109 -0
- proxylayer-0.1.0/README.md +80 -0
- proxylayer-0.1.0/pyproject.toml +3 -0
- proxylayer-0.1.0/setup.cfg +4 -0
- proxylayer-0.1.0/setup.py +40 -0
- proxylayer-0.1.0/src/proxylayer/__init__.py +10 -0
- proxylayer-0.1.0/src/proxylayer/client.py +277 -0
- proxylayer-0.1.0/src/proxylayer.egg-info/PKG-INFO +109 -0
- proxylayer-0.1.0/src/proxylayer.egg-info/SOURCES.txt +9 -0
- proxylayer-0.1.0/src/proxylayer.egg-info/dependency_links.txt +1 -0
- proxylayer-0.1.0/src/proxylayer.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: proxylayer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zero-dependency Python client for the ProxyLayer API
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: ProxyLayer
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://proxy-layer.com
|
|
9
|
+
Project-URL: Documentation, https://docs.proxy-layer.com/sdk
|
|
10
|
+
Project-URL: Repository, https://github.com/Twayzz77/proxy-layer.com/tree/main/packages/python-sdk
|
|
11
|
+
Keywords: proxylayer,proxy,api,isp,residential
|
|
12
|
+
Platform: UNKNOWN
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# ProxyLayer Python SDK
|
|
29
|
+
|
|
30
|
+
Zero-dependency Python client for the ProxyLayer REST API. It uses only Python's standard library and returns the API's JSON dictionaries with their original camelCase fields.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install proxylayer
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Python 3.10 or later is required. Set a read-only or full-access API key:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
export PROXYLAYER_API_KEY="pl_live_..."
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Use a full-access key to create purchases. Keep API keys in environment variables or a secret manager; never commit them.
|
|
45
|
+
|
|
46
|
+
## Quote a purchase and create checkout
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import os
|
|
50
|
+
import uuid
|
|
51
|
+
|
|
52
|
+
from proxylayer import ProxyLayer, ProxyLayerError
|
|
53
|
+
|
|
54
|
+
client = ProxyLayer(api_key=os.environ["PROXYLAYER_API_KEY"])
|
|
55
|
+
purchase = {
|
|
56
|
+
"productSlug": "isp",
|
|
57
|
+
"durationDays": 30,
|
|
58
|
+
"items": [{"countryCode": "US", "quantity": 2}],
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
quote = client.quote(purchase)
|
|
63
|
+
print("Current quote in USD cents:", quote["amountCents"])
|
|
64
|
+
|
|
65
|
+
checkout = client.create_checkout(
|
|
66
|
+
purchase=purchase,
|
|
67
|
+
payment_method="stripe",
|
|
68
|
+
client_operation_id=str(uuid.uuid4()),
|
|
69
|
+
)
|
|
70
|
+
print("Checkout:", checkout["checkoutSessionId"])
|
|
71
|
+
print("Payment URL:", checkout.get("paymentUrl"))
|
|
72
|
+
except ProxyLayerError as error:
|
|
73
|
+
print(error.status, error.code, error, error.issues)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A quote does not reserve a price or availability. Stripe and crypto checkouts return payment instructions; `payment_method="balance"` spends wallet funds immediately. For safe retries, save the `client_operation_id` and reuse it with the same purchase when the result is unknown.
|
|
77
|
+
|
|
78
|
+
## Read account data
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
balance = client.get_balance()
|
|
82
|
+
orders = client.list_orders(limit=10)
|
|
83
|
+
inventory = client.list_static_proxies(product="isp", limit=10)
|
|
84
|
+
residential = client.get_residential_proxies(
|
|
85
|
+
country="us",
|
|
86
|
+
session="sticky",
|
|
87
|
+
quantity=5,
|
|
88
|
+
format="socks5://login:password@ip:port",
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Static inventory and residential results include proxy credentials. Do not log or expose them.
|
|
93
|
+
|
|
94
|
+
## Client methods
|
|
95
|
+
|
|
96
|
+
- `get_catalog(product=None)` — public catalog and prices.
|
|
97
|
+
- `quote(purchase)` — calculate a current price for a purchase, supported renewal, or Residential traffic.
|
|
98
|
+
- `request_otp(email)` / `verify_otp(email=..., code=...)` — obtain an API key by email code; verification authenticates the current client, and returns the key for secure storage if needed.
|
|
99
|
+
- `get_balance()` — wallet balance.
|
|
100
|
+
- `create_checkout(...)` / `get_checkout_status(checkout_session_id)` — payments and delivery status.
|
|
101
|
+
- `list_orders(limit=None, cursor=None)` — paginated order and top-up history.
|
|
102
|
+
- `list_static_proxies(product=..., limit=None, cursor=None)` — ISP, Datacenter, or Mobile inventory.
|
|
103
|
+
- `get_residential_proxies(...)` — traffic status and generated proxy strings.
|
|
104
|
+
|
|
105
|
+
The SDK intentionally does not persist credentials, refresh OAuth tokens, retry requests automatically, or expose every REST endpoint. Pass an API key or access token to `ProxyLayer`; the caller owns secret storage and token refresh.
|
|
106
|
+
|
|
107
|
+
See the [API reference](https://docs.proxy-layer.com/api-access) and [SDK guide](https://docs.proxy-layer.com/sdk) for request fields and examples in other languages.
|
|
108
|
+
|
|
109
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# ProxyLayer Python SDK
|
|
2
|
+
|
|
3
|
+
Zero-dependency Python client for the ProxyLayer REST API. It uses only Python's standard library and returns the API's JSON dictionaries with their original camelCase fields.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install proxylayer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Python 3.10 or later is required. Set a read-only or full-access API key:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
export PROXYLAYER_API_KEY="pl_live_..."
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Use a full-access key to create purchases. Keep API keys in environment variables or a secret manager; never commit them.
|
|
18
|
+
|
|
19
|
+
## Quote a purchase and create checkout
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import os
|
|
23
|
+
import uuid
|
|
24
|
+
|
|
25
|
+
from proxylayer import ProxyLayer, ProxyLayerError
|
|
26
|
+
|
|
27
|
+
client = ProxyLayer(api_key=os.environ["PROXYLAYER_API_KEY"])
|
|
28
|
+
purchase = {
|
|
29
|
+
"productSlug": "isp",
|
|
30
|
+
"durationDays": 30,
|
|
31
|
+
"items": [{"countryCode": "US", "quantity": 2}],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
quote = client.quote(purchase)
|
|
36
|
+
print("Current quote in USD cents:", quote["amountCents"])
|
|
37
|
+
|
|
38
|
+
checkout = client.create_checkout(
|
|
39
|
+
purchase=purchase,
|
|
40
|
+
payment_method="stripe",
|
|
41
|
+
client_operation_id=str(uuid.uuid4()),
|
|
42
|
+
)
|
|
43
|
+
print("Checkout:", checkout["checkoutSessionId"])
|
|
44
|
+
print("Payment URL:", checkout.get("paymentUrl"))
|
|
45
|
+
except ProxyLayerError as error:
|
|
46
|
+
print(error.status, error.code, error, error.issues)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
A quote does not reserve a price or availability. Stripe and crypto checkouts return payment instructions; `payment_method="balance"` spends wallet funds immediately. For safe retries, save the `client_operation_id` and reuse it with the same purchase when the result is unknown.
|
|
50
|
+
|
|
51
|
+
## Read account data
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
balance = client.get_balance()
|
|
55
|
+
orders = client.list_orders(limit=10)
|
|
56
|
+
inventory = client.list_static_proxies(product="isp", limit=10)
|
|
57
|
+
residential = client.get_residential_proxies(
|
|
58
|
+
country="us",
|
|
59
|
+
session="sticky",
|
|
60
|
+
quantity=5,
|
|
61
|
+
format="socks5://login:password@ip:port",
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Static inventory and residential results include proxy credentials. Do not log or expose them.
|
|
66
|
+
|
|
67
|
+
## Client methods
|
|
68
|
+
|
|
69
|
+
- `get_catalog(product=None)` — public catalog and prices.
|
|
70
|
+
- `quote(purchase)` — calculate a current price for a purchase, supported renewal, or Residential traffic.
|
|
71
|
+
- `request_otp(email)` / `verify_otp(email=..., code=...)` — obtain an API key by email code; verification authenticates the current client, and returns the key for secure storage if needed.
|
|
72
|
+
- `get_balance()` — wallet balance.
|
|
73
|
+
- `create_checkout(...)` / `get_checkout_status(checkout_session_id)` — payments and delivery status.
|
|
74
|
+
- `list_orders(limit=None, cursor=None)` — paginated order and top-up history.
|
|
75
|
+
- `list_static_proxies(product=..., limit=None, cursor=None)` — ISP, Datacenter, or Mobile inventory.
|
|
76
|
+
- `get_residential_proxies(...)` — traffic status and generated proxy strings.
|
|
77
|
+
|
|
78
|
+
The SDK intentionally does not persist credentials, refresh OAuth tokens, retry requests automatically, or expose every REST endpoint. Pass an API key or access token to `ProxyLayer`; the caller owns secret storage and token refresh.
|
|
79
|
+
|
|
80
|
+
See the [API reference](https://docs.proxy-layer.com/api-access) and [SDK guide](https://docs.proxy-layer.com/sdk) for request fields and examples in other languages.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from setuptools import find_packages, setup
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="proxylayer",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
description="Zero-dependency Python client for the ProxyLayer API",
|
|
10
|
+
long_description=Path(__file__).with_name("README.md").read_text(encoding="utf-8"),
|
|
11
|
+
long_description_content_type="text/markdown",
|
|
12
|
+
python_requires=">=3.10",
|
|
13
|
+
packages=find_packages("src"),
|
|
14
|
+
package_dir={"": "src"},
|
|
15
|
+
package_data={"proxylayer": ["py.typed"]},
|
|
16
|
+
include_package_data=True,
|
|
17
|
+
install_requires=[],
|
|
18
|
+
license="MIT",
|
|
19
|
+
author="ProxyLayer",
|
|
20
|
+
keywords=["proxylayer", "proxy", "api", "isp", "residential"],
|
|
21
|
+
classifiers=[
|
|
22
|
+
"Development Status :: 3 - Alpha",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Programming Language :: Python :: 3.14",
|
|
33
|
+
"Typing :: Typed",
|
|
34
|
+
],
|
|
35
|
+
project_urls={
|
|
36
|
+
"Homepage": "https://proxy-layer.com",
|
|
37
|
+
"Documentation": "https://docs.proxy-layer.com/sdk",
|
|
38
|
+
"Repository": "https://github.com/Twayzz77/proxy-layer.com/tree/main/packages/python-sdk",
|
|
39
|
+
},
|
|
40
|
+
)
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"""Small standard-library HTTP client for ProxyLayer's versioned REST API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from typing import Any, Literal
|
|
8
|
+
from urllib.error import HTTPError, URLError
|
|
9
|
+
from urllib.parse import quote, urlencode
|
|
10
|
+
from urllib.request import Request, urlopen
|
|
11
|
+
|
|
12
|
+
DEFAULT_BASE_URL = "https://app.proxy-layer.com"
|
|
13
|
+
Product = Literal["isp", "datacenter", "mobile", "residential"]
|
|
14
|
+
FixedProduct = Literal["isp", "datacenter", "mobile"]
|
|
15
|
+
PaymentMethod = Literal["stripe", "crypto", "balance"]
|
|
16
|
+
ProxyFormat = Literal[
|
|
17
|
+
"http://login:password@ip:port",
|
|
18
|
+
"https://login:password@ip:port",
|
|
19
|
+
"socks5://login:password@ip:port",
|
|
20
|
+
"ip:port:login:password",
|
|
21
|
+
]
|
|
22
|
+
JsonObject = dict[str, Any]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ProxyLayerError(RuntimeError):
|
|
26
|
+
"""An API or transport error, with machine-readable status and code."""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
message: str,
|
|
31
|
+
*,
|
|
32
|
+
status: int,
|
|
33
|
+
code: str,
|
|
34
|
+
issues: list[Any] | None = None,
|
|
35
|
+
) -> None:
|
|
36
|
+
super().__init__(message)
|
|
37
|
+
self.status = status
|
|
38
|
+
self.code = code
|
|
39
|
+
self.issues = issues
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ProxyLayer:
|
|
43
|
+
"""Call ProxyLayer's REST API using only Python's standard library.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
api_key: API key. Defaults to ``PROXYLAYER_API_KEY``.
|
|
47
|
+
access_token: OAuth access token. Used when no API key is set.
|
|
48
|
+
base_url: API origin. Defaults to ``PROXYLAYER_BASE_URL`` or the
|
|
49
|
+
production API.
|
|
50
|
+
timeout: Per-request timeout in seconds.
|
|
51
|
+
|
|
52
|
+
Request and response payloads use the API's camelCase field names.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
api_key: str | None = None,
|
|
59
|
+
access_token: str | None = None,
|
|
60
|
+
base_url: str | None = None,
|
|
61
|
+
timeout: float = 30,
|
|
62
|
+
) -> None:
|
|
63
|
+
if timeout <= 0:
|
|
64
|
+
raise ValueError("timeout must be greater than zero")
|
|
65
|
+
self.api_key = (api_key or os.getenv("PROXYLAYER_API_KEY") or "").strip() or None
|
|
66
|
+
self.access_token = access_token.strip() if access_token else None
|
|
67
|
+
self.base_url = (
|
|
68
|
+
base_url or os.getenv("PROXYLAYER_BASE_URL") or DEFAULT_BASE_URL
|
|
69
|
+
).strip().rstrip("/")
|
|
70
|
+
self.timeout = timeout
|
|
71
|
+
|
|
72
|
+
def _request(
|
|
73
|
+
self,
|
|
74
|
+
method: Literal["GET", "POST"],
|
|
75
|
+
path: str,
|
|
76
|
+
*,
|
|
77
|
+
auth: Literal["none", "optional", "required"] = "required",
|
|
78
|
+
query: dict[str, str | int | None] | None = None,
|
|
79
|
+
body: JsonObject | None = None,
|
|
80
|
+
headers: dict[str, str] | None = None,
|
|
81
|
+
) -> JsonObject:
|
|
82
|
+
token = self.api_key or self.access_token
|
|
83
|
+
if auth == "required" and not token:
|
|
84
|
+
raise ProxyLayerError(
|
|
85
|
+
"Authentication required. Set PROXYLAYER_API_KEY or pass api_key.",
|
|
86
|
+
status=401,
|
|
87
|
+
code="UNAUTHORIZED",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
url = f"{self.base_url}/{path.lstrip('/')}"
|
|
91
|
+
if query:
|
|
92
|
+
params = {key: value for key, value in query.items() if value is not None}
|
|
93
|
+
if params:
|
|
94
|
+
url = f"{url}?{urlencode(params)}"
|
|
95
|
+
|
|
96
|
+
request_headers = {"Accept": "application/json", **(headers or {})}
|
|
97
|
+
if token and auth != "none":
|
|
98
|
+
request_headers["Authorization"] = f"Bearer {token}"
|
|
99
|
+
payload = None
|
|
100
|
+
if body is not None:
|
|
101
|
+
request_headers["Content-Type"] = "application/json"
|
|
102
|
+
payload = json.dumps(body, separators=(",", ":")).encode("utf-8")
|
|
103
|
+
request = Request(url, data=payload, headers=request_headers, method=method)
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
with urlopen(request, timeout=self.timeout) as response:
|
|
107
|
+
raw = response.read()
|
|
108
|
+
except HTTPError as error:
|
|
109
|
+
self._raise_api_error(error.read(), error.code)
|
|
110
|
+
except URLError as error:
|
|
111
|
+
raise ProxyLayerError(
|
|
112
|
+
f"Could not connect to ProxyLayer: {error.reason}",
|
|
113
|
+
status=0,
|
|
114
|
+
code="NETWORK_ERROR",
|
|
115
|
+
) from error
|
|
116
|
+
except (TimeoutError, OSError) as error:
|
|
117
|
+
raise ProxyLayerError(
|
|
118
|
+
f"Could not complete ProxyLayer request: {error}",
|
|
119
|
+
status=0,
|
|
120
|
+
code="NETWORK_ERROR",
|
|
121
|
+
) from error
|
|
122
|
+
|
|
123
|
+
if not raw:
|
|
124
|
+
return {}
|
|
125
|
+
try:
|
|
126
|
+
result = json.loads(raw)
|
|
127
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
|
128
|
+
raise ProxyLayerError(
|
|
129
|
+
"ProxyLayer returned an invalid JSON response.",
|
|
130
|
+
status=0,
|
|
131
|
+
code="INVALID_RESPONSE",
|
|
132
|
+
) from error
|
|
133
|
+
if not isinstance(result, dict):
|
|
134
|
+
raise ProxyLayerError(
|
|
135
|
+
"ProxyLayer returned an unexpected response shape.",
|
|
136
|
+
status=0,
|
|
137
|
+
code="INVALID_RESPONSE",
|
|
138
|
+
)
|
|
139
|
+
return result
|
|
140
|
+
|
|
141
|
+
@staticmethod
|
|
142
|
+
def _raise_api_error(raw: bytes, status: int) -> None:
|
|
143
|
+
try:
|
|
144
|
+
result = json.loads(raw) if raw else {}
|
|
145
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
146
|
+
result = {}
|
|
147
|
+
error = result.get("error", {}) if isinstance(result, dict) else {}
|
|
148
|
+
if not isinstance(error, dict):
|
|
149
|
+
error = {}
|
|
150
|
+
message = error.get("message")
|
|
151
|
+
code = error.get("code")
|
|
152
|
+
issues = error.get("issues")
|
|
153
|
+
raise ProxyLayerError(
|
|
154
|
+
message if isinstance(message, str) else f"ProxyLayer API request failed (HTTP {status})",
|
|
155
|
+
status=status,
|
|
156
|
+
code=code if isinstance(code, str) else "API_ERROR",
|
|
157
|
+
issues=issues if isinstance(issues, list) else None,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def get_catalog(self, product: Product | None = None) -> JsonObject:
|
|
161
|
+
"""List products, terms, countries, and USD prices. No auth required."""
|
|
162
|
+
return self._request("GET", "/api/v1/catalog", auth="none", query={"product": product})
|
|
163
|
+
|
|
164
|
+
def quote(self, purchase: JsonObject) -> JsonObject:
|
|
165
|
+
"""Calculate a price; quotes do not reserve availability or price."""
|
|
166
|
+
return self._request("POST", "/api/v1/quotes", auth="optional", body={"purchase": purchase})
|
|
167
|
+
|
|
168
|
+
def request_otp(self, email: str) -> JsonObject:
|
|
169
|
+
"""Send an email verification code for API-key sign-in."""
|
|
170
|
+
return self._request("POST", "/api/v1/auth/otp/request", auth="none", body={"email": email})
|
|
171
|
+
|
|
172
|
+
def verify_otp(
|
|
173
|
+
self,
|
|
174
|
+
*,
|
|
175
|
+
email: str,
|
|
176
|
+
code: str,
|
|
177
|
+
key_name: str | None = None,
|
|
178
|
+
access: Literal["read", "full"] | None = None,
|
|
179
|
+
) -> JsonObject:
|
|
180
|
+
"""Exchange an email code for an API key; store the returned key securely."""
|
|
181
|
+
body: JsonObject = {"email": email, "code": code}
|
|
182
|
+
if key_name:
|
|
183
|
+
body["keyName"] = key_name
|
|
184
|
+
if access:
|
|
185
|
+
body["access"] = access
|
|
186
|
+
result = self._request("POST", "/api/v1/auth/otp/verify", auth="none", body=body)
|
|
187
|
+
api_key = result.get("apiKey")
|
|
188
|
+
if isinstance(api_key, str) and api_key:
|
|
189
|
+
self.api_key = api_key
|
|
190
|
+
return result
|
|
191
|
+
|
|
192
|
+
def get_balance(self) -> JsonObject:
|
|
193
|
+
"""Read the authenticated account's USD wallet balance."""
|
|
194
|
+
return self._request("GET", "/api/v1/balance")
|
|
195
|
+
|
|
196
|
+
def create_checkout(
|
|
197
|
+
self,
|
|
198
|
+
*,
|
|
199
|
+
purchase: JsonObject,
|
|
200
|
+
payment_method: PaymentMethod | None = None,
|
|
201
|
+
crypto_currency: str | None = None,
|
|
202
|
+
crypto_network: str | None = None,
|
|
203
|
+
client_operation_id: str | None = None,
|
|
204
|
+
) -> JsonObject:
|
|
205
|
+
"""Create payment instructions or immediately settle from wallet balance.
|
|
206
|
+
|
|
207
|
+
Reuse ``client_operation_id`` and the same purchase when retrying a
|
|
208
|
+
request whose outcome is unknown.
|
|
209
|
+
"""
|
|
210
|
+
body: JsonObject = {"purchase": purchase}
|
|
211
|
+
if payment_method:
|
|
212
|
+
body["paymentMethod"] = payment_method
|
|
213
|
+
if crypto_currency:
|
|
214
|
+
body["cryptoCurrency"] = crypto_currency
|
|
215
|
+
if crypto_network:
|
|
216
|
+
body["cryptoNetwork"] = crypto_network
|
|
217
|
+
request_headers = None
|
|
218
|
+
if client_operation_id:
|
|
219
|
+
body["clientOperationId"] = client_operation_id
|
|
220
|
+
request_headers = {"Idempotency-Key": client_operation_id}
|
|
221
|
+
return self._request("POST", "/api/v1/checkouts", body=body, headers=request_headers)
|
|
222
|
+
|
|
223
|
+
def get_checkout_status(self, checkout_session_id: str) -> JsonObject:
|
|
224
|
+
"""Read payment and provisioning status for a checkout."""
|
|
225
|
+
return self._request("GET", f"/api/v1/checkouts/{quote(checkout_session_id, safe='')}")
|
|
226
|
+
|
|
227
|
+
def list_orders(self, *, limit: int | None = None, cursor: str | None = None) -> JsonObject:
|
|
228
|
+
"""List paginated orders and top-ups."""
|
|
229
|
+
return self._request("GET", "/api/v1/orders", query={"limit": limit, "cursor": cursor})
|
|
230
|
+
|
|
231
|
+
def list_static_proxies(
|
|
232
|
+
self,
|
|
233
|
+
*,
|
|
234
|
+
product: FixedProduct,
|
|
235
|
+
checkout_session_id: str | None = None,
|
|
236
|
+
limit: int | None = None,
|
|
237
|
+
cursor: str | None = None,
|
|
238
|
+
) -> JsonObject:
|
|
239
|
+
"""List owned ISP, Datacenter, or Mobile proxies and credentials."""
|
|
240
|
+
return self._request(
|
|
241
|
+
"GET",
|
|
242
|
+
"/api/v1/proxies",
|
|
243
|
+
query={
|
|
244
|
+
"product": product,
|
|
245
|
+
"checkoutSessionId": checkout_session_id,
|
|
246
|
+
"limit": limit,
|
|
247
|
+
"cursor": cursor,
|
|
248
|
+
},
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
def get_residential_proxies(
|
|
252
|
+
self,
|
|
253
|
+
*,
|
|
254
|
+
country: str | None = None,
|
|
255
|
+
city: str | None = None,
|
|
256
|
+
region: str | None = None,
|
|
257
|
+
asn: str | None = None,
|
|
258
|
+
session: Literal["sticky", "rotating"] | None = None,
|
|
259
|
+
ttl: int | None = None,
|
|
260
|
+
quantity: int | None = None,
|
|
261
|
+
format: ProxyFormat | None = None,
|
|
262
|
+
) -> JsonObject:
|
|
263
|
+
"""Read traffic status and generate residential proxy strings."""
|
|
264
|
+
return self._request(
|
|
265
|
+
"GET",
|
|
266
|
+
"/api/v1/residential/proxies",
|
|
267
|
+
query={
|
|
268
|
+
"country": country,
|
|
269
|
+
"city": city,
|
|
270
|
+
"region": region,
|
|
271
|
+
"asn": asn,
|
|
272
|
+
"session": session,
|
|
273
|
+
"ttl": ttl,
|
|
274
|
+
"quantity": quantity,
|
|
275
|
+
"format": format,
|
|
276
|
+
},
|
|
277
|
+
)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: proxylayer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zero-dependency Python client for the ProxyLayer API
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: ProxyLayer
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://proxy-layer.com
|
|
9
|
+
Project-URL: Documentation, https://docs.proxy-layer.com/sdk
|
|
10
|
+
Project-URL: Repository, https://github.com/Twayzz77/proxy-layer.com/tree/main/packages/python-sdk
|
|
11
|
+
Keywords: proxylayer,proxy,api,isp,residential
|
|
12
|
+
Platform: UNKNOWN
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# ProxyLayer Python SDK
|
|
29
|
+
|
|
30
|
+
Zero-dependency Python client for the ProxyLayer REST API. It uses only Python's standard library and returns the API's JSON dictionaries with their original camelCase fields.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install proxylayer
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Python 3.10 or later is required. Set a read-only or full-access API key:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
export PROXYLAYER_API_KEY="pl_live_..."
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Use a full-access key to create purchases. Keep API keys in environment variables or a secret manager; never commit them.
|
|
45
|
+
|
|
46
|
+
## Quote a purchase and create checkout
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import os
|
|
50
|
+
import uuid
|
|
51
|
+
|
|
52
|
+
from proxylayer import ProxyLayer, ProxyLayerError
|
|
53
|
+
|
|
54
|
+
client = ProxyLayer(api_key=os.environ["PROXYLAYER_API_KEY"])
|
|
55
|
+
purchase = {
|
|
56
|
+
"productSlug": "isp",
|
|
57
|
+
"durationDays": 30,
|
|
58
|
+
"items": [{"countryCode": "US", "quantity": 2}],
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
quote = client.quote(purchase)
|
|
63
|
+
print("Current quote in USD cents:", quote["amountCents"])
|
|
64
|
+
|
|
65
|
+
checkout = client.create_checkout(
|
|
66
|
+
purchase=purchase,
|
|
67
|
+
payment_method="stripe",
|
|
68
|
+
client_operation_id=str(uuid.uuid4()),
|
|
69
|
+
)
|
|
70
|
+
print("Checkout:", checkout["checkoutSessionId"])
|
|
71
|
+
print("Payment URL:", checkout.get("paymentUrl"))
|
|
72
|
+
except ProxyLayerError as error:
|
|
73
|
+
print(error.status, error.code, error, error.issues)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A quote does not reserve a price or availability. Stripe and crypto checkouts return payment instructions; `payment_method="balance"` spends wallet funds immediately. For safe retries, save the `client_operation_id` and reuse it with the same purchase when the result is unknown.
|
|
77
|
+
|
|
78
|
+
## Read account data
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
balance = client.get_balance()
|
|
82
|
+
orders = client.list_orders(limit=10)
|
|
83
|
+
inventory = client.list_static_proxies(product="isp", limit=10)
|
|
84
|
+
residential = client.get_residential_proxies(
|
|
85
|
+
country="us",
|
|
86
|
+
session="sticky",
|
|
87
|
+
quantity=5,
|
|
88
|
+
format="socks5://login:password@ip:port",
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Static inventory and residential results include proxy credentials. Do not log or expose them.
|
|
93
|
+
|
|
94
|
+
## Client methods
|
|
95
|
+
|
|
96
|
+
- `get_catalog(product=None)` — public catalog and prices.
|
|
97
|
+
- `quote(purchase)` — calculate a current price for a purchase, supported renewal, or Residential traffic.
|
|
98
|
+
- `request_otp(email)` / `verify_otp(email=..., code=...)` — obtain an API key by email code; verification authenticates the current client, and returns the key for secure storage if needed.
|
|
99
|
+
- `get_balance()` — wallet balance.
|
|
100
|
+
- `create_checkout(...)` / `get_checkout_status(checkout_session_id)` — payments and delivery status.
|
|
101
|
+
- `list_orders(limit=None, cursor=None)` — paginated order and top-up history.
|
|
102
|
+
- `list_static_proxies(product=..., limit=None, cursor=None)` — ISP, Datacenter, or Mobile inventory.
|
|
103
|
+
- `get_residential_proxies(...)` — traffic status and generated proxy strings.
|
|
104
|
+
|
|
105
|
+
The SDK intentionally does not persist credentials, refresh OAuth tokens, retry requests automatically, or expose every REST endpoint. Pass an API key or access token to `ProxyLayer`; the caller owns secret storage and token refresh.
|
|
106
|
+
|
|
107
|
+
See the [API reference](https://docs.proxy-layer.com/api-access) and [SDK guide](https://docs.proxy-layer.com/sdk) for request fields and examples in other languages.
|
|
108
|
+
|
|
109
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
proxylayer
|