Skip to main content

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) -> 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

Trace ID enables distributed tracing across your service mesh. Use installed_trace_id from mmar_mimpl to set the trace ID context.

from mmar_mimpl import installed_trace_id
from mmar_ptag import ptag_client

class UserService:
    def get_user(self, *, user_id: int) -> dict:
        ...

client = ptag_client(UserService, "localhost:50051")

# Set trace_id using installed_trace_id context manager
with installed_trace_id(trace_id="request-abc-123"):
    result = client.get_user(user_id=123)

The trace ID value is stored in mmar_mimpl.TRACE_ID_VAR, making it accessible throughout the request lifecycle and automatically propagated to downstream services.

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 interface
  • address: 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.

Metadata

Release files for mmar-ptag 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mmar-ptag 1.3.0
File Size Uploaded Provenance Actions
mmar_ptag-1.3.0.tar.gz 9.6 kB Without provenance Details for mmar_ptag-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mmar-ptag 1.3.0
File Interpreter ABI Platform Actions
mmar_ptag-1.3.0-py3-none-any.whl Python 3 none any Details for mmar_ptag-1.3.0-py3-none-any.whl

Total release size: 22.2 kB

Release files / mmar_ptag-1.3.0.tar.gz

Download URL mmar_ptag-1.3.0.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cdc8f36911ad6c5fee4e81153866ca8923215d8258384bbcfbbcbc11d35e350c
BLAKE2b-256 checksum
How to use checksums
f6ebc38c403e20c23ab92136e87f74e3061829c7700d50dc8d7e81940271dedd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.31

Release files / mmar_ptag-1.3.0-py3-none-any.whl

Download URL mmar_ptag-1.3.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5286968389b6bdca145c965168915478ab56a967160ab0a3ef6b8a8356c61571
BLAKE2b-256 checksum
How to use checksums
fbbb40320bc0b3186c119c9619984e4a0775015feb84e52820d2b837423d021c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.31

Security for mmar-ptag 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page