Skip to main content

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())

IP Targeting

Route requests through specific IP types or geographic regions:

# Target residential IPs in the US
client = SpaceRouter("sr_live_xxx", ip_type="residential", region="US")

# Target mobile IPs in South Korea
client = SpaceRouter("sr_live_xxx", ip_type="mobile", region="Seoul, KR")

# Change routing on the fly
mobile_client = client.with_routing(ip_type="mobile", region="JP")

Available IP types: residential, mobile, datacenter, business

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
ip_type None IP type filter
region None Region filter (substring match)
timeout 30.0 Request timeout in seconds

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spacerouter-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spacerouter-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file spacerouter-0.1.0.tar.gz.

File metadata

  • Download URL: spacerouter-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spacerouter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 991f48e7da6682db7e9153b5bef2322a665a83053e41da6258e83213e2d942fe
MD5 81b31aa643ba288b92168a3eca03f7d1
BLAKE2b-256 5d7cc517c72a02b06589ae92efdca152bb0b9b046f91b2e4af4390f82e60eb43

See more details on using hashes here.

Provenance

The following attestation bundles were made for spacerouter-0.1.0.tar.gz:

Publisher: publish.yml on gluwa/space-router-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spacerouter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spacerouter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spacerouter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c19e9374f8e735c316537353b3bd1d58591c429784f92affec0a132f3ec5016
MD5 b4d4fb2f20135e7005deb387e4d5ce60
BLAKE2b-256 2c3d9465169535def48165b1fb4f4690cbc4b35ad158de17ffee3c7b4c1fd313

See more details on using hashes here.

Provenance

The following attestation bundles were made for spacerouter-0.1.0-py3-none-any.whl:

Publisher: publish.yml on gluwa/space-router-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page