Skip to main content

FastAPI + SyftBox

Project description

fastsyftbox

Logo

PyPI - Version PyPI - Downloads License MadeWith


Build offline-first Python apps with FastAPI and SyftBox — FAST.

🚀 Features

  • Build local admin UIs with FastAPI.
  • 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 and create your app:

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:

app = FastAPI(title=app_name)

# add your fastapi app to the syftbox object
syftbox = Syftbox(app=app, name=app_name)

# normal fastapi
@app.get("/", response_class=HTMLResponse)
def root():
    return HTMLResponse("<html><body><h1>Welcome to {app_name}</h1>")


# 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
@syftbox.on_request("/hello")
def hello_handler(request: MessageModel):
    response = MessageModel(message=f"Hi {request.name}", name="Bob")
    return response.model_dump_json()

# Debug your RPC endpoints in the browser
syftbox.enable_debug_tool(
    endpoint="/hello",
    example_request=str(MessageModel(message="Hello!", name="Alice").model_dump_json()),
    publish=True,
)

HTTP / JS

Vanilla JS fetch:

const url = "http://somewebsite.com/api"
const request = await fetch(url, {
    method: 'POST',
    headers,
    body
});

Becomes syftFetch:

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.

Read more about SyftBox here

🧱 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:

syftbox.enable_debug_tool(
    endpoint="/hello",
    example_request=str(MessageModel(message="Hello!", name="Alice").model_dump_json()),
    publish=True,
)

🧭 Construct syft:// RPC URLs

Debug Tool Screenshot

🎯 Configure custom headers

Debug Tool Screenshot

🔍 View real-time responses

Debug Tool Screenshot

Then visit either: http://localhost:${SYFTBOX_ASSIGNED_PORT}/rpc-debug or if you have publish=True https://syftboxdev.openmined.org/datasites/{{ email }}/public/{{ app_name }}/rpc-debug.html

📥 SyftBox App Install via GitHub

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastsyftbox-0.1.5.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastsyftbox-0.1.5-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file fastsyftbox-0.1.5.tar.gz.

File metadata

  • Download URL: fastsyftbox-0.1.5.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for fastsyftbox-0.1.5.tar.gz
Algorithm Hash digest
SHA256 928262ffc88319ea51ac86f9903e4d12e9979c8624d4023608fac4d811722825
MD5 5d70eb7696b1e0ba6ded0bf80f05490e
BLAKE2b-256 427addd307e2544a296ee069e42d1b780e6b604bb7e2e92422c8a4502fa2d4dc

See more details on using hashes here.

File details

Details for the file fastsyftbox-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: fastsyftbox-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for fastsyftbox-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 00cad3cb8a4468384d60c2aae675d061af52526562eec7752642ca48e7c3fa86
MD5 dec3c840d51c8daf7215ba2b3e8d1979
BLAKE2b-256 d3e011c2c4add05c091fee7949807a98daf6780680a1c4e97f64402439a5e00f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page