trpc-gen-python
v0.1.3
Published
Generate Python (Pydantic + httpx) clients from tRPC routers
Maintainers
Readme
trpc-gen-python
Generate type-safe Python clients from tRPC routers. Automatically converts your tRPC endpoints into Pydantic models and httpx-based client code.
Installation
npx trpc-gen-python generateOr install globally:
npm install -g trpc-gen-python
trpc-gen-python generateQuick Start
- Create a
trpc-gen-python.tomlconfiguration file in your project root:
# Which endpoints to generate (supports glob patterns)
endpoints = ["user.*", "post.list"]
[router]
# Path to your tRPC router file
path = "./src/server/router.ts"
# Export name of your router
export = "appRouter"
# Base URL for your tRPC API
base_url = "http://localhost:3000/api/trpc"
[output]
# Output directory for generated Python code
dir = "./generated"
# Name of the generated Python package
package_name = "trpc_client"- Run the generator:
npx trpc-gen-python generate- Use the generated Python client:
from generated.trpc_client import TRPCClient
client = TRPCClient()
# Call your tRPC procedures
user = client.user.get(id=123)
posts = client.post.list(limit=10)CLI Options
trpc-gen-python generate [options]
Options:
-c, --config <path> Path to config file (default: trpc-gen-python.toml)
-h, --help Display help
-V, --version Display versionPython Dependencies
The generated client requires:
pip install pydantic httpxLicense
MIT
Contributing
Issues and pull requests welcome!
