Skip to main content

English | 中文

tRPC-Python Framework

Python LICENSE Releases Docs Tests Coverage

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 trpc and http protocols 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 task processes to isolate heavy computation from network I/O)
  • Unified multi-protocol access and Web services (built-in trpc and http protocol support, providing custom @route routing 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 gcc or clang, 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

  1. 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
  1. 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
  1. 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

Examples

See the Examples Index for detailed descriptions.

  • helloworld: Unary Greeter service, listening on 127.0.0.1:8000 by default, plus a custom UDP 8090 protocol example
  • Streaming Service: Covers unary, client streaming, server streaming, and bidirectional streaming, listening on TCP 8000–8040
  • HTTP SSE: GET /sse server-sent events with five process layouts, listening on 8080–8084
  • hellotrt: Tensor echo and normal_task task scheduling, listening on 127.0.0.1:8000 by default
  • HTTP: HTTP RPC and custom @route routing, listening on 9002 / 9003

Plugins

For developing built-in plugins within the framework, please refer to the developer guides:

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.1

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

Source distribution (sdist)

Source distribution for trpc-python 1.0.1
File Size Uploaded Provenance Actions
trpc_python-1.0.1.tar.gz 382.4 kB Without provenance Details for trpc_python-1.0.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for trpc-python 1.0.1
File Actions
trpc_python-1.0.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details for trpc_python-1.0.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
trpc_python-1.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for trpc_python-1.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
trpc_python-1.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for trpc_python-1.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
trpc_python-1.0.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for trpc_python-1.0.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
trpc_python-1.0.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for trpc_python-1.0.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
trpc_python-1.0.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details for trpc_python-1.0.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
trpc_python-1.0.1-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details for trpc_python-1.0.1-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Total release size: 35.3 MB

Release files / trpc_python-1.0.1.tar.gz

Download URL trpc_python-1.0.1.tar.gz
Size 382.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5281f7b1e116af327eeb525a4eea34d43f59999da103cea609330b96fb22a2b2
BLAKE2b-256 checksum
How to use checksums
f6c161cd4bd2ef40771123a45d50e66748d0e461801b9752fe253c0e50dbc00d
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.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL trpc_python-1.0.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.9 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
bb69d14f8f7c0b782f68a15002121709fee5ed0e02c94776cb8e7207d04d98c7
BLAKE2b-256 checksum
How to use checksums
e52aed79641a15fff19a90905e3dbbf0fb5e57d419c87b9996209cfa65cddd15
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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL trpc_python-1.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.0 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b3cdb89642751940c0c9468986a5b3e83cd91a02fe09dec9c975621628d37707
BLAKE2b-256 checksum
How to use checksums
945a78de0798a38a663d86625a207bf4c6459482f09cfe860166cc997e1cacb4
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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL trpc_python-1.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a1cf2c3f9ce71cb4941bfbcb0e395ffde628735a49088166aae019b2fdc74c6d
BLAKE2b-256 checksum
How to use checksums
18b67ac1d6b606b76274fe5d34d1311af4296006c7f55b67208d26702e793b51
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.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL trpc_python-1.0.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.1 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1e4e1f252f08ca38e706b0ba3c3c66d7fdc5186e2c7e7171beddaeab151e15ff
BLAKE2b-256 checksum
How to use checksums
f07d1219696a475748e12d13c55a4e4013a2672e17c0a6cff2e89fcdfe8bba34
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.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL trpc_python-1.0.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6699d50538f2a80544778e36c9559b2c7fd628e8a087c066d44491d756bb3aa4
BLAKE2b-256 checksum
How to use checksums
e56f9288e45ce4c393aefd8cfc7d4b8aaa12ce3d40d988de563901b67576eacc
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.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL trpc_python-1.0.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.9 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ccf7ca6b4cf71ae3eaedbccc62c4eaf9558f5c72acf4cf7deb9412bb7939a064
BLAKE2b-256 checksum
How to use checksums
d02efedd9784c6199e8576bbf6a845ce32bd444daff4558993d2148118610d34
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.1-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL trpc_python-1.0.1-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.0 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
19af1faa38f624a95ad71399d70d2c837f77e062359de4f70c99e7bb36dada83
BLAKE2b-256 checksum
How to use checksums
7879f7155fe503d38c9e2d54d35b624fcd28475e2f06782e5df5196ae13965dd
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.1

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.0.1 This release

8 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