Skip to main content

Python client for the stablebrowse browser agent API

Project description

stablebrowse (Python)

Python client for the stablebrowse browser agent API.

Install

From PyPI (once published):

pip install stablebrowse

From source (for local development):

cd sdks/python
pip install -e .

Requires Python 3.9+. Depends on httpx.

Quick start

from stablebrowse import Stablebrowse

# Bearer token comes from either the constructor or the
# STABLEBROWSE_API_KEY environment variable.
client = Stablebrowse(api_key="sb_live_...")

# (Optional) upload per-end-user social-media credentials.
client.end_users("alice").credentials.set(
    twitter_auth_token="...",
    twitter_ct0="...",
)

# Sync-feeling submit. Polls internally until the task terminates.
result = client.tasks.run(
    end_user_id="alice",
    task="find the top AI tweets today",
)
print(result.result)

Async primitives

If you want to drive the poll loop yourself — for example, to push progress into your own queue, or to run many submissions in parallel with your own scheduler — use the raw methods:

submission = client.tasks.submit(end_user_id="alice", task="...")
while True:
    task = client.tasks.get(submission.task_id)
    if task.is_terminal:
        break
    time.sleep(2)

Multi-turn conversations

Pass the session_id you got from the first call to continue a conversation:

first = client.tasks.run(end_user_id="alice", task="who's trending on X?")
follow = client.tasks.run(
    end_user_id="alice",
    task="what about in music specifically?",
    session_id=first.session_id,
)

The server builds previousContext from the last completed turn so the agent has the earlier answer when it reasons about the follow-up.

End users and credentials

Each business scopes end-users by opaque identifier — "alice" inside your business is independent of any other business's "alice":

alice = client.end_users("alice")

alice.credentials.set(
    tiktok_session_id="...",
    tiktok_csrf_token="...",
)

status = alice.credentials.get()
assert status.platforms["tiktok"] is True

# Remove all creds
alice.credentials.delete()

# Or a specific subset
alice.credentials.delete(fields=["twitter_auth_token", "twitter_ct0"])

Field names are snake_case in Python and get translated to camelCase on the wire automatically.

API key management

Create and revoke keys in the dashboard under Settings → API Keys. Key lifecycle is dashboard-only by design — a leaked key can't mint more.

Errors

Every exception derives from StablebrowseError:

  • TaskFailedrun() saw the task finish with status=failed. The failed Task is on .task.
  • TaskTimeout — the poll deadline expired before the task terminated. The still-running Task is on .task so you can keep polling.
  • StablebrowseError — every other HTTP or transport error. .status_code and .body are populated when the server returned structured JSON.

Configuration

The constructor reads a couple of env vars if you don't pass them:

  • STABLEBROWSE_API_KEY — bearer token
  • STABLEBROWSE_BASE_URL — override the API base, useful for pointing at beta or a local gateway

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

stablebrowse-0.3.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

stablebrowse-0.3.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file stablebrowse-0.3.0.tar.gz.

File metadata

  • Download URL: stablebrowse-0.3.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for stablebrowse-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2fa448486a1290bc8932f4d410364d69617f31e5258b9707d6ced10ddcf63125
MD5 9a3befe05ef5d593216eba447bc2e4d6
BLAKE2b-256 d46c0cb7981dbabdda6019481c26f5a1e7d25a67fbdee1b353e5a95152bda84c

See more details on using hashes here.

File details

Details for the file stablebrowse-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: stablebrowse-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for stablebrowse-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68e65cf1db2c301023be5373a6992a1737254f5d5b58d590c266e03ebe7372e6
MD5 0191b3cc759b40d65aff22bdd2637d9a
BLAKE2b-256 043796b7e7aebc8073799c77ae6db9695d11900121a4d2c741a5a74252e27a56

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