pydantically-type-adapted-grpc framework for multimodal architectures team
Project description
mmar-ptag
pydantically-type-adapted-grpc framework for multimodal architectures team
The main goal: simplify defining type-safe Python interfaces to separate services.
Installation
pip install mmar-ptag
Quick Start
1. Define the Service
from types import SimpleNamespace
from mmar_ptag import deploy_server
class Greeter:
def say_hello(self, *, name: str, count: int = 1, trace_id: str = "") -> dict:
return {"message": f"Hello, {name} x{count}"}
2. Run the Server
deploy_server(
config_server=SimpleNamespace(port=50051, max_workers=10),
service=Greeter()
)
3. Create a Client
from mmar_ptag import ptag_client
class Greeter:
def say_hello(self, *, name: str, count: int = 1) -> dict:
...
client = ptag_client(Greeter, "localhost:50051")
result = client.say_hello(name="World", count=3)
print(result) # {'message': 'Hello, World x3'}
Trace ID Support
The trace_id parameter enables distributed tracing across your service mesh. When included in a method signature, it is automatically propagated through the call chain.
from mmar_ptag import ptag_client
class UserService:
def get_user(self, *, user_id: int, trace_id: str = "") -> dict:
...
client = ptag_client(UserService, "localhost:50051")
# Trace ID is automatically propagated through the call chain
result = client.get_user(user_id=123, trace_id="request-abc-123")
The trace_id value is stored in mmar_ptag.ptag_framework.TRACE_ID_VAR, making it accessible throughout the request lifecycle without manual passing.
How It Works
ptag uses Pydantic adapters to handle type conversion between Python and gRPC/protobuf.
Example: client.say_hello(name="World", count=3)
Client flow (sending request):
{name="World", count=3}
-(args tuple)->
("World", 3)
-(args_adapter.dump_json)->
["World", 3]
-(wrap in PTAGRequest)->
b'\n\tsay_hello\x12\x0c["World", 3]'
-(server receives)->
Server flow (processing & responding):
b'\n\tsay_hello\x12\x0c["World", 3]'
-(args_adapter.validate_json)->
["World", 3]
-(bind to kwargs)->
{name="World", count=3}
-(say_hello method)->
{"message": "Hello, World x3"}
-(result_adapter.dump_json)->
{"message": "Hello, World x3"}
-(wrap in PTAGResponse)->
b'\n\tsay_hello\x12\x1e{"message": "Hello, World x3"}'
-(client receives)->
Client flow (receiving response):
b'\n\tsay_hello\x12\x1e{"message": "Hello, World x3"}'
-(return_adapter.validate_json)->
{"message": "Hello, World x3"}
This ensures:
- Arguments are validated and serialized before sending
- Return values are deserialized and validated after receiving
- Type safety across the wire without manual protobuf definitions
Features
- Type-safe RPC using Pydantic for validation
- Automatic reconnection with configurable retry attempts
- Built-in tracing with trace ID support
- Interface-based design – define services as Python classes
- Keyword-only arguments – explicit and readable API
API Reference
ptag_client(interface, address, reconnect_attempts=5)
Create a dynamic client for the given interface at the provided gRPC address.
interface: Type (class) defining the service interfaceaddress: gRPC server address (e.g.,"localhost:50051")reconnect_attempts: Number of retry attempts on connection failure (default: 5)
ptag_attach(server, service_object)
Attach a service object to an existing gRPC server.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mmar_ptag-1.1.2.tar.gz.
File metadata
- Download URL: mmar_ptag-1.1.2.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b432ba65643037bc86a11be83bd0009f97a52150510c37a08bd1295f98b7f1b8
|
|
| MD5 |
299052fc276d44156d2d2999e5fb049a
|
|
| BLAKE2b-256 |
982e9f8b6a3e6c3b00d459836da9b241c33967e7de623bd0fe337dd603259d95
|
File details
Details for the file mmar_ptag-1.1.2-py3-none-any.whl.
File metadata
- Download URL: mmar_ptag-1.1.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.31
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c266d8122edd5b213c16c4acd46db237aa6dec457a0521d9cdee66a32fd2508
|
|
| MD5 |
890c0a87f3271b1b4fe39ab9fd8c48aa
|
|
| BLAKE2b-256 |
4e15e63caad4b6e542cca10b25d0b6cbcfe9f31e55dbe6197dc66baabad7ebe0
|