Metadata-Version: 2.5
Name: fletbase-sdk
Version: 0.1.0a0
Summary: Python client SDK for FletBase — a document database, auth, and file storage backend for Flet apps
Project-URL: Homepage, https://flet.dev
Project-URL: Source, https://github.com/flet-dev/fletbase
Author: Flet
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: backend,cloudflare,database,firebase,flet
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.27; sys_platform != 'emscripten'
Description-Content-Type: text/markdown

# fletbase-sdk

The Python client for FletBase, the backend for [Flet](https://flet.dev) 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

```bash
pip install fletbase-sdk
```

Or add `fletbase-sdk` to your app's `[project].dependencies`. The package you
import is `fletbase`.

## Quickstart

```python
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](https://github.com/flet-dev/fletbase).
