Python SDK for the Space Router residential proxy network
Project description
SpaceRouter Python SDK
Python SDK for routing HTTP requests through the Space Router residential proxy network.
Installation
pip install spacerouter
# With SOCKS5 support
pip install spacerouter[socks]
Quick Start
from spacerouter import SpaceRouter
with SpaceRouter("sr_live_YOUR_API_KEY", gateway_url="http://gateway:8080") as client:
response = client.get("https://httpbin.org/ip")
print(response.json()) # {"origin": "residential-ip"}
print(response.node_id) # node that handled the request
print(response.request_id) # unique request ID for tracing
Async Usage
from spacerouter import AsyncSpaceRouter
async with AsyncSpaceRouter("sr_live_YOUR_API_KEY") as client:
response = await client.get("https://httpbin.org/ip")
print(response.json())
Region Targeting
Route requests through specific geographic regions:
# Target residential IPs in the US
client = SpaceRouter("sr_live_xxx", region="US")
# Target residential IPs in South Korea
client = SpaceRouter("sr_live_xxx", region="KR")
# Change routing on the fly
jp_client = client.with_routing(region="JP")
SOCKS5 Proxy
client = SpaceRouter(
"sr_live_xxx",
protocol="socks5",
gateway_url="socks5://gateway:1080",
)
response = client.get("https://httpbin.org/ip")
Requires the socks extra: pip install spacerouter[socks]
API Key Management
from spacerouter import SpaceRouterAdmin
with SpaceRouterAdmin("http://localhost:8000") as admin:
# Create a key (raw value only available here)
key = admin.create_api_key("my-agent", rate_limit_rpm=120)
print(key.api_key) # sr_live_...
# List keys
for k in admin.list_api_keys():
print(k.name, k.key_prefix, k.is_active)
# Revoke a key
admin.revoke_api_key(key.id)
Async variant: AsyncSpaceRouterAdmin
Error Handling
from spacerouter import SpaceRouter
from spacerouter.exceptions import (
AuthenticationError, # 407 - invalid API key
RateLimitError, # 429 - rate limit exceeded
NoNodesAvailableError, # 503 - no residential nodes online
UpstreamError, # 502 - target unreachable via node
)
with SpaceRouter("sr_live_xxx") as client:
try:
response = client.get("https://example.com")
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except NoNodesAvailableError:
print("No nodes available, try again later")
except UpstreamError as e:
print(f"Node {e.node_id} could not reach target")
except AuthenticationError:
print("Check your API key")
Note: HTTP errors from the target website (e.g. 404, 500) are not raised as exceptions. Only proxy-layer errors produce exceptions.
Configuration
| Parameter | Default | Description |
|---|---|---|
api_key |
(required) | API key (sr_live_...) |
gateway_url |
http://localhost:8080 |
Proxy gateway URL |
protocol |
http |
http or socks5 |
region |
None |
2-letter country code (ISO 3166-1 alpha-2) |
timeout |
30.0 |
Request timeout in seconds |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spacerouter-0.2.2.tar.gz.
File metadata
- Download URL: spacerouter-0.2.2.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02acf551f3bda65a00aeed7797f6456dc750e8f429058793f448a3bc5340e647
|
|
| MD5 |
1d351c4781e139d858107dc57ded8892
|
|
| BLAKE2b-256 |
5d36d8fbc45901710024ac461fbcde176b4eb193a62e76abde13fa6201739f7b
|
Provenance
The following attestation bundles were made for spacerouter-0.2.2.tar.gz:
Publisher:
publish.yml on space-labs/space-router-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spacerouter-0.2.2.tar.gz -
Subject digest:
02acf551f3bda65a00aeed7797f6456dc750e8f429058793f448a3bc5340e647 - Sigstore transparency entry: 1246220836
- Sigstore integration time:
-
Permalink:
space-labs/space-router-sdk@48cd18cb7d72d5a6ac4803fb8428a958ee742eed -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/space-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@48cd18cb7d72d5a6ac4803fb8428a958ee742eed -
Trigger Event:
push
-
Statement type:
File details
Details for the file spacerouter-0.2.2-py3-none-any.whl.
File metadata
- Download URL: spacerouter-0.2.2-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd6661cb77aa9663aca27c9d365b1817f315561129f688f1c0038b311c684d30
|
|
| MD5 |
dc63dacdc04a25ba514c844a64a01fc0
|
|
| BLAKE2b-256 |
93cc703a75187e3651e5ce9b6771faa7eea93836e57d181fff932fffb966ec4a
|
Provenance
The following attestation bundles were made for spacerouter-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on space-labs/space-router-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spacerouter-0.2.2-py3-none-any.whl -
Subject digest:
bd6661cb77aa9663aca27c9d365b1817f315561129f688f1c0038b311c684d30 - Sigstore transparency entry: 1246220838
- Sigstore integration time:
-
Permalink:
space-labs/space-router-sdk@48cd18cb7d72d5a6ac4803fb8428a958ee742eed -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/space-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@48cd18cb7d72d5a6ac4803fb8428a958ee742eed -
Trigger Event:
push
-
Statement type: