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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_rpc_cli-0.11.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.11.0.tar.gz
Algorithm Hash digest
SHA256 ee1602790bb5ab2585e35b01e2b401c97268a11cc984152e27f0f9a651d5afe6
MD5 e6094f33589ac5d107af1123014b9acd
BLAKE2b-256 960d56846bc6cbe1518e0554fc2a45d9225b968502ccdb41526c24c1af5d67bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_rpc_cli-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2be6369812af90942692200f8093b236961ea2d00b930294e24ac9e815b8b7aa
MD5 6ca44fdd56e5301019e3ce2862bbf322
BLAKE2b-256 8b105e9f3bfa8ad7965d0da8e45dbed2f1cdb61e565e15f58612a7d30a7c8bb7

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