|
1 | | -GetFreeProxy Python client |
2 | | -================================= |
| 1 | +GetFreeProxy — Python client |
| 2 | +=========================== |
3 | 3 |
|
4 | | -Install |
5 | | -------- |
| 4 | +This is a small, typed Python client for the GetFreeProxy API (https://developer.getfreeproxy.com). |
| 5 | + |
| 6 | +About the API |
| 7 | +------------- |
| 8 | +The GetFreeProxy API exposes a simple endpoint to fetch public proxy servers: |
| 9 | + |
| 10 | +- GET /v1/proxies — returns a JSON array of proxy objects. Optional query parameters include `country`, `protocol`, and `page`. |
| 11 | + |
| 12 | +Each proxy object contains fields such as `ip`, `port`, `protocol`, `proxyUrl`, `countryCode`, `anonymity`, `uptime`, and timestamps like `lastAliveAt`. |
| 13 | + |
| 14 | +Key behaviours of this client |
| 15 | +---------------------------- |
| 16 | +- Minimal runtime dependency (`httpx`). |
| 17 | +- Synchronous `Client` and asynchronous `AsyncClient` classes with simple `query(...)` methods. |
| 18 | +- Returns a list of `Proxy` dataclasses (fields mapped to Pythonic names, e.g. `country_code`). |
| 19 | +- Raises typed exceptions on errors: `APIError`, `InvalidAPIKey`, `NetworkError`, `TimeoutError`, `ParseError`. |
| 20 | + |
| 21 | +Installation |
| 22 | +------------ |
| 23 | + |
| 24 | +Install from PyPI (when published) or locally in editable mode during development: |
6 | 25 |
|
7 | 26 | ```bash |
8 | | -pip install . |
| 27 | +pip install freeproxy-python |
| 28 | +# or local editable install for development: |
| 29 | +pip install -e .[dev] |
9 | 30 | ``` |
10 | 31 |
|
11 | | -Usage (sync) |
12 | | ------------- |
| 32 | +Quick examples |
| 33 | +-------------- |
| 34 | + |
| 35 | +Sync example: |
13 | 36 |
|
14 | 37 | ```py |
15 | | -from getfreeproxy import FreeProxyClient |
| 38 | +from freeproxy import Client |
16 | 39 |
|
17 | | -client = FreeProxyClient(api_key="YOUR_API_KEY") |
| 40 | +client = Client(api_key="YOUR_API_KEY") |
18 | 41 | proxies = client.query(country="US", protocol="https") |
19 | 42 | for p in proxies: |
20 | | - print(p.proxy_url) |
| 43 | + print(p.to_url()) |
21 | 44 | client.close() |
22 | 45 | ``` |
23 | 46 |
|
24 | | -Usage (async) |
25 | | -------------- |
| 47 | +Async example: |
26 | 48 |
|
27 | 49 | ```py |
28 | 50 | import asyncio |
29 | | -from getfreeproxy import AsyncFreeProxyClient |
| 51 | +from freeproxy import AsyncClient |
30 | 52 |
|
31 | 53 | async def main(): |
32 | | - client = AsyncFreeProxyClient(api_key="YOUR_API_KEY") |
| 54 | + client = AsyncClient(api_key="YOUR_API_KEY") |
33 | 55 | proxies = await client.query(country="US") |
34 | 56 | for p in proxies: |
35 | | - print(p.proxy_url) |
| 57 | + print(p.to_url()) |
36 | 58 | await client.aclose() |
37 | 59 |
|
38 | 60 | asyncio.run(main()) |
39 | 61 | ``` |
40 | 62 |
|
41 | | -Tests |
42 | | ------ |
| 63 | +Authentication |
| 64 | +-------------- |
| 65 | +Provide your API key to the client constructor. The client sends `Authorization: Bearer <API_KEY>` in requests. |
43 | 66 |
|
44 | | -Install dev dependencies and run tests: |
| 67 | +Query parameters |
| 68 | +---------------- |
| 69 | +- `country`: ISO 3166-1 alpha-2 country code (e.g. `US`). |
| 70 | +- `protocol`: proxy protocol filter like `http`, `https`, `socks5`. |
| 71 | +- `page`: pagination page index (integer). |
45 | 72 |
|
46 | | -```bash |
47 | | -pip install -e .[dev] |
48 | | -pytest -q |
49 | | -``` |
50 | | - |
51 | | -Publishing |
52 | | ----------- |
| 73 | +Errors and exceptions |
| 74 | +--------------------- |
| 75 | +- `APIError` is raised for non-2xx HTTP responses. The message attempts to surface the API `error` field when present, otherwise it falls back to the response body. |
| 76 | +- `InvalidAPIKey` is a subclass used when the API returns HTTP 401. |
| 77 | +- `NetworkError` and `TimeoutError` wrap transport-level failures. |
53 | 78 |
|
54 | | -This repository uses a GitHub Actions workflow to publish to PyPI when a tag matching `vX.Y.Z` is pushed. |
| 79 | +Notes and limitations |
| 80 | +--------------------- |
| 81 | +- This client intentionally keeps runtime dependencies minimal and does not implement automatic retries. It also does not stream responses — responses are small (up to ~10 proxies per request). |
55 | 82 |
|
56 | | -Preparation (one-time): |
57 | | -- Create a PyPI API token at https://pypi.org/ (Account > API tokens). |
58 | | -- Add the token to GitHub repository secrets as `PYPI_API_TOKEN` (Repository Settings > Secrets). |
59 | | - |
60 | | -Release steps (recommended via CI): |
61 | | - |
62 | | -1. Bump `version` in `pyproject.toml` to the new release version (for example `0.0.2`). |
63 | | -2. Create a signed or annotated tag and push it: |
| 83 | +Testing |
| 84 | +------- |
| 85 | +Run the test suite locally with: |
64 | 86 |
|
65 | 87 | ```bash |
66 | | -git tag -a v0.0.2 -m "Release v0.0.2" |
67 | | -git push origin v0.0.2 |
| 88 | +pip install -e .[dev] |
| 89 | +pytest -q |
68 | 90 | ``` |
69 | 91 |
|
70 | | -When the tag is pushed, GitHub Actions will run `.github/workflows/release.yml` and publish the built distributions to PyPI using the `PYPI_API_TOKEN` secret. |
71 | | - |
72 | | -You can also build and upload locally (useful for dry-run checks): |
| 92 | +License |
| 93 | +------- |
| 94 | +MIT |
73 | 95 |
|
74 | | -```bash |
75 | | -python -m pip install --upgrade build twine |
76 | | -python -m build |
77 | | -python -m twine check dist/* |
78 | | -# then upload (will require PyPI credentials or token): |
79 | | -python -m twine upload dist/* |
80 | | -``` |
81 | 96 |
|
0 commit comments