Skip to main content

pygrpc-native

A gRPC server for Python whose HTTP/2 and gRPC work runs in Rust, outside the GIL. Your handlers stay in Python.

With grpcio, every call runs grpcio's own Python layer under the same GIL as your handlers, and on a busy server that layer is often where most of the time goes. pygrpc-native does the framing, flow control, deadlines and cancellation on a small tokio runtime and hands Python each call as an event: an id, the method, the request bytes and who sent it. You decode the protobuf, run the handler and send back the encoded response, so clients and the wire format stay exactly as they are with grpcio.

grpc client ──HTTP/2──▶ tokio threads (no GIL)
                          │ path → method id
                          ▼
                    event queue ──▶ recv_batch() in Python
                          ◀── respond(call_id, bytes) from any thread

Python takes calls in batches, so a burst of requests costs one trip across the GIL instead of one per call.

Install

pip install pygrpc-native

Wheels are published for Linux (x86_64, aarch64) and macOS (arm64, x86_64) and work on CPython 3.10 and later. To build from a checkout:

pip install maturin
maturin develop --release

Example

import threading
from pygrpc_native import EVENT_CALL, NativeGrpcFront

front = NativeGrpcFront("0.0.0.0:50051", [("/echo.Echo/Say", False)])
front.start()

def serve():
    while (events := front.recv_batch(64)) is not None:
        for kind, call_id, method_id, payload, client_key in events:
            if kind == EVENT_CALL:
                front.respond(call_id, payload)

threading.Thread(target=serve).start()

Any grpcio client can call it:

import grpc

with grpc.insecure_channel("localhost:50051") as channel:
    print(channel.unary_unary("/echo.Echo/Say")(b"hello"))

In a real server payload is a serialized protobuf message: decode it with the generated class, run the handler (in a thread pool, if it blocks) and pass the serialized reply to respond.

API

NativeGrpcFront(target, methods, io_threads=2, client_key_metadata=None) binds host:port (every address the host resolves to), unix:path or unix:///path. Port 0 picks a free port. methods lists (path, server_streaming) pairs, where a path is /package.Service/Method and a method's id is its index in the list.

Member Purpose
bound_port the bound TCP port; 1 for a Unix socket, as grpcio reports it
set_fallback(path) forward unknown methods to a grpcio server on a Unix socket
start() start accepting connections
recv_batch(max_events, timeout_ms=None) wait for events with the GIL released; None once closed
respond(call_id, payload) answer a unary call
fail(call_id, code, message) end any call with a non-OK status, without blocking
stream_send(call_id, payload) send one streamed message; blocks while the client is not reading
stream_end(call_id) finish a stream with OK; a stream cut short by close() ends with UNAVAILABLE
stream_open(call_id) whether the client is still reading a stream
close() stop without waiting for calls in flight; their clients get UNAVAILABLE

recv_batch returns (kind, call_id, method_id, payload, client_key) tuples. kind is EVENT_CALL for a new call and EVENT_CANCEL when the client left a stream before it ended (payload and client_key are then None). client_key is the value of the client_key_metadata request metadata when it is set and present, and the peer address otherwise, so calls from the same client can be routed to the same worker.

set_fallback lets one port serve methods you don't list: run a regular grpc.Server on a Unix socket and its methods are proxied there, with its interceptors.

Limitations

  • Unary and server-streaming methods only. Other kinds can go through the fallback server.
  • No TLS or authentication yet, and grpcio interceptors don't run on the listed methods.
  • Clients of a Unix socket server must set grpc.default_authority, since the socket path grpc-core sends as :authority is not valid HTTP/2.
  • Like grpc-core, binding a Unix socket path replaces any socket file already there.
  • Per connection: at most 1024 concurrent streams and 16 KiB of request metadata. A connection that hasn't finished the HTTP/2 preface after 120 s is dropped.

Tests

cargo test --locked --no-default-features
maturin develop --release
pytest tests

License

Apache-2.0

Metadata

Release files for pygrpc-native 0.1.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 pygrpc-native 0.1.0
File Size Uploaded Provenance Actions
pygrpc_native-0.1.0.tar.gz 30.4 kB With provenance Details for pygrpc_native-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pygrpc-native 0.1.0
File Actions
pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
pygrpc_native-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for pygrpc_native-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
pygrpc_native-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for pygrpc_native-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 4.1 MB

Release files / pygrpc_native-0.1.0.tar.gz

Download URL pygrpc_native-0.1.0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
232ddb187cb15c9c8ef24efcd6aa43bc58149f662a6644f3d4ca4ae144ce11dc
BLAKE2b-256 checksum
How to use checksums
31e747f426ce9922288386599c56a8c386141e27fdd60a42792d620192a47317
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
ce80c0c2b642bc3451d34ab3cc345b7630fc476744f3c6d8fd94c8f3c72494a7
BLAKE2b-256 checksum
How to use checksums
11484cf7db4b0cae412fbc5a28ee9cf18162ec046d6dbecd5e1702d47ed90b2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL pygrpc_native-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
38d8462bdc967480809fd5dc774ae1717463904f03182d622e5e8dbbd2796038
BLAKE2b-256 checksum
How to use checksums
e3718601011d92f23450ae5f1ecffcd0cd6bb4a98c57b1f7bbf4f9728bbc7400
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / pygrpc_native-0.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL pygrpc_native-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 963.4 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7c7e723374101396b43eeee6225615ba5dba4470bcaace6eb82ff7f75140b029
BLAKE2b-256 checksum
How to use checksums
55b5139a520aa4bdbfc19ed404b7263e1e41f09651f543b02e0897d5b94019ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / pygrpc_native-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL pygrpc_native-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 992.0 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
975be88ae50d92803a7a5e04c7c969c4615dba1e3e04be7831a92a82a4683768
BLAKE2b-256 checksum
How to use checksums
ac349f58514a67c0b35c25e842ee7961bd11a24b85c2729b3c5df4c17c396016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for pygrpc-native 0.1.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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for pygrpc_native-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

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.

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