Skip to main content

Supernatural Python SDK — stealth browser-as-a-service client.

Project description

Supernatural Python SDK

Official Python client for the Supernatural stealth browser-as-a-service API.

Installation

pip install sprntrl
# Optional: Playwright integration
pip install 'sprntrl[playwright]' && playwright install chromium

Quick start

from sprntrl import Sprntrl

client = Sprntrl()  # reads SPRNTRL_API_KEY from env

session = client.sessions.create(os="macos", location="America/New_York")

# browser_session is a context manager that waits for the session,
# connects Playwright, and closes the browser + Playwright on exit.
# auto_whitelist=True registers your IP (CDP access is IP-gated).
with client.sessions.browser_session(session["id"], auto_whitelist=True) as browser:
    page = browser.contexts[0].new_page()
    page.goto("https://bot.sannysoft.com")
    page.screenshot(path="out.png")

client.sessions.stop(session["id"])

Async

import asyncio
from sprntrl import AsyncSprntrl

async def main():
    async with AsyncSprntrl() as client:
        session = await client.sessions.create(os="macos", location="America/New_York")
        async with client.sessions.browser_session(session["id"], auto_whitelist=True) as browser:
            page = await browser.contexts[0].new_page()
            await page.goto("https://example.com")
        await client.sessions.stop(session["id"])

asyncio.run(main())

Lower-level connect() and cdp_url()

If you want to manage the browser lifecycle yourself:

browser = client.sessions.connect(session_id, auto_whitelist=True)
# ... your code ...
browser.close()

Or to hand the raw WebSocket URL to any CDP client (chrome-remote-interface-python, raw websockets, etc.):

url = client.sessions.cdp_url(session_id)
# url = "wss://api.supernatural.sh/api/v1/sessions/<id>/cdp"

Configuration

Env var Default
SPRNTRL_API_KEY
SPRNTRL_BASE_URL https://api.supernatural.sh

Or override per client:

client = Sprntrl(api_key="sk_...", base_url="https://api.supernatural.sh", timeout=30, max_retries=2)

Resources

  • client.sessions — create, list, list_active, list_history, list_resumable, list_locations, get, stop, resume, delete_persistent, wait_until_ready, connect, browser_session, cdp_url
  • client.sessions.files — list, download, upload
  • client.profiles — create, list, get, update, duplicate, delete
  • client.templates.list()
  • client.ip_whitelist — list, add, remove
  • client.usage — current, history
  • client.user — me, update, update_settings, change_password
  • client.api_keys — list, create (full key returned ONCE), revoke

Error handling

from sprntrl import Sprntrl, APIError, RateLimitError, AuthenticationError

client = Sprntrl()
try:
    client.sessions.create(os="macos", location="America/New_York")
except RateLimitError as e:
    print("rate limited:", e.status, e.body)
except AuthenticationError:
    print("bad API key")
except APIError as e:
    print("api error:", e.status, e)

Transient errors (5xx, 429, 408, connection errors) are retried automatically up to max_retries times with exponential backoff.

Gotchas

  • CDP access is IP-whitelist gated. The WebSocket at /api/v1/sessions/:id/cdp does not accept bearer auth — instead, your public IP (as Cloudflare sees it) must be in your account's whitelist. Use client.ip_whitelist.add("current") or pass auto_whitelist=True to sessions.connect.
  • Sessions start async. sessions.create returns immediately with status: "creating". Call sessions.wait_until_ready(id) before connecting, or just use sessions.connect() which waits for you.
  • API key is shown only once. api_keys.create() returns the full key field exactly once — store it immediately.

License

MIT

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

sprntrl-0.1.1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

sprntrl-0.1.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file sprntrl-0.1.1.tar.gz.

File metadata

  • Download URL: sprntrl-0.1.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sprntrl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 075717c02ae99e95370194230908db54d7a801ac50a8f50c1a6b7cfc829c072c
MD5 5d19dd2bb561310d431e511192d062e5
BLAKE2b-256 1042b04cc33a19892bb2ed37e364dc6aa7df4da09f4d45ab3304284576c1ab28

See more details on using hashes here.

File details

Details for the file sprntrl-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sprntrl-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sprntrl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e9323b885d16cc493257219a242694679cbb064b77518dbb0471527f9278d661
MD5 321a2797161d5ec62275cb5c8787e7b4
BLAKE2b-256 d48602dbe800e4b3c176a964d7f3cdbad05eb9b12cb51da7982cebbe0b5f3f04

See more details on using hashes here.

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