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)
print(f"cost: ${result.total_cost_usd:.4f}")
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
Only usable with a Cognito JWT (see the web dashboard). API-key bearer tokens cannot mint more keys — that's by design to contain a leak.
# Typically used from a short-lived admin script, not from app code.
keys = client.api_keys.list()
new = client.api_keys.create(label="production")
print("save this — you won't see it again:", new.secret)
client.api_keys.revoke(new.prefix)
Errors
Every exception derives from StablebrowseError:
TaskFailed—run()saw the task finish with status=failed. The failedTaskis on.task.TaskTimeout— the poll deadline expired before the task terminated. The still-runningTaskis on.taskso you can keep polling.StablebrowseError— every other HTTP or transport error..status_codeand.bodyare 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 tokenSTABLEBROWSE_BASE_URL— override the API base, useful for pointing at beta or a local gateway
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 stablebrowse-0.1.0.tar.gz.
File metadata
- Download URL: stablebrowse-0.1.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a263f28834ffdc8ec882f2fb9a74d70096df80da7bf45b50ee47af54bbf0573d
|
|
| MD5 |
002637457bdea8b691a3cc38f71ec018
|
|
| BLAKE2b-256 |
bdd3d5d1984db5c162d95329c048dc6b5d99c30863cb90d203ff7f534133834e
|
File details
Details for the file stablebrowse-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stablebrowse-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fab965267f9928da31a3d803b266275ff13748744f7161eaab2f0fb44630ba00
|
|
| MD5 |
7a791f8d8c984cd53d62f59d04f4fead
|
|
| BLAKE2b-256 |
48339a063b1deb9f62052c3fe7ce61c6bfbc0851f384fb853e52a4812c025711
|