fletbase-sdk
The Python client for FletBase, the backend for Flet apps: a
Firestore-style document database that runs on Cloudflare, with auth and file storage
to follow.
Pre-alpha. The API and the wire protocol still change between releases. Pin an
exact version.
- Async only. One API, written with
await, everywhere.
- Runs where Flet runs: desktop, mobile, and the browser. Under Pyodide (
flet build web, Flet Studio's preview) it talks through the browser's own fetch, and
does not even install httpx.
- Small. One runtime dependency,
httpx, and only outside the browser.
Install
pip install fletbase-sdk
Or add fletbase-sdk to your app's [project].dependencies. The package you
import is fletbase.
Quickstart
import asyncio
import fletbase
from fletbase import database
async def main():
async with fletbase.server(
base_url="https://api.flet.app",
project_id="prj_...",
service_key="fb_ak_...",
) as project:
todos = project.database.collection("todos")
ref = await todos.add({"title": "Ship v1", "views": 0})
await ref.update({"views": database.increment(1)}) # computed by the server
snap = await ref.get()
print(snap["title"], snap["views"], snap.revision)
asyncio.run(main())
fletbase.server() is the handle for trusted code (scripts, backends, CI), and
takes a service or operator key. Never put such a key in an app you ship to users.
What works today
|
|
| Documents |
add, get, set (with merge=), update, delete, guarded by revision= |
| Field transforms |
database.increment, array_union, array_remove, server_timestamp, delete_field |
| Atomic writes |
db.batch(), and optimistic transactions with db.run_transaction(...) |
| Retries |
every write carries a mutation ID, so a retried write is applied once |
Coming:
- queries (
where, order_by, cursors, aggregates);
- saving and loading dataclasses (
model=);
fletbase.project() for public apps, with end-user sign-in;
- realtime listeners;
- files;
- local databases (
database.local(...)) that live on the device, browser included, behind the same API.
Debugging
Set FLETBASE_DEBUG=1 to print every request and response, or pass debug=True to
fletbase.server(). Credentials are never printed. fletbase.observability has the
programmatic hooks.
License
Apache-2.0. The FletBase server is licensed separately; see the
repository.