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.15.2.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.15.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_rpc_cli-0.15.2.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.15.2.tar.gz
Algorithm Hash digest
SHA256 fdd6f3999772299cd7685eb89d6336de017f16545d4ada4c457825ab89e032ca
MD5 b282376b7ccc2f6334b1e80394105386
BLAKE2b-256 f552e7fc1cdc4039dae5a6510bbc86ceb066c53ee70f25a3da9abfe9c9201056

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_rpc_cli-0.15.2-py3-none-any.whl
Algorithm Hash digest
SHA256 49e1824c33d27e62862774931423088219d7d4651529c42c926d6786bccf1265
MD5 36ddf78f10e3ba31c47605f13d534192
BLAKE2b-256 202fb8079e6f027f560287ef7838c7d99966b1a37782ec1c3766ab461bde99e1

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