Getting Started

Get PolyRPC running in under 5 minutes.

Prerequisites

  • Node.js 18+
  • Python 3.9+ with FastAPI/Pydantic
  • A Next.js or React project

Installation

1. Install the CLI

npm install -g polyrpc

2. Initialize in your project

$ cd your-project
$ polyrpc init

This creates a polyrpc.toml config file:

[python]
source_dir = "backend"

[typescript]
output_file = "frontend/src/lib/polyrpc.d.ts"

[api]
base_url = "/api"

3. Install the client packages

npm install @polyrpc/client @polyrpc/react @tanstack/react-query

4. Start the watcher

$ polyrpc watch

You'll see:

⚡ PolyRPC Sentinel
👁 Watching backend → frontend/src/lib/polyrpc.d.ts
→ Watching for changes... (Ctrl+C to stop)

Your First Type-Safe API Call

Python Backend

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class User(BaseModel):
    id: int
    name: str
    email: str

@app.get("/users/{user_id}")
async def get_user(user_id: int) -> User:
    return User(id=user_id, name="Alice", email="alice@example.com")

React Frontend

'use client';

import { py } from '@/lib/polyrpc';

export default function Page() {
  // Full type inference from Python!
  const { data, isLoading } = py.users.get_user.useQuery({ user_id: 1 });

  if (isLoading) return <div>Loading...</div>;

  return (
    <div>
      <h1>{data.name}</h1>
      <p>{data.email}</p>
    </div>
  );
}

Next Steps