Server-side Python SDK for InstantDB — the Modern Firebase
Project description
Python Admin SDK
Get Started · Examples · Docs · Discord
Welcome to Instant's Python Admin SDK.
Quickstart
uv add instantdb
# or
pip install instantdb
Requires Python 3.10+.
app_id and admin_token can be passed explicitly or read from
INSTANT_APP_ID / INSTANT_APP_ADMIN_TOKEN environment variables.
from instantdb import Instant, id
db = Instant(
app_id="YOUR_APP_ID",
admin_token="YOUR_ADMIN_TOKEN",
)
# Transact (InstaML)
goal_id = id()
db.transact(db.tx.goals[goal_id].update({"title": "Get fit"}))
# Query (InstaQL)
result = db.query({"goals": {"todos": {}}})
# Auth: magic codes, tokens, user management
token = db.auth.create_token(email="alyssa@example.com")
# Impersonate for permission-scoped queries
scoped = db.as_user(guest=True)
scoped_result = scoped.query({"goals": {}})
The async client (AsyncInstant) ships the same surface plus
subscribe_query (live SSE subscriptions) and streams (durable
bidirectional byte streams). Use it from FastAPI handlers, agents, or
anywhere you're already running an event loop:
import asyncio
from instantdb import AsyncInstant
adb = AsyncInstant()
async def main():
async with adb.subscribe_query({"goals": {}}) as sub:
async for payload in sub:
process(payload)
asyncio.run(main())
Head on over to the Python Docs for more usage docs!
Development
cd client/packages/python
uv sync
make check # ruff + mypy strict + pytest
make fmt
Editing the SDK source
Only edit src/instantdb/_async/. The sync client at
src/instantdb/_sync/ is generated from the async tree via
unasync and is committed to
the repo. After any change to _async/, regenerate:
make unasync
This runs scripts/run_unasync.py (preprocesses + applies replacement
rules) then ruff (import sort + format). Commit the generated _sync/
tree alongside your async change.
Some modules under _async/ are intentionally async-only — they're
listed in the ASYNC_ONLY set in scripts/run_unasync.py and each one
explains its rationale in its own docstring (typically: relies on
asyncio coordination primitives that don't survive unasync's
token-rewrite).
Adding a new file under _async/:
- HTTP-shaped surface (request/response, no background tasks): just
drop it in and re-run
make unasync— it'll be picked up automatically. - Async-only surface (background tasks, asyncio coordination):
drop it in, add its path to
ASYNC_ONLYinscripts/run_unasync.py, and note the why in the module's docstring so the next person doesn't have to figure it out.
If you add a method or import that should exist only on the async
client (inside a file that is unasynced), wrap it in marker comments
and re-run make unasync:
# UNASYNC_REMOVE_START
def new_async_only_method(self): ...
# UNASYNC_REMOVE_END
Full mechanics — replacement rules, preprocessing details, what to
avoid — live in the docstring of scripts/run_unasync.py.
Testing changes
We test in three layers, fastest to most realistic:
- Unit tests (
make check) — validation, header construction, error parsing, and pure-logic helpers (buffer-discard math, dispatch precedence, etc.). No network. This is the fast inner loop. - Sandbox integration tests — exercise the SDK against a real Instant server and assert on outcomes. Similar to how we test the JS admin SDK.
- End-to-end branch test — scaffold a real consumer project that pulls the SDK from your branch, then run a script the way a user would.
Sandbox (integration)
The sandbox at client/sandbox/admin-sdk-python/ is the integration layer.
cd ../../sandbox/admin-sdk-python
cp .env.example .env # fill in INSTANT_APP_ID + INSTANT_APP_ADMIN_TOKEN
uv sync
# uncomment a tester call inside main() in src/main.py
uv run --env-file .env python -m src.main
Two entry points: src/main.py for the async client (everything, including
subscribe + streams) and src/main_sync.py for the sync client (auth, query,
transact, storage, rooms, webhooks). Tester calls are commented out at rest —
uncomment the one you want, run it, re-comment before committing.
Defaults to http://localhost:8888; set INSTANT_API_URI in .env to point
elsewhere.
End-to-end (a real project on your branch)
To exercise a change the way a user would — scaffold a project, install the SDK,
run a script — point a fresh create-instant-app project at your branch:
-
Push your branch to GitHub (e.g.
my-feature). -
Scaffold a project with the per-branch build of
create-instant-app(the@branch-<your-branch>tag is published automatically per branch):cd /tmp pnpx create-instant-app@branch-my-feature --python my-app cd my-app
-
The scaffold pulls
instantdbfrom PyPI by default, which won't have your branch's changes. Point it at your branch by adding a[tool.uv.sources]entry to the scaffoldedpyproject.toml:[tool.uv.sources] instantdb = { git = "https://github.com/instantdb/instant.git", branch = "my-feature", subdirectory = "client/packages/python" }
-
Sync and run (the scaffolder already wrote a working
.env):uv sync # clones the repo, builds the SDK from your branch, installs it uv run --env-file .env python main.py
If you already have the monorepo checked out and are iterating on the SDK, use a local editable path instead so source edits show up without re-syncing from git:
[tool.uv.sources]
instantdb = { path = "/absolute/path/to/client/packages/python", editable = true }
Questions?
If you have any questions, feel free to drop us a line on our Discord
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 instantdb-1.0.46-py3-none-any.whl.
File metadata
- Download URL: instantdb-1.0.46-py3-none-any.whl
- Upload date:
- Size: 49.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb530e79d323ee21c6ea40249c19af516b3e27102b2048e7aec16dd583c8c7a4
|
|
| MD5 |
b5284ec6693c9a33b93e0e2dd2d96ba8
|
|
| BLAKE2b-256 |
af1d0e47c9d6db89051f72a0ed04f2a0594fcef561d5e9fc956862bbb948c45b
|
Provenance
The following attestation bundles were made for instantdb-1.0.46-py3-none-any.whl:
Publisher:
python-publish.yml on instantdb/instant
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
instantdb-1.0.46-py3-none-any.whl -
Subject digest:
bb530e79d323ee21c6ea40249c19af516b3e27102b2048e7aec16dd583c8c7a4 - Sigstore transparency entry: 1767151364
- Sigstore integration time:
-
Permalink:
instantdb/instant@c3a5f48b3b28a2ad0d09b6befb6dedafcf3db2e0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/instantdb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c3a5f48b3b28a2ad0d09b6befb6dedafcf3db2e0 -
Trigger Event:
push
-
Statement type: