pyRPC
DemoBlogChangelogDocs
Get Started

Quickstart

Get a working pyRPC server and client in under 2 minutes.

Quickstart

Copy, paste, run. No fluff — just a working pyRPC server and client call.

1. Install

uv add pyrpc-core pyrpc-fastapi uvicorn

2. Server

Create server.py:

from fastapi import FastAPI
from pyrpc_core import rpc
from pyrpc_fastapi import mount_fastapi

app = FastAPI()

@rpc
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

@rpc
def greet(name: str = "World") -> str:
    """Greet someone."""
    return f"Hello, {name}!"

mount_fastapi(app)

Run it:

uvicorn server:app --reload

Expected output:

INFO:     Uvicorn running on http://127.0.0.1:8000
INFO:     Application startup complete.

3. Client (TypeScript)

This is where the magic happens. pyRPC synchronizes your Python types into TypeScript contracts.

Install Client

npm install @pyrpc/client

Sync Contracts

Synchronize your Python procedures into TypeScript types using the CLI:

# Synchronize the contract from your running server
npx pyrpc codegen --url http://localhost:8000

Call Procedures

import { createClient } from "@pyrpc/client"
import type { Types } from "@pyrpc/types"

const client = createClient<Types>()

// Fully typed result and parameters!
const result = await client.add(10, 5)
const message = await client.greet("pyRPC")

console.log(result, message)

4. Client (Python)

You can also call your procedures from other Python services or scripts with zero codegen required.

from pyrpc_core import RPCClient

with RPCClient("http://localhost:8000") as client:
    # Everything is dynamic and introspected at runtime
    result = client.add(a=10, b=5)
    print(result)  # 15

Done 🎉

You now have a working pyRPC server + end-to-end typed contracts. Next: