https://github.com/openmined/fastsyftbox
FastAPI + Syftbox Events
https://github.com/openmined/fastsyftbox
Last synced: 3 months ago
JSON representation
FastAPI + Syftbox Events
- Host: GitHub
- URL: https://github.com/openmined/fastsyftbox
- Owner: OpenMined
- License: apache-2.0
- Created: 2025-05-13T01:36:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-18T07:07:40.000Z (9 months ago)
- Last Synced: 2025-11-23T20:02:53.204Z (7 months ago)
- Language: Python
- Size: 658 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
fastsyftbox
[](https://pypi.org/project/fastsyftbox/)
[](https://pypi.org/project/fastsyftbox/)
[](https://pypi.org/project/fastsyftbox/)
[](https://github.com/OpenMined/fastsyftbox/actions/workflows/pr-tests.yml)
[](https://github.com/OpenMined/fastsyftbox/blob/main/LICENSE)
[](https://syftbox.net/)
## Build offline-first Python apps with FastAPI and SyftBox โ FAST.
## ๐ Features
- Build **local admin UIs** with [FastAPI](https://fastapi.tiangolo.com/).
- Build **delay-tolerant UIs/APIs** using SyftEvents.
- Keep private data offline with **SyftBox HTTP over RPC**.
- Builtin JS SDK with `fetch` compatible syntax
- Debug APIs with a built-in **Postman-style interface**.
---
## ๐ง Purpose
How can you build a web app that runs on your **own device**, without uploading data to the cloud?
With SyftBox, you can:
- Run a webserver anywhere that can go offline and keep functioning when it comes back online.
- Access your data **even when offline** or when your laptop lid is closed.
---
## โก Quick Start
Install with [uv](https://github.com/astral-sh/uv) and create your app:
```bash
uvx fastsyftbox version
uvx fastsyftbox create app test
```
To start in hot-reloading more:
```
cd test
./run.sh
```
This generates a sample FastAPI app in `app.py`:
```python
app = FastSyftBox(
app_name=app_name,
syftbox_endpoint_tags=[
"syftbox"
], # endpoints with this tag are also available via Syft RPC
include_syft_openapi=True, # Create OpenAPI endpoints for syft-rpc routes
)
# normal fastapi
@app.get("/", response_class=HTMLResponse)
def root():
return HTMLResponse("
Welcome to {app_name}
")
# build a model with pydantic
class MessageModel(BaseModel):
message: str
name: str | None = None
# make syftbox rpc endpoints easily
# syft://{datasite}/app_data/{app_name}/rpc/hello
@app.post("/hello", tags=["syftbox"])
def hello_handler(request: MessageModel):
print("got request", request)
response = MessageModel(message=f"Hi {request.name}", name="Bob")
return response.model_dump_json()
# Debug your RPC endpoints in the browser
app.enable_debug_tool(
endpoint="/hello",
example_request=str(MessageModel(message="Hello!", name="Alice").model_dump_json()),
publish=True,
)
```
## HTTP / JS
Vanilla JS fetch:
```js
const url = "http://somewebsite.com/api"
const request = await fetch(url, {
method: 'POST',
headers,
body
});
```
Becomes syftFetch:
```js
const syftUrl = "syft://madhava@openmined.org/app_data/fastsyftbox/rpc/hello"
const request = await syftFetch(syftUrl, {
method: 'POST',
headers,
body
});
```
Under the hood:
- Translates to the correct HTTP request
- Adds `syft-x` headers
- Waits for queued response
- Polls future until completed
## What is SyftBox?
SyftBox is a new platform for building privacy-preserving applications and experiences that work over the internet without uploading your data. Instead of sending your data to a server, SyftBox lets you run powerful AI and analytics locally or in trusted environments, so your personal information stays private and secure.
## ๐งฑ Your Dependencies
Add any Python dependencies to `requirements.txt` and `run.sh` will install them fresh every run.
## ๐งช RPC Debug Tool
Its like Postman but for SyftBox RPC.
A built-in HTML/JS tool helps you debug your HTTP over RPC endpoints.
To enable:
```python
app.enable_debug_tool(
endpoint="/hello",
example_request=str(MessageModel(message="Hello!", name="Alice").model_dump_json()),
publish=True,
)
```
### ๐งญ Construct syft:// RPC URLs

### ๐ฏ Configure custom headers

### ๐ View real-time responses

Then visit either:
http://localhost:${SYFTBOX_ASSIGNED_PORT}/rpc-debug
or if you have publish=True
https://syftbox.net/datasites/{{ email }}/public/{{ app_name }}/rpc-debug.html
## ๐ฅ SyftBox App Install via GitHub
```bash
syftbox app install GITHUB_URL
```
This executes run.sh and binds your app to a random port:
http://localhost:${SYFTBOX_ASSIGNED_PORT}
## ๐ Example `fastsyftbox` Apps
- ๐ฌ YouTube Wrapped