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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_rpc_cli-0.15.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d46ef4bca7966c3153590353c23076ca8a652de24a00a3bb2b4d9676b9f992e6
MD5 f38268e347dddb192e65909611894393
BLAKE2b-256 522e2b566573d88ca9d89e26657363ad5dcdee78f37535d4c98f5345d29e2125

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_rpc_cli-0.15.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9ff97e9eb0ea526c59c69bc4c5ce82f18ed0a82dcea0a314590795bca821e28
MD5 26ad25454fc3cdde4695909b4839601c
BLAKE2b-256 03cc7ce4f10e54df29565ac6eacea6f1acc70f2eaa4ce7e8dc6ef01b11347a17

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