trevrpc 1.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
trevrpc-1.13.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 trev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: trevrpc
3
+ Version: 1.13.0
4
+ Summary: A client for TrevRPC, a protobuf RPC framework over QUIC
5
+ Keywords: rpc,quic,protobuf,qmux,asyncio
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Framework :: AsyncIO
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Topic :: Internet
16
+ Classifier: Topic :: System :: Networking
17
+ Classifier: Typing :: Typed
18
+ Requires-Dist: aioquic>=1.9,<1.10
19
+ Requires-Dist: protobuf-py>=0.7,<0.8
20
+ Requires-Python: >=3.14
21
+ Project-URL: Homepage, https://trev.zip/llc/TrevRPC
22
+ Project-URL: Documentation, https://trev.zip/llc/TrevRPC/wiki/Python-Guide
23
+ Project-URL: Repository, https://trev.zip/llc/TrevRPC
24
+ Project-URL: Issues, https://trev.zip/llc/TrevRPC/issues
25
+ Project-URL: Changelog, https://trev.zip/llc/TrevRPC/releases
26
+ Description-Content-Type: text/markdown
27
+
28
+ # trevrpc
29
+
30
+ A Python client for [TrevRPC](https://trev.zip/llc/TrevRPC), a protobuf RPC framework over QUIC.
31
+
32
+ It calls TrevRPC services over native QUIC with [aioquic](https://github.com/aiortc/aioquic), and over
33
+ QMux over TLS on the server's TCP listener where UDP is blocked, on messages generated by
34
+ [protobuf-py](https://github.com/bufbuild/protobuf-py). It is a client only, asyncio only, and requires
35
+ Python 3.14.
36
+
37
+ See the [Python Guide](https://trev.zip/llc/TrevRPC/wiki/Python-Guide) for the whole API, and
38
+ [#666](https://trev.zip/llc/TrevRPC/issues/666) for what is still in progress.
39
+
40
+ ## Installing
41
+
42
+ ```sh
43
+ pip install trevrpc # or: uv add trevrpc
44
+ pip install protoc-gen-py protoc-gen-trevrpc-py # the protoc plugins, for generating code
45
+ ```
46
+
47
+ ## Generating a client
48
+
49
+ `protoc-gen-py` generates the messages and `protoc-gen-trevrpc-py` the clients, next to them:
50
+
51
+ ```yaml
52
+ # buf.gen.yaml
53
+ version: v2
54
+ plugins:
55
+ - local: protoc-gen-py
56
+ out: gen
57
+ - local: protoc-gen-trevrpc-py
58
+ out: gen
59
+ ```
60
+
61
+ ## Calling a service
62
+
63
+ ```python
64
+ import trevrpc
65
+ from gen.greeter_pb import HelloRequest
66
+ from gen.greeter_trevrpc import GreeterClient
67
+
68
+ async with trevrpc.Channel("example.com:443") as channel:
69
+ greeter = GreeterClient(channel)
70
+
71
+ # unary
72
+ reply = await greeter.say_hello(HelloRequest(name="Ada"), timeout=5)
73
+
74
+ # server streaming
75
+ async with greeter.watch(HelloRequest(name="Ada")) as replies:
76
+ async for reply in replies:
77
+ print(reply.message)
78
+
79
+ # client streaming
80
+ upload = greeter.upload()
81
+ await upload.send_all(requests)
82
+ reply = await upload.close_and_recv()
83
+
84
+ # bidirectional streaming
85
+ async with greeter.chat() as chat:
86
+ await chat.send(HelloRequest(name="Ada"))
87
+ reply = await chat.recv()
88
+ await chat.close_send()
89
+ ```
90
+
91
+ Every method takes the call options as keyword arguments: `timeout` (seconds), `metadata`,
92
+ `max_frame_size` (at most the channel's, 4 MiB by default; a larger value raises
93
+ `INVALID_ARGUMENT`), and the `on_response_headers` and `on_response_metadata` callbacks. A call that
94
+ does not end with an OK status raises `trevrpc.TrevRpcError`, which carries the status's code,
95
+ message, trailing metadata and details (`retry_delay`, `find_details()`).
96
+
97
+ ## Connection metadata
98
+
99
+ Metadata that every call of a channel carries, such as a bearer token, can be set once on the
100
+ channel. Each connection carries it until the server confirms it stored it, and later calls refer to
101
+ it by ID instead of repeating it. A call's own metadata wins for a key both have.
102
+
103
+ ```python
104
+ channel = trevrpc.Channel(
105
+ "example.com:443", connection_metadata={"authorization": f"Bearer {token}"}
106
+ )
107
+ channel.set_connection_metadata({"authorization": f"Bearer {refreshed}"}) # later calls
108
+ ```
109
+
110
+ ## Transports
111
+
112
+ A channel connects over QUIC and falls back to QMux over TLS (ALPN `qmux-02.trevrpc-1`) when QUIC
113
+ has not connected within 300 ms, or failed: the first to connect wins. After the fallback won,
114
+ reconnects use it directly for 5 minutes before they race again. A call never moves between
115
+ connections. The channel options set this up:
116
+
117
+ ```python
118
+ channel = trevrpc.Channel(
119
+ "example.com:443",
120
+ transport="auto", # or "quic", or "tcp" for QMux over TLS only
121
+ tcp_address="example.com:443", # the server's TCP listener; the address by default
122
+ fallback_delay=0.3,
123
+ reprobe_interval=300,
124
+ )
125
+ ```
126
+
127
+ `channel.transport` says which one the current connection uses (`"quic"` or `"qmux"`).
128
+
129
+ ## Datagrams
130
+
131
+ On native QUIC, the messages of directions the schema marks `unreliable_requests` or
132
+ `unreliable_responses` may travel as QUIC datagrams: they can be lost or reordered, but never
133
+ duplicated, and applications that need ordering add sequence numbers. A request that does not fit a
134
+ datagram, or finds the connection's datagram queue full, goes on the stream, as every message does
135
+ over QMux over TLS. Datagram responses are held until the response headers have been read, and a
136
+ call whose responses ended waits up to 10 ms for the datagrams the server said it sent.
137
+
138
+ ## Compression
139
+
140
+ Messages travel compressed with zstd where the server agrees, negotiated per connection; see
141
+ [Compression](https://trev.zip/llc/TrevRPC/wiki/Compression). The codec is the standard library's
142
+ `compression.zstd`, so it needs no extra dependency; on a Python built without libzstd, nothing is
143
+ compressed.
144
+
145
+ - **Dictionaries** trained on your messages compress every message of their types:
146
+
147
+ ```python
148
+ compression = trevrpc.Compression(
149
+ [trevrpc.Dictionary(Path("metrics.dict").read_bytes(), ["example.v1.MetricSample"])],
150
+ level=1,
151
+ )
152
+ channel = trevrpc.Channel("example.com:443", compression=compression)
153
+ ```
154
+
155
+ - **Without a dictionary**, messages of 256 bytes or more compress on methods whose schema sets
156
+ `compression: COMPRESSION_MESSAGE`, with no settings.
157
+ - **Stream compression** compresses each streamed direction of a `COMPRESSION_STREAM` method
158
+ against the call's earlier messages, from its third message. Requests compress optimistically,
159
+ without waiting for the server's answer; a server that refuses gets the call replayed without
160
+ it, which the caller never sees. Each channel holds at most `stream_compression_memory` bytes
161
+ for it (64 MiB by default; negative turns it off), about 350 KiB per direction it decodes and
162
+ 585 KiB per direction it compresses.
163
+
164
+ Message types with a field marked `debug_redact` never compress without a dictionary or with
165
+ stream compression.
166
+
167
+ ## Flow control
168
+
169
+ Streaming calls read at most 32 messages or 1 MiB ahead of the caller, and writes wait for the
170
+ transport, so a slow side holds the other back through QUIC flow control. Leaving an `async for`
171
+ early does not end the call: use the call as an `async with` block, or call `aclose()`.
@@ -0,0 +1,144 @@
1
+ # trevrpc
2
+
3
+ A Python client for [TrevRPC](https://trev.zip/llc/TrevRPC), a protobuf RPC framework over QUIC.
4
+
5
+ It calls TrevRPC services over native QUIC with [aioquic](https://github.com/aiortc/aioquic), and over
6
+ QMux over TLS on the server's TCP listener where UDP is blocked, on messages generated by
7
+ [protobuf-py](https://github.com/bufbuild/protobuf-py). It is a client only, asyncio only, and requires
8
+ Python 3.14.
9
+
10
+ See the [Python Guide](https://trev.zip/llc/TrevRPC/wiki/Python-Guide) for the whole API, and
11
+ [#666](https://trev.zip/llc/TrevRPC/issues/666) for what is still in progress.
12
+
13
+ ## Installing
14
+
15
+ ```sh
16
+ pip install trevrpc # or: uv add trevrpc
17
+ pip install protoc-gen-py protoc-gen-trevrpc-py # the protoc plugins, for generating code
18
+ ```
19
+
20
+ ## Generating a client
21
+
22
+ `protoc-gen-py` generates the messages and `protoc-gen-trevrpc-py` the clients, next to them:
23
+
24
+ ```yaml
25
+ # buf.gen.yaml
26
+ version: v2
27
+ plugins:
28
+ - local: protoc-gen-py
29
+ out: gen
30
+ - local: protoc-gen-trevrpc-py
31
+ out: gen
32
+ ```
33
+
34
+ ## Calling a service
35
+
36
+ ```python
37
+ import trevrpc
38
+ from gen.greeter_pb import HelloRequest
39
+ from gen.greeter_trevrpc import GreeterClient
40
+
41
+ async with trevrpc.Channel("example.com:443") as channel:
42
+ greeter = GreeterClient(channel)
43
+
44
+ # unary
45
+ reply = await greeter.say_hello(HelloRequest(name="Ada"), timeout=5)
46
+
47
+ # server streaming
48
+ async with greeter.watch(HelloRequest(name="Ada")) as replies:
49
+ async for reply in replies:
50
+ print(reply.message)
51
+
52
+ # client streaming
53
+ upload = greeter.upload()
54
+ await upload.send_all(requests)
55
+ reply = await upload.close_and_recv()
56
+
57
+ # bidirectional streaming
58
+ async with greeter.chat() as chat:
59
+ await chat.send(HelloRequest(name="Ada"))
60
+ reply = await chat.recv()
61
+ await chat.close_send()
62
+ ```
63
+
64
+ Every method takes the call options as keyword arguments: `timeout` (seconds), `metadata`,
65
+ `max_frame_size` (at most the channel's, 4 MiB by default; a larger value raises
66
+ `INVALID_ARGUMENT`), and the `on_response_headers` and `on_response_metadata` callbacks. A call that
67
+ does not end with an OK status raises `trevrpc.TrevRpcError`, which carries the status's code,
68
+ message, trailing metadata and details (`retry_delay`, `find_details()`).
69
+
70
+ ## Connection metadata
71
+
72
+ Metadata that every call of a channel carries, such as a bearer token, can be set once on the
73
+ channel. Each connection carries it until the server confirms it stored it, and later calls refer to
74
+ it by ID instead of repeating it. A call's own metadata wins for a key both have.
75
+
76
+ ```python
77
+ channel = trevrpc.Channel(
78
+ "example.com:443", connection_metadata={"authorization": f"Bearer {token}"}
79
+ )
80
+ channel.set_connection_metadata({"authorization": f"Bearer {refreshed}"}) # later calls
81
+ ```
82
+
83
+ ## Transports
84
+
85
+ A channel connects over QUIC and falls back to QMux over TLS (ALPN `qmux-02.trevrpc-1`) when QUIC
86
+ has not connected within 300 ms, or failed: the first to connect wins. After the fallback won,
87
+ reconnects use it directly for 5 minutes before they race again. A call never moves between
88
+ connections. The channel options set this up:
89
+
90
+ ```python
91
+ channel = trevrpc.Channel(
92
+ "example.com:443",
93
+ transport="auto", # or "quic", or "tcp" for QMux over TLS only
94
+ tcp_address="example.com:443", # the server's TCP listener; the address by default
95
+ fallback_delay=0.3,
96
+ reprobe_interval=300,
97
+ )
98
+ ```
99
+
100
+ `channel.transport` says which one the current connection uses (`"quic"` or `"qmux"`).
101
+
102
+ ## Datagrams
103
+
104
+ On native QUIC, the messages of directions the schema marks `unreliable_requests` or
105
+ `unreliable_responses` may travel as QUIC datagrams: they can be lost or reordered, but never
106
+ duplicated, and applications that need ordering add sequence numbers. A request that does not fit a
107
+ datagram, or finds the connection's datagram queue full, goes on the stream, as every message does
108
+ over QMux over TLS. Datagram responses are held until the response headers have been read, and a
109
+ call whose responses ended waits up to 10 ms for the datagrams the server said it sent.
110
+
111
+ ## Compression
112
+
113
+ Messages travel compressed with zstd where the server agrees, negotiated per connection; see
114
+ [Compression](https://trev.zip/llc/TrevRPC/wiki/Compression). The codec is the standard library's
115
+ `compression.zstd`, so it needs no extra dependency; on a Python built without libzstd, nothing is
116
+ compressed.
117
+
118
+ - **Dictionaries** trained on your messages compress every message of their types:
119
+
120
+ ```python
121
+ compression = trevrpc.Compression(
122
+ [trevrpc.Dictionary(Path("metrics.dict").read_bytes(), ["example.v1.MetricSample"])],
123
+ level=1,
124
+ )
125
+ channel = trevrpc.Channel("example.com:443", compression=compression)
126
+ ```
127
+
128
+ - **Without a dictionary**, messages of 256 bytes or more compress on methods whose schema sets
129
+ `compression: COMPRESSION_MESSAGE`, with no settings.
130
+ - **Stream compression** compresses each streamed direction of a `COMPRESSION_STREAM` method
131
+ against the call's earlier messages, from its third message. Requests compress optimistically,
132
+ without waiting for the server's answer; a server that refuses gets the call replayed without
133
+ it, which the caller never sees. Each channel holds at most `stream_compression_memory` bytes
134
+ for it (64 MiB by default; negative turns it off), about 350 KiB per direction it decodes and
135
+ 585 KiB per direction it compresses.
136
+
137
+ Message types with a field marked `debug_redact` never compress without a dictionary or with
138
+ stream compression.
139
+
140
+ ## Flow control
141
+
142
+ Streaming calls read at most 32 messages or 1 MiB ahead of the caller, and writes wait for the
143
+ transport, so a slow side holds the other back through QUIC flow control. Leaving an `async for`
144
+ early does not end the call: use the call as an `async with` block, or call `aclose()`.
@@ -0,0 +1,76 @@
1
+ [project]
2
+ name = "trevrpc"
3
+ version = "1.13.0"
4
+ description = "A client for TrevRPC, a protobuf RPC framework over QUIC"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.14"
9
+ dependencies = [
10
+ "aioquic>=1.9,<1.10",
11
+ "protobuf-py>=0.7,<0.8",
12
+ ]
13
+ keywords = [
14
+ "rpc",
15
+ "quic",
16
+ "protobuf",
17
+ "qmux",
18
+ "asyncio",
19
+ ]
20
+ classifiers = [
21
+ "Development Status :: 3 - Alpha",
22
+ "Framework :: AsyncIO",
23
+ "Intended Audience :: Developers",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Topic :: Internet",
29
+ "Topic :: System :: Networking",
30
+ "Typing :: Typed",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://trev.zip/llc/TrevRPC"
35
+ Documentation = "https://trev.zip/llc/TrevRPC/wiki/Python-Guide"
36
+ Repository = "https://trev.zip/llc/TrevRPC"
37
+ Issues = "https://trev.zip/llc/TrevRPC/issues"
38
+ Changelog = "https://trev.zip/llc/TrevRPC/releases"
39
+
40
+ [dependency-groups]
41
+ dev = ["pytest>=9"]
42
+
43
+ [build-system]
44
+ requires = ["uv_build>=0.11,<0.14"]
45
+ build-backend = "uv_build"
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
49
+
50
+ [tool.pyright]
51
+ include = [
52
+ "src",
53
+ "tests",
54
+ "interop",
55
+ "protoc-gen-trevrpc-py/src",
56
+ ]
57
+ exclude = ["**/*_pb.py"]
58
+ pythonVersion = "3.14"
59
+ typeCheckingMode = "strict"
60
+
61
+ [[tool.pyright.executionEnvironments]]
62
+ root = "src"
63
+
64
+ [[tool.pyright.executionEnvironments]]
65
+ root = "tests"
66
+ extraPaths = [
67
+ "src",
68
+ ".",
69
+ ]
70
+
71
+ [[tool.pyright.executionEnvironments]]
72
+ root = "interop"
73
+ extraPaths = ["src"]
74
+
75
+ [[tool.pyright.executionEnvironments]]
76
+ root = "protoc-gen-trevrpc-py/src"
@@ -0,0 +1,62 @@
1
+ [project]
2
+ name = "trevrpc"
3
+ version = "1.13.0"
4
+ description = "A client for TrevRPC, a protobuf RPC framework over QUIC"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.14"
9
+ dependencies = [
10
+ # The receive backpressure in _quic.py relies on 1.9's flow-control internals.
11
+ "aioquic>=1.9,<1.10",
12
+ # Pre-1.0: code protoc-gen-py generates must match the runtime's minor version.
13
+ "protobuf-py>=0.7,<0.8",
14
+ ]
15
+ keywords = ["rpc", "quic", "protobuf", "qmux", "asyncio"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Framework :: AsyncIO",
19
+ "Intended Audience :: Developers",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3 :: Only",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Topic :: Internet",
25
+ "Topic :: System :: Networking",
26
+ "Typing :: Typed",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://trev.zip/llc/TrevRPC"
31
+ Documentation = "https://trev.zip/llc/TrevRPC/wiki/Python-Guide"
32
+ Repository = "https://trev.zip/llc/TrevRPC"
33
+ Issues = "https://trev.zip/llc/TrevRPC/issues"
34
+ Changelog = "https://trev.zip/llc/TrevRPC/releases"
35
+
36
+ [dependency-groups]
37
+ dev = ["pytest>=9"]
38
+
39
+ [build-system]
40
+ requires = ["uv_build>=0.11,<0.14"]
41
+ build-backend = "uv_build"
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
45
+
46
+ [tool.pyright]
47
+ include = ["src", "tests", "interop", "protoc-gen-trevrpc-py/src"]
48
+ # protobuf-py's generated messages are not checked strictly; the clients next to them are.
49
+ exclude = ["**/*_pb.py"]
50
+ executionEnvironments = [
51
+ { root = "src" },
52
+ { root = "tests", extraPaths = [
53
+ "src",
54
+ ".",
55
+ ] },
56
+ { root = "interop", extraPaths = [
57
+ "src",
58
+ ] },
59
+ { root = "protoc-gen-trevrpc-py/src" },
60
+ ]
61
+ pythonVersion = "3.14"
62
+ typeCheckingMode = "strict"
@@ -0,0 +1,55 @@
1
+ """TrevRPC for Python: a client for TrevRPC services over native QUIC and QMux over TLS.
2
+
3
+ Generate a client for your service with `protoc-gen-py` (protobuf-py's messages) and
4
+ `protoc-gen-trevrpc-py`, then call it on a `Channel`::
5
+
6
+ import trevrpc
7
+ from gen.greeter_trevrpc import GreeterClient
8
+ from gen.greeter_pb import HelloRequest
9
+
10
+ async with trevrpc.Channel("example.com:443") as channel:
11
+ greeter = GreeterClient(channel)
12
+ reply = await greeter.say_hello(HelloRequest(name="Ada"), timeout=5)
13
+ """
14
+
15
+ from ._call import (
16
+ BidiStreamingCall,
17
+ CallOptions,
18
+ ClientStreamingCall,
19
+ ResponseStream,
20
+ Status,
21
+ )
22
+ from ._channel import Channel, ChannelOptions, Transport, TransportPolicy, connect
23
+ from ._compression import Compression, Dictionary
24
+ from ._frames import DEFAULT_MAX_FRAME_SIZE
25
+ from ._metadata import Metadata, MetadataInput
26
+ from ._method import Method, MethodCompression, MethodKind
27
+ from ._qmux import QMUX_ALPN
28
+ from ._quic import ALPN
29
+ from ._status import Code, StatusDetail, TrevRpcError
30
+
31
+ __all__ = [
32
+ "ALPN",
33
+ "DEFAULT_MAX_FRAME_SIZE",
34
+ "QMUX_ALPN",
35
+ "BidiStreamingCall",
36
+ "CallOptions",
37
+ "Channel",
38
+ "ChannelOptions",
39
+ "ClientStreamingCall",
40
+ "Code",
41
+ "Compression",
42
+ "Dictionary",
43
+ "Metadata",
44
+ "MetadataInput",
45
+ "Method",
46
+ "MethodCompression",
47
+ "MethodKind",
48
+ "ResponseStream",
49
+ "Status",
50
+ "StatusDetail",
51
+ "Transport",
52
+ "TransportPolicy",
53
+ "TrevRpcError",
54
+ "connect",
55
+ ]