Skip to main content

trevrpc

A Python client for TrevRPC, a protobuf RPC framework over QUIC.

It calls TrevRPC services over native QUIC with aioquic, and over QMux over TLS on the server's TCP listener where UDP is blocked, on messages generated by protobuf-py. It is a client only, asyncio only, and requires Python 3.14.

See the Python Guide for the whole API, and #666 for what is still in progress.

Installing

pip install trevrpc                              # or: uv add trevrpc
pip install protoc-gen-py protoc-gen-trevrpc-py  # the protoc plugins, for generating code

Generating a client

protoc-gen-py generates the messages and protoc-gen-trevrpc-py the clients, next to them:

# buf.gen.yaml
version: v2
plugins:
  - local: protoc-gen-py
    out: gen
  - local: protoc-gen-trevrpc-py
    out: gen

Calling a service

import trevrpc
from gen.greeter_pb import HelloRequest
from gen.greeter_trevrpc import GreeterClient

async with trevrpc.Channel("example.com:443") as channel:
    greeter = GreeterClient(channel)

    # unary
    reply = await greeter.say_hello(HelloRequest(name="Ada"), timeout=5)

    # server streaming
    async with greeter.watch(HelloRequest(name="Ada")) as replies:
        async for reply in replies:
            print(reply.message)

    # client streaming
    upload = greeter.upload()
    await upload.send_all(requests)
    reply = await upload.close_and_recv()

    # bidirectional streaming
    async with greeter.chat() as chat:
        await chat.send(HelloRequest(name="Ada"))
        reply = await chat.recv()
        await chat.close_send()

Every method takes the call options as keyword arguments: timeout (seconds), metadata, max_frame_size (at most the channel's, 4 MiB by default; a larger value raises INVALID_ARGUMENT), and the on_response_headers and on_response_metadata callbacks. A call that does not end with an OK status raises trevrpc.TrevRpcError, which carries the status's code, message, trailing metadata and details (retry_delay, find_details()).

Connection metadata

Metadata that every call of a channel carries, such as a bearer token, can be set once on the channel. Each connection carries it until the server confirms it stored it, and later calls refer to it by ID instead of repeating it. A call's own metadata wins for a key both have.

channel = trevrpc.Channel(
    "example.com:443", connection_metadata={"authorization": f"Bearer {token}"}
)
channel.set_connection_metadata({"authorization": f"Bearer {refreshed}"})  # later calls

Transports

A channel connects over QUIC and falls back to QMux over TLS (ALPN qmux-02.trevrpc-1) when QUIC has not connected within 300 ms, or failed: the first to connect wins. After the fallback won, reconnects use it directly for 5 minutes before they race again. A call never moves between connections. The channel options set this up:

channel = trevrpc.Channel(
    "example.com:443",
    transport="auto",  # or "quic", or "tcp" for QMux over TLS only
    tcp_address="example.com:443",  # the server's TCP listener; the address by default
    fallback_delay=0.3,
    reprobe_interval=300,
)

channel.transport says which one the current connection uses ("quic" or "qmux").

Datagrams

On native QUIC, the messages of directions the schema marks unreliable_requests or unreliable_responses may travel as QUIC datagrams: they can be lost or reordered, but never duplicated, and applications that need ordering add sequence numbers. A request that does not fit a datagram, or finds the connection's datagram queue full, goes on the stream, as every message does over QMux over TLS. Datagram responses are held until the response headers have been read, and a call whose responses ended waits up to 10 ms for the datagrams the server said it sent.

Compression

Messages travel compressed with zstd where the server agrees, negotiated per connection; see Compression. The codec is the standard library's compression.zstd, so it needs no extra dependency; on a Python built without libzstd, nothing is compressed.

  • Dictionaries trained on your messages compress every message of their types:

    compression = trevrpc.Compression(
        [trevrpc.Dictionary(Path("metrics.dict").read_bytes(), ["example.v1.MetricSample"])],
        level=1,
    )
    channel = trevrpc.Channel("example.com:443", compression=compression)
    
  • Without a dictionary, messages of 256 bytes or more compress on methods whose schema sets compression: COMPRESSION_MESSAGE, with no settings.

  • Stream compression compresses each streamed direction of a COMPRESSION_STREAM method against the call's earlier messages, from its third message. Requests compress optimistically, without waiting for the server's answer; a server that refuses gets the call replayed without it, which the caller never sees. Each channel holds at most stream_compression_memory bytes for it (64 MiB by default; negative turns it off), about 350 KiB per direction it decodes and 585 KiB per direction it compresses.

Message types with a field marked debug_redact never compress without a dictionary or with stream compression.

Flow control

Streaming calls read at most 32 messages or 1 MiB ahead of the caller, and writes wait for the transport, so a slow side holds the other back through QUIC flow control. Leaving an async for early does not end the call: use the call as an async with block, or call aclose().

Metadata

Release files for trevrpc 1.13.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 trevrpc 1.13.0
File Size Uploaded Provenance Actions
trevrpc-1.13.0.tar.gz 53.1 kB Without provenance Details for trevrpc-1.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for trevrpc 1.13.0
File Interpreter ABI Platform Actions
trevrpc-1.13.0-py3-none-any.whl Python 3 none any Details for trevrpc-1.13.0-py3-none-any.whl

Total release size: 113.9 kB

Release files / trevrpc-1.13.0.tar.gz

Download URL trevrpc-1.13.0.tar.gz
Size 53.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dc6d2953b67a8e184df511126a72b830b0cb9de6c696533b98aa3ff2cf0f5416
BLAKE2b-256 checksum
How to use checksums
5599ddf77ed8b631e7b168962ebf4107c6b3b91b4788625804aa5da17d0389e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / trevrpc-1.13.0-py3-none-any.whl

Download URL trevrpc-1.13.0-py3-none-any.whl
Size 60.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b6c0e7b5fb426079fbf4769a3f329d94cefdccb70d4bdaeb656047a2e5383a3
BLAKE2b-256 checksum
How to use checksums
fce1868d441775c3bcf791e7fc20b2daff763f0b1d5af6ffac87f5eab8b7ab6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for trevrpc 1.13.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.13.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