Skip to main content

GRPC Router

Release Status Python versions CI Status Documentation Status

GRPC Router is a small component that implements a simple service register to be used for client side service discovery. Services register with the GRPC router, clients request the details of such services in order to discover them and connect directly.

Installation

pip install grpc_router

Requires Python 3.11 or newer.

Usage

Start the router (defaults: bind to [::]:50034 with 10 workers):

grpc-router --hostname 0.0.0.0 --port 50034 --max-workers 10 --shutdown-grace 5

On SIGTERM or SIGINT (Ctrl+C) the router shuts down gracefully: its health status turns NOT_SERVING, new requests are rejected and in-flight requests get --shutdown-grace seconds to complete. A second signal stops it immediately.

A service registers itself and a client looks it up:

from grpc_router.client.client import GRPCRouterClient
from grpc_router.core.models import HealthCheckType

# in the service
with GRPCRouterClient("router.mydomain.com", 50034) as router:
    router.register_service(
        "myorg.billing.invoices", host="invoices1.mydomain.com", port=8080,
        region="us-east", health_check_type=HealthCheckType.ACTIVE_CLIENT,
    )
    ...  # serve requests; the client pushes heartbeats in the background
    router.deregister_service("myorg.billing.invoices")

# in a client of that service
router = GRPCRouterClient("router.mydomain.com", 50034)
host, port = router.get_service("myorg.billing.invoices", region="us-east")

Instances of the same service are returned round robin, preferring the client's own region.

With HealthCheckType.ACTIVE_CLIENT the client sends heartbeats to the router. A service that misses heartbeats, or reports an error with set_health_status(service_id, HEALTH_STATUS_ERROR, "why"), is taken out of service until it reports a healthy status again (HEALTH_STATUS_GOOD or HEALTH_STATUS_WARNING, from grpc_router.stubs.grpc_router_service_pb2).

If the router forgets a service (it restarted, or the service was out of service and silent for longer than the expiry timeout), the client registers the service again on its next heartbeat.

Keeping the register across router restarts

grpc-router --state-file /var/lib/grpc-router/state.json

The router saves its register to that JSON file in the background (at most once per --state-save-interval seconds, default 1, plus on shutdown) and reloads it on start, so clients can find services straight away after a restart, including services without health checks, which never re-register on their own. Restored services have a full health check timeout to send a heartbeat. The file holds the service tokens, so it is created readable by its owner only. Use one file per router. The router also exposes the standard gRPC health checking service, and server reflection (both v1 and v1alpha) so tools like grpcurl can list and describe its API.

Metadata

Release files for grpc-router 0.4.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 grpc-router 0.4.0
File Size Uploaded Provenance Actions
grpc_router-0.4.0.tar.gz 37.4 kB With provenance Details for grpc_router-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grpc-router 0.4.0
File Interpreter ABI Platform Actions
grpc_router-0.4.0-py3-none-any.whl Python 3 none any Details for grpc_router-0.4.0-py3-none-any.whl

Total release size: 61.6 kB

Release files / grpc_router-0.4.0.tar.gz

Download URL grpc_router-0.4.0.tar.gz
Size 37.4 kB
Tags Source
SHA-256 checksum
How to use checksums
908caf9e7379b1fb32a2499586590bc326b174726b03f2750b2ec47250d9fa0b
BLAKE2b-256 checksum
How to use checksums
42fe544418295f41a08faee628f76b0d3e465b588096166a28a8c34c2827eee7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 27, 2026.

Transparency log

Release files / grpc_router-0.4.0-py3-none-any.whl

Download URL grpc_router-0.4.0-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6b8a7babe6c289e4cc9723f289fe9a9b28c75c2985d8eda457f49232a753d56
BLAKE2b-256 checksum
How to use checksums
840eb63c95ffe2ae1d3f70dc36f01b18e02e7e3e3c0c9f3a05458919874a0a3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 27, 2026.

Transparency log

Security for grpc-router 0.4.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for grpc_router-0.4.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 Nov 27, 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