Skip to main content

CLI tool for pydantic-rpc with server runtime support

Project description

pydantic-rpc-cli

CLI tool for pydantic-rpc with built-in server runtime support.

Installation

pip install pydantic-rpc-cli

This will install:

  • pydantic-rpc (core library)
  • hypercorn (ASGI server)
  • gunicorn (WSGI server)
  • uvloop (optional asyncio performance improvement)

Usage

Generate Protobuf Files

# Generate .proto file from a service class
pydantic-rpc generate myapp.services.UserService --output ./proto/

# Also compile to Python code
pydantic-rpc generate myapp.services.UserService --compile

Run Servers

gRPC Server (default)

# Start a gRPC server
pydantic-rpc serve myapp.services.UserService --port 50051

# The CLI automatically detects if your service has async methods
# and uses AsyncIOServer or Server accordingly

Connect RPC via ASGI (HTTP/2)

# Run with Hypercorn (built-in)
pydantic-rpc serve myapp.services.UserService --asgi --port 8000

# Service will be available at:
# http://localhost:8000/UserService/

Connect RPC via WSGI (HTTP/1.1)

# Run with Gunicorn (built-in)
pydantic-rpc serve myapp.services.UserService --wsgi --port 8000

# With multiple workers
pydantic-rpc serve myapp.services.UserService --wsgi --port 8000 --workers 4

# Service will be available at:
# http://localhost:8000/UserService/

Example Service

# myapp/services.py
from pydantic_rpc import Message, AsyncIOServer

class HelloRequest(Message):
    name: str

class HelloResponse(Message):
    message: str

class GreeterService:
    async def say_hello(self, request: HelloRequest) -> HelloResponse:
        return HelloResponse(message=f"Hello, {request.name}!")

Run it:

# As gRPC
pydantic-rpc serve myapp.services.GreeterService

# As Connect RPC (HTTP/2)
pydantic-rpc serve myapp.services.GreeterService --asgi --port 8000

# As Connect RPC (HTTP/1.1)
pydantic-rpc serve myapp.services.GreeterService --wsgi --port 8000

Benefits of the Separated CLI

  • Lightweight Core: The main pydantic-rpc package remains lightweight without server dependencies
  • Full Server Support: When you install pydantic-rpc-cli, you get everything needed to run services
  • Flexibility: Choose between gRPC, ASGI (HTTP/2), or WSGI (HTTP/1.1) at runtime

License

Same as pydantic-rpc

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

pydantic_rpc_cli-0.12.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

pydantic_rpc_cli-0.12.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_rpc_cli-0.12.0.tar.gz.

File metadata

  • Download URL: pydantic_rpc_cli-0.12.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pydantic_rpc_cli-0.12.0.tar.gz
Algorithm Hash digest
SHA256 55422d71230d106bdd6b181b189519465cc1c2cb81e26e89e50e12e3751b92ae
MD5 6ab939e6033b06ed5fcaa6a2c7c13a0f
BLAKE2b-256 1909a665715f0d2320fce021420917600e84c8bac33400ad2f2d3f568c1751ab

See more details on using hashes here.

File details

Details for the file pydantic_rpc_cli-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_rpc_cli-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b05ce69b77910da576ffced0652f016448c69a11f8589ea4afe0f073556c85a
MD5 ed990306a089b096b366c320047d9cf9
BLAKE2b-256 915904eb6eebf459709a0429cdd004787d6d59d65787f885644c35a92a4bdd6e

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