English | 中文
tRPC-Python Framework
tRPC-Python is the Python language implementation of tRPC. It is a pluggable, high-performance RPC framework that enables rapid development of RPC services through pluggable protocols, filters, and service governance components.
For more information, please refer to the Quick Start and Detailed Documentation.
Framework Features
tRPC-Python has the following features:
- Multi-Service Listening: Multiple services can be started within a single process, listening on multiple addresses simultaneously.
- Fully Pluggable Components: All components are designed to be pluggable, with built-in default implementations for core functionalities that can be replaced on demand; third-party components can also be implemented and registered into the framework.
- Multi-Protocol Interoperability: Supports extending any third-party protocol (simply by implementing the protocol's packing and unpacking interfaces). Built-in support for
trpcandhttpprotocols is provided by default and can be switched at any time. - Multiple Process Models: Provides multiple process models that can be flexibly selected via
global.processmodel(defaults to single-process mode). - Code Generation Tool: Provides the trpc command-line tool to generate Python stub code from protobuf with one click.
Use Cases
- High-performance cross-language microservice communication (based on Protocol Buffers, seamlessly interoperating with the multi-language tRPC ecosystem)
- Streaming data transmission and real-time interaction (supporting client streaming, server streaming, bidirectional streaming RPC, and HTTP SSE)
- AI model inference and compute-intensive services (supporting Tensor transmission and standalone
taskprocesses to isolate heavy computation from network I/O) - Unified multi-protocol access and Web services (built-in
trpcandhttpprotocol support, providing custom@routerouting and custom protocol extensions) - High-concurrency and multi-core scaling services (supporting single-process, multi-process, I/O and Handle separation, and other process models)
- Pluggable microservice governance integration (supporting naming services, configuration centers, logging, metrics monitoring, task scheduling, and filter extensions)
- Single-process multi-service aggregated deployment (mounting multiple logical services within the same process, listening on TCP, UDP, or Unix Domain Socket simultaneously)
Quick Start
Prerequisites
- Python 3.8+ (Python 3.10+ recommended)
- C compiler toolchain (such as
gccorclang, used to compile Cython extensions during installation) - tRPC command-line tool (optional, used to generate Python stub code from protobuf)
Installation
Install with pip
pip install trpc-python
Install optional extras on demand (such as uvloop acceleration and snappy compression):
pip install "trpc-python[fast,snappy]"
Install with uv
uv provides a faster and reproducible installation experience:
# macOS / Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or on macOS: brew install uv
# Install the published package in a virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv pip install trpc-python
# Install optional extras on demand
uv pip install "trpc-python[fast,snappy]"
For projects managed by uv:
# Core capabilities only
uv add trpc-python
# With optional extras
# uv add "trpc-python[fast,snappy]"
When developing this repository:
git clone --depth 1 https://github.com/trpc-group/trpc-python.git
cd trpc-python
# Option 1: Sync dev and test dependencies with uv
uv sync --extra dev --group test
# Option 2: Install using a virtual environment and pip / build script
python3 -m venv .venv
source .venv/bin/activate
./build.sh
Develop a Greeter RPC Service
- Define the protobuf service (
helloworld.proto) and generate stub code:
syntax = "proto3";
package trpc.trpc_python_group.helloworld;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string msg = 1;
}
message HelloReply {
string msg = 1;
}
trpc create --lang=python -p helloworld.proto --rpconly -f
- Write the server configuration file (
trpc_python.yaml):
server:
service:
- name: trpc.trpc_python_group.helloworld.Greeter
ip: 127.0.0.1
port: 8000
network: tcp
protocol: trpc
timeout: 5000
- Implement the server and client code:
# server.py
from trpc_sdk.abc import TrpcContext
from trpc_sdk.server import create_server
from trpc_trpc_python_group_helloworld import pb, rpc
class GreeterServicer(rpc.GreeterServicer):
async def SayHello(self, ctx: TrpcContext, request: pb.HelloRequest) -> pb.HelloReply:
rsp = pb.HelloReply()
rsp.msg = f"hello: {request.msg}"
return rsp
if __name__ == "__main__":
server = create_server("trpc_python.yaml")
rpc.register_GreeterServicer_server(server, GreeterServicer(), fix_rpc_name=True)
server.serve()
# client.py
import asyncio
from trpc_sdk.abc import TrpcContext
from trpc_sdk.client import Options
from trpc_sdk.serialization import SerializationType
from trpc_trpc_python_group_helloworld import pb, rpc
async def main():
proxy = rpc.GreeterClientProxyImpl(need_clone_ctx=False)
req = pb.HelloRequest(msg="hello")
options = (
Options()
.set_target("ip://127.0.0.1:8000")
.set_protocol("trpc")
.set_serialization_type(SerializationType.PB)
.set_network("tcp")
)
rsp = await proxy.asyncSayHello(TrpcContext(), req, options)
print(rsp.msg)
if __name__ == "__main__":
asyncio.run(main())
Run the Example Service
The repository includes an out-of-the-box helloworld example. You can start the server and invoke it from the client directly:
# Terminal 1: Start the server (listens on 127.0.0.1:8000 by default)
python examples/helloworld/trpc_main.py
# Terminal 2: Run the client call (outputs hello: hello)
python examples/helloworld/test_greeter.py
Related Documentation
- Quick Start
- Basics Tutorial
- Framework Configuration
- Server Development Guide
- Client Development Guide
- Documentation Index
Examples
See the Examples Index for detailed descriptions.
- helloworld: Unary Greeter service, listening on
127.0.0.1:8000by default, plus a custom UDP8090protocol example - Streaming Service: Covers unary, client streaming, server streaming, and bidirectional streaming, listening on TCP
8000–8040 - HTTP SSE:
GET /sseserver-sent events with five process layouts, listening on8080–8084 - hellotrt: Tensor echo and
normal_tasktask scheduling, listening on127.0.0.1:8000by default - HTTP: HTTP RPC and custom
@routerouting, listening on9002/9003
Plugins
For developing built-in plugins within the framework, please refer to the developer guides:
- Plugin Development Basics
- Protocol Plugin
- Config Plugin
- Task Plugin
- Log Plugin
- Metrics Plugin
- Database Plugin
For more plugins integrating with external governance components, please refer to the tRPC Ecosystem Repositories.
How to Contribute
We warmly welcome community contributions! If you are interested in contributing, please read our Contribution Guidelines and check the unassigned tasks in Issues. Claim a task and let's make tRPC-Python better together.
Ways to Contribute
- Report Bugs or Suggest Features - Report issues or propose new features via Issues
- Improve Documentation - Enhance tutorials, examples, and API references to help fellow developers get started quickly
- Submit PRs - Participate in bug fixes, new feature development, performance optimizations, or test coverage improvements
- Extend Plugins & Share Use Cases - Develop ecosystem plugins or share your RPC service best practices
Quick Contribution Setup
# Fork and clone the repository
git clone https://github.com/YOUR_USERNAME/trpc-python.git
cd trpc-python
# Install development and test dependencies, then run tests
pip install -e ".[dev,fast,snappy]"
pip install -r requirements-test.txt
pytest
# Make your changes and submit a PR!
Please read CONTRIBUTING.md for detailed contribution workflows and coding standards.
Please follow CODE-OF-CONDUCT.md to help maintain a friendly, respectful, and inclusive open-source community.
Metadata
Release files for trpc-python 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trpc_python-1.0.0.tar.gz | 384.8 kB | Without provenance | Details for trpc_python-1.0.0.tar.gz |
Built distributions (wheels)
Total release size: 35.3 MB
Release files / trpc_python-1.0.0.tar.gz
| Download URL | trpc_python-1.0.0.tar.gz |
|---|---|
| Size | 384.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f945c2dbcfac542d8e8e4f1d527f1dd18ea52e86f9fc5194a479c4eb22534445
|
|
BLAKE2b-256 checksum How to use checksums |
a06ef3e5a6f6c266c94655663de91daaa5ef3a8c34be0c90f662543c4e766efb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / trpc_python-1.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trpc_python-1.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
103cd6a2d5a61bccc1db63a3798addc55cf212dbb8c1d72fc7a485bbe6587e67
|
|
BLAKE2b-256 checksum How to use checksums |
a671b3cb85206ce624f1d69d9f4a197da47a8f792cce0331b8c6284f498f3e27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / trpc_python-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trpc_python-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ebf3f830a4c1ca4e156a433fed0b72a3d9987d9cd134a064439fc0ef40ef9c8d
|
|
BLAKE2b-256 checksum How to use checksums |
b8ad84249a416046de87da08ce460bf5447bf8072dab42dd099c869fc4679a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / trpc_python-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trpc_python-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
a07a8e9c254e9315921ead3ad7934f6593b0ca7faa20b0d67bbb8c6cbe5beb3b
|
|
BLAKE2b-256 checksum How to use checksums |
4784765a61afcb897b435a7061f94bd4a1a85120772541a195a16aa3ee404ea4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / trpc_python-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trpc_python-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ada4e90bb9dd7da16e372ac095ccc44738caa04103880e51c5bccaa9397349a6
|
|
BLAKE2b-256 checksum How to use checksums |
d506f61fd809b8e750bf68d0c0a7f84f556248ec1530cce1ca9ae5992e98d15c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / trpc_python-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trpc_python-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ca57d61afbdac9cb7001b4fa2ca3b204ca33a5fe57fdf1a7c47a53652b12fef0
|
|
BLAKE2b-256 checksum How to use checksums |
c2cfdc3abdef4bdc089f1d1253860d515b5f7c457d14bbd745f8de9687f4c6ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / trpc_python-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trpc_python-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
d56ca30322bc748b20135a06ae3511938ce5788cd71c5281e5ebea2f26bd2116
|
|
BLAKE2b-256 checksum How to use checksums |
065183be6b6c36c56ecc978d8593e9913e1c3b5ef769a20431a56ca81585f282
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / trpc_python-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | trpc_python-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
07637807eaf71de3c9341916d0dc89d5b58444ecc9f286b00096ee7cb6ab04a4
|
|
BLAKE2b-256 checksum How to use checksums |
2f963ef84d93d4a52f29d72ca2e55ea8b2b5630ea948cbcc3f76ad22537e606e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Security for trpc-python 1.0.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.