sub2api 0.3.0__tar.gz → 0.3.1__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.
- {sub2api-0.3.0 → sub2api-0.3.1}/PKG-INFO +2 -2
- {sub2api-0.3.0 → sub2api-0.3.1}/README.md +1 -1
- {sub2api-0.3.0 → sub2api-0.3.1}/pyproject.toml +1 -1
- {sub2api-0.3.0 → sub2api-0.3.1}/src/sub2api/__init__.py +1 -1
- {sub2api-0.3.0 → sub2api-0.3.1}/src/sub2api/_client.py +0 -1
- {sub2api-0.3.0 → sub2api-0.3.1}/tests/test_client.py +36 -0
- {sub2api-0.3.0 → sub2api-0.3.1}/LICENSE +0 -0
- {sub2api-0.3.0 → sub2api-0.3.1}/src/sub2api/_exceptions.py +0 -0
- {sub2api-0.3.0 → sub2api-0.3.1}/src/sub2api/_models.py +0 -0
- {sub2api-0.3.0 → sub2api-0.3.1}/src/sub2api/_resources.py +0 -0
- {sub2api-0.3.0 → sub2api-0.3.1}/src/sub2api/_token_store.py +0 -0
- {sub2api-0.3.0 → sub2api-0.3.1}/src/sub2api/py.typed +0 -0
- {sub2api-0.3.0 → sub2api-0.3.1}/tests/test_resources.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sub2api
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Python client for the user-facing API of Sub2API instances
|
|
5
5
|
Author: Eight Labs
|
|
6
6
|
License-Expression: MIT
|
|
@@ -62,7 +62,7 @@ print(client.balance().balance)
|
|
|
62
62
|
|
|
63
63
|
Pass either the instance origin or its full `/api/v1` URL. By default, the client keeps its tokens in memory and attempts renewal after an authenticated `401` if it has a refresh token. Supplying `expires_at` as a Unix timestamp also enables proactive renewal within 30 seconds of expiry.
|
|
64
64
|
|
|
65
|
-
The default browser fingerprint is Chrome. You can choose another `
|
|
65
|
+
The default browser fingerprint is Chrome. The selected `curl_cffi` browser profile also supplies the default `User-Agent`. You can choose another profile, set a custom `User-Agent`, or configure proxies with your own `curl_cffi.requests.Session`.
|
|
66
66
|
|
|
67
67
|
```python
|
|
68
68
|
from curl_cffi import requests
|
|
@@ -33,7 +33,7 @@ print(client.balance().balance)
|
|
|
33
33
|
|
|
34
34
|
Pass either the instance origin or its full `/api/v1` URL. By default, the client keeps its tokens in memory and attempts renewal after an authenticated `401` if it has a refresh token. Supplying `expires_at` as a Unix timestamp also enables proactive renewal within 30 seconds of expiry.
|
|
35
35
|
|
|
36
|
-
The default browser fingerprint is Chrome. You can choose another `
|
|
36
|
+
The default browser fingerprint is Chrome. The selected `curl_cffi` browser profile also supplies the default `User-Agent`. You can choose another profile, set a custom `User-Agent`, or configure proxies with your own `curl_cffi.requests.Session`.
|
|
37
37
|
|
|
38
38
|
```python
|
|
39
39
|
from curl_cffi import requests
|
|
@@ -5,6 +5,7 @@ import threading
|
|
|
5
5
|
import time
|
|
6
6
|
from concurrent.futures import ThreadPoolExecutor
|
|
7
7
|
from email.utils import formatdate
|
|
8
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
8
9
|
from typing import Any
|
|
9
10
|
|
|
10
11
|
import httpx
|
|
@@ -85,6 +86,41 @@ def test_balance_uses_bearer_token_and_timezone() -> None:
|
|
|
85
86
|
assert str(balance.total_recharged) == "30"
|
|
86
87
|
|
|
87
88
|
|
|
89
|
+
@pytest.mark.parametrize(
|
|
90
|
+
("profile", "headers", "expected"),
|
|
91
|
+
[
|
|
92
|
+
("chrome", None, "Chrome/"),
|
|
93
|
+
("safari", None, "Version/"),
|
|
94
|
+
("chrome", {"User-Agent": "custom-agent/1.0"}, "custom-agent/1.0"),
|
|
95
|
+
],
|
|
96
|
+
)
|
|
97
|
+
def test_user_agent_uses_the_browser_profile_or_explicit_header(
|
|
98
|
+
profile: str, headers: dict[str, str] | None, expected: str
|
|
99
|
+
) -> None:
|
|
100
|
+
class HeaderHandler(BaseHTTPRequestHandler):
|
|
101
|
+
def do_GET(self) -> None:
|
|
102
|
+
body = json.dumps({"user_agent": self.headers.get("User-Agent")}).encode()
|
|
103
|
+
self.send_response(200)
|
|
104
|
+
self.send_header("Content-Type", "application/json")
|
|
105
|
+
self.send_header("Content-Length", str(len(body)))
|
|
106
|
+
self.end_headers()
|
|
107
|
+
self.wfile.write(body)
|
|
108
|
+
|
|
109
|
+
with HTTPServer(("127.0.0.1", 0), HeaderHandler) as server, ThreadPoolExecutor(1) as pool:
|
|
110
|
+
server.timeout = 5
|
|
111
|
+
handler = pool.submit(server.handle_request)
|
|
112
|
+
with Sub2API(
|
|
113
|
+
f"http://127.0.0.1:{server.server_port}", impersonate=profile, timeout=5
|
|
114
|
+
) as client:
|
|
115
|
+
result = client.request("GET", "settings/public", authenticated=False, headers=headers)
|
|
116
|
+
handler.result(timeout=5)
|
|
117
|
+
|
|
118
|
+
if headers is None:
|
|
119
|
+
assert expected in result["user_agent"]
|
|
120
|
+
else:
|
|
121
|
+
assert result["user_agent"] == expected
|
|
122
|
+
|
|
123
|
+
|
|
88
124
|
def test_login_stores_tokens_and_returns_user() -> None:
|
|
89
125
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
90
126
|
assert request.url.path == "/api/v1/auth/login"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|