End-to-end type safety from Python to TypeScript — typed RPC with automatic TS client codegen.
Project description
PyBridge
End-to-end type safety from Python to TypeScript — no codegen ceremony, no schema drift.
Define procedures in Python with standard type hints + Pydantic. Run one command. Get a fully typed TypeScript client.
pip install pybridge-rpc
pybridge generate --bridge examples.basic:bridge --out client/api.ts --hooks
# server.py
from pybridge import Bridge
from pydantic import BaseModel
bridge = Bridge()
class User(BaseModel):
id: str
name: str
email: str
@bridge.procedure("users.create")
async def create_user(input: User) -> User: ...
app = bridge.asgi()
import { createClient, type AppRouter } from "./api";
const api = createClient<AppRouter>("http://localhost:8000");
const user = await api.users.create({ id: "1", name: "Kofi", email: "k@example.com" });
// ^ fully typed as User
Features
- Zero-ceremony typed RPC — Python function signature is the API contract. No
.input()/.output()wrappers, no separate schema files. - Pydantic → TypeScript — full type projection: nested models, unions, literals, enums,
datetime,UUID, tuples,dict, optional/nullable. - One-command codegen —
pybridge generateemits a singleapi.tswith types + proxy client + optional TanStack Query hooks. - ASGI transport — HTTP, WebSocket subscriptions, and SSE streams out of the box (built on Starlette).
- Framework integrations — drop into FastAPI, Django, Sanic, or Litestar without rewriting your app.
- File uploads, CORS & CSRF helpers, observer protocol for logging/metrics/tracing hooks.
- OpenAPI 3.x exporter — get a spec for tooling that needs one, without making it the source of truth.
- Watch mode —
watchfiles-backed regeneration with mtime-polling fallback. - Typed errors —
ProcedureErrorcodes propagate to the client. - Fully typed package — ships
py.typed.
Why PyBridge
Full-stack teams with a Python backend and a TypeScript frontend live with a constant gap: define models in Pydantic, redefine them as TS interfaces, hope they stay in sync. The usual fixes have rough edges:
| Approach | Trade-off |
|---|---|
| FastAPI + openapi-typescript | Works, but it's a 4-step pipeline (FastAPI → OpenAPI → codegen → wire-up). Generated SDKs have opinions about method names and return shapes that often need wrapping. |
| tRPC / oRPC | Great DX — but your backend has to be TypeScript. |
| GraphQL + codegen | Adds a schema language, a runtime, and a resolver layer for something a function signature already encodes. |
| PyBridge | Python type hints are the source of truth. One command produces a thin, idiomatic TS client whose types are a direct projection of your Pydantic models. |
The goal is the same DX tRPC/oRPC developers enjoy — with Python as the source of truth. See docs/design.md for the full rationale.
Status
Phases 1–3 are complete and tested (33 tests passing). Currently 0.2.x — beta. API is stable for the documented surface; breaking changes will be called out in release notes.
Documentation
All docs live in docs/:
- Design — the problem, approach, architecture.
- Quickstart — install, server + client, feature list.
- Streaming — WebSocket subscriptions and SSE streams.
- Authentication — bearer tokens, cookie sessions, CSRF.
- Observability — observers, timeouts, body limits.
- Framework integrations — FastAPI, Django, Sanic, Litestar.
- TanStack example — Router + Query end-to-end.
- Performance — benchmarks.
- Project layout — module map.
- Roadmap — phases, tech stack, status.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 pybridge_rpc-0.2.1.tar.gz.
File metadata
- Download URL: pybridge_rpc-0.2.1.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50b8e55d4cd748d246264568a915f097bb123bb2b03fe2d34f6e9adcb114c0ea
|
|
| MD5 |
327c07c577ed7b231747e5f92c3909d2
|
|
| BLAKE2b-256 |
0ce76bb7fdb9e6831ad9805f7b4d97f5b9abda0ce538e1888d2276fec23de98b
|
File details
Details for the file pybridge_rpc-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pybridge_rpc-0.2.1-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64c66487b7f97e514086edce6a52a3873cfa6c059bc0ddd32a3e0948e2651922
|
|
| MD5 |
37e0adab01543f1795dde3a8a1bc40d3
|
|
| BLAKE2b-256 |
51ad0616edca8fffce4cc822762fdb9bfb18d623dac7228f6743b6f9b58d6386
|