Metadata-Version: 2.5
Name: grpc-client-kit
Version: 0.1.0
Summary: Batteries-optional async gRPC client toolkit (channel pool, load balancing, health checking, streaming-aware interceptors, observability)
Project-URL: Repository, https://github.com/bedrock-python/grpc-client-kit
Project-URL: Documentation, https://bedrock-python.github.io/grpc-client-kit/
Project-URL: Changelog, https://github.com/bedrock-python/grpc-client-kit/blob/master/CHANGELOG.md
Project-URL: Bug Tracker, https://github.com/bedrock-python/grpc-client-kit/issues
Author-email: Alex Shalaev <shalaevad.alexey@gmail.com>
License: Apache License
        Version 2.0, January 2004
        http://www.apache.org/licenses/
        
        TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
        1. Definitions.
        
        "License" shall mean the terms and conditions for use, reproduction,
        and distribution as defined by Sections 1 through 9 of this document.
        
        "Licensor" shall mean the copyright owner or entity authorized by
        the copyright owner that is granting the License.
        
        "Legal Entity" shall mean the union of the acting entity and all
        other entities that control, are controlled by, or are under common
        control with that entity. For the purposes of this definition,
        "control" means (i) the power, direct or indirect, to cause the
        direction or management of such entity, whether by contract or
        otherwise, or (ii) ownership of fifty percent (50%) or more of the
        outstanding shares, or (iii) beneficial ownership of such entity.
        
        "You" (or "Your") shall mean an individual or Legal Entity
        exercising permissions granted by this License.
        
        "Source" form shall mean the preferred form for making modifications,
        including but not limited to software source code, documentation
        source, and configuration files.
        
        "Object" form shall mean any form resulting from mechanical
        transformation or translation of a Source form, including but
        not limited to compiled object code, generated documentation,
        and conversions to other media types.
        
        "Work" shall mean the work of authorship, whether in Source or
        Object form, made available under the License, as indicated by a
        copyright notice that is included in or attached to the work
        (an example is provided in the Appendix below).
        
        "Derivative Works" shall mean any work, whether in Source or Object
        form, that is based on (or derived from) the Work and for which the
        editorial revisions, annotations, elaborations, or other modifications
        represent, as a whole, an original work of authorship. For the purposes
        of this License, Derivative Works shall not include works that remain
        separable from, or merely link (or bind by name) to the interfaces of,
        the Work and Derivative Works thereof.
        
        "Contribution" shall mean any work of authorship, including
        the original version of the Work and any modifications or additions
        to that Work or Derivative Works thereof, that is intentionally
        submitted to Licensor for inclusion in the Work by the copyright owner
        or by an individual or Legal Entity authorized to submit on behalf of
        the copyright owner. For the purposes of this definition, "submitted"
        means any form of electronic, verbal, or written communication sent
        to the Licensor or its representatives, including but not limited to
        communication on electronic mailing lists, source code control systems,
        and issue tracking systems that are managed by, or on behalf of, the
        Licensor for the purpose of discussing and improving the Work, but
        excluding communication that is conspicuously marked or otherwise
        designated in writing by the copyright owner as "Not a Contribution."
        
        "Contributor" shall mean Licensor and any individual or Legal Entity
        on behalf of whom a Contribution has been received by Licensor and
        subsequently incorporated within the Work.
        
        2. Grant of Copyright License. Subject to the terms and conditions of
        this License, each Contributor hereby grants to You a perpetual,
        worldwide, non-exclusive, no-charge, royalty-free, irrevocable
        copyright license to reproduce, prepare Derivative Works of,
        publicly display, publicly perform, sublicense, and distribute the
        Work and such Derivative Works in Source or Object form.
        
        3. Grant of Patent License. Subject to the terms and conditions of
        this License, each Contributor hereby grants to You a perpetual,
        worldwide, non-exclusive, no-charge, royalty-free, irrevocable
        (except as stated in this section) patent license to make, have made,
        use, offer to sell, sell, import, and otherwise transfer the Work,
        where such license applies only to those patent claims licensable
        by such Contributor that are necessarily infringed by their
        Contribution(s) alone or by combination of their Contribution(s)
        with the Work to which such Contribution(s) was submitted. If You
        institute patent litigation against any entity (including a
        cross-claim or counterclaim in a lawsuit) alleging that the Work
        or a Contribution incorporated within the Work constitutes direct
        or contributory patent infringement, then any patent licenses
        granted to You under this License for that Work shall terminate
        as of the date such litigation is filed.
        
        4. Redistribution. You may reproduce and distribute copies of the
        Work or Derivative Works thereof in any medium, with or without
        modifications, and in Source or Object form, provided that You
        meet the following conditions:
        
        (a) You must give any other recipients of the Work or
        Derivative Works a copy of this License; and
        
        (b) You must cause any modified files to carry prominent notices
        stating that You changed the files; and
        
        (c) You must retain, in the Source form of any Derivative Works
        that You distribute, all copyright, patent, trademark, and
        attribution notices from the Source form of the Work,
        excluding those notices that do not pertain to any part of
        the Derivative Works; and
        
        (d) If the Work includes a "NOTICE" text file as part of its
        distribution, then any Derivative Works that You distribute must
        include a readable copy of the attribution notices contained
        within such NOTICE file, excluding those notices that do not
        pertain to any part of the Derivative Works, in at least one
        of the following places: within a NOTICE text file distributed
        as part of the Derivative Works; within the Source form or
        documentation, if provided along with the Derivative Works; or,
        within a display generated by the Derivative Works, if and
        wherever such third-party notices normally appear. The contents
        of the NOTICE file are for informational purposes only and
        do not modify the License. You may add Your own attribution
        notices within Derivative Works that You distribute, alongside
        or as an addendum to the NOTICE text from the Work, provided
        that such additional attribution notices cannot be construed
        as modifying the License.
        
        You may add Your own copyright statement to Your modifications and
        may provide additional or different license terms and conditions
        for use, reproduction, or distribution of Your modifications, or
        for any such Derivative Works as a whole, provided Your use,
        reproduction, and distribution of the Work otherwise complies with
        the conditions stated in this License.
        
        5. Submission of Contributions. Unless You explicitly state otherwise,
        any Contribution intentionally submitted for inclusion in the Work
        by You to the Licensor shall be under the terms and conditions of
        this License, without any additional terms or conditions.
        Notwithstanding the above, nothing herein shall supersede or modify
        the terms of any separate license agreement you may have executed
        with Licensor regarding such Contributions.
        
        6. Trademarks. This License does not grant permission to use the trade
        names, trademarks, service marks, or product names of the Licensor,
        except as required for reasonable and customary use in describing the
        origin of the Work and reproducing the content of the NOTICE file.
        
        7. Disclaimer of Warranty. Unless required by applicable law or
        agreed to in writing, Licensor provides the Work (and each
        Contributor provides its Contributions) on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
        implied, including, without limitation, any warranties or conditions
        of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
        PARTICULAR PURPOSE. You are solely responsible for determining the
        appropriateness of using or redistributing the Work and assume any
        risks associated with Your exercise of permissions under this License.
        
        8. Limitation of Liability. In no event and under no legal theory,
        whether in tort (including negligence), contract, or otherwise,
        unless required by applicable law (such as deliberate and grossly
        negligent acts) or agreed to in writing, shall any Contributor be
        liable to You for damages, including any direct, indirect, special,
        incidental, or consequential damages of any character arising as a
        result of this License or out of the use or inability to use the
        Work (including but not limited to damages for loss of goodwill,
        work stoppage, computer failure or malfunction, or any and all
        other commercial damages or losses), even if such Contributor
        has been advised of the possibility of such damages.
        
        9. Accepting Warranty or Additional Liability. While redistributing
        the Work or Derivative Works thereof, You may choose to offer,
        and charge a fee for, acceptance of support, warranty, indemnity,
        or other liability obligations and/or rights consistent with this
        License. However, in accepting such obligations, You may act only
        on Your own behalf and on Your sole responsibility, not on behalf
        of any other Contributor, and only if You agree to indemnify,
        defend, and hold each Contributor harmless for any liability
        incurred by, or claims asserted against, such Contributor by reason
        of your accepting any such warranty or additional liability.
        
        END OF TERMS AND CONDITIONS
        
        APPENDIX: How to apply the Apache License to your work.
        
        To apply the Apache License to your work, attach the following
        boilerplate notice, with the fields enclosed by brackets "[]"
        replaced with your own identifying information. (Don't include
        the brackets!) The text should be enclosed in the appropriate
        comment syntax for the file format. We also recommend that a
        file or class name and description of purpose be included on the
        same "printed page" as the copyright notice for easier
        identification within third-party archives.
        
        Copyright 2026 Alex Shalaev
        
        Licensed under the Apache License, Version 2.0 (the "License");
        you may not use this file except in compliance with the License.
        You may obtain a copy of the License at
        
        http://www.apache.org/licenses/LICENSE-2.0
        
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
License-File: LICENSE
Keywords: async,asyncio,client,grpc,grpcio,load-balancing,microservices,observability
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: grpcio<2.0.0,>=1.78.0
Provides-Extra: all
Requires-Dist: deadline-budget<1.0.0,>=0.1.0; extra == 'all'
Requires-Dist: grpcio-health-checking<2.0.0,>=1.78.0; extra == 'all'
Requires-Dist: opentelemetry-api<2.0.0,>=1.30.0; extra == 'all'
Requires-Dist: prometheus-client<1.0.0,>=0.20.0; extra == 'all'
Provides-Extra: deadline
Requires-Dist: deadline-budget<1.0.0,>=0.1.0; extra == 'deadline'
Provides-Extra: health
Requires-Dist: grpcio-health-checking<2.0.0,>=1.78.0; extra == 'health'
Provides-Extra: metrics
Requires-Dist: prometheus-client<1.0.0,>=0.20.0; extra == 'metrics'
Provides-Extra: observability
Requires-Dist: opentelemetry-api<2.0.0,>=1.30.0; extra == 'observability'
Requires-Dist: prometheus-client<1.0.0,>=0.20.0; extra == 'observability'
Provides-Extra: tracing
Requires-Dist: opentelemetry-api<2.0.0,>=1.30.0; extra == 'tracing'
Description-Content-Type: text/markdown

# grpc-client-kit

Batteries-optional async gRPC client toolkit (channel pool, load balancing, health checking, streaming-aware interceptors, observability)

[![PyPI](https://img.shields.io/pypi/v/grpc-client-kit?color=blue)](https://pypi.org/project/grpc-client-kit/)
[![Python](https://img.shields.io/pypi/pyversions/grpc-client-kit)](https://pypi.org/project/grpc-client-kit/)
[![License](https://img.shields.io/github/license/bedrock-python/grpc-client-kit)](LICENSE)
[![CI](https://github.com/bedrock-python/grpc-client-kit/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/bedrock-python/grpc-client-kit/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/bedrock-python/grpc-client-kit/graph/badge.svg)](https://codecov.io/gh/bedrock-python/grpc-client-kit)
[![Docs](https://img.shields.io/badge/docs-online-blue)](https://bedrock-python.github.io/grpc-client-kit/)

`grpc-client-kit` is the caller-side half of a production gRPC setup: a channel
pool keyed by the full identity of a channel, client-side load balancing,
active `grpc.health.v1` monitoring, and a fixed-order chain of streaming-aware
interceptors for retries, deadlines, circuit breaking, logging, tracing and
metrics.

The core depends only on `grpcio`. Every integration is an opt-in extra, so you
install exactly what you use.

## Why grpc-client-kit

- **Channels are pooled by identity, not by address.** Target, security,
  options, compression *and* the interceptor chain form the pool key, so a
  client never inherits another client's retry policy or circuit breaker.
- **A timeout is the budget of a whole call, not of one attempt.** It becomes a
  deadline once, on entry, and the retry layer divides what is left between
  attempts — `max_attempts × timeout` is not a thing this kit does.
- **A deadline can survive the hop.** Install the caller's request budget once
  and every outgoing call is trimmed to what the request still has, instead of
  being issued with a fresh timeout five services deep. The kit supplies the
  mechanism; installing the budget stays the caller's decision.
- **A layer is one `around_call`, not four interceptor methods.** You write a
  single async generator; the kit expands it into the four adapters a channel
  registers, so streaming calls get the same treatment unary calls get.
- **A failed call marks its target down immediately.** Active probes learn
  about a dead backend one interval late; passive quarantine takes it out of
  the rotation on the first `UNAVAILABLE`, so an outage costs one call, not a
  full share of the traffic.
- **Local refusals are distinguishable from server failures.** Every failure
  the kit raises on its own authority derives from `GrpcClientKitError`, and
  a breaker rejection is `status="rejected"` in the metrics — never `"error"`
  — so "is the breaker open or is the backend down?" has an answer.
- **A bare install is a working install.** `import grpc_client_kit` never
  reaches for an extra: names that need one resolve on first access and raise
  an `ImportError` that says which extra to install.
- **What gRPC core does better stays with gRPC core.** Idle connections are
  parked by `grpc.client_idle_timeout_ms`, native `loadBalancingConfig` and
  `retryPolicy` pass through untouched, and the docs say plainly
  [when to use which](https://bedrock-python.github.io/grpc-client-kit/guide/native-vs-kit/).

## Installation

```bash
pip install grpc-client-kit                       # core (grpcio only)
pip install "grpc-client-kit[health]"             # + grpc.health.v1 monitoring
pip install "grpc-client-kit[metrics,tracing]"    # + Prometheus + OpenTelemetry
pip install "grpc-client-kit[observability]"      # + metrics and tracing together
pip install "grpc-client-kit[deadline]"           # + request budget propagation
pip install "grpc-client-kit[all]"                # everything
```

**Requirements:** Python 3.12+

## Quick start

```python
import asyncio

from grpc_client_kit import ChannelPool, GrpcClient, GrpcClientConfig

from my_service_pb2 import GreetRequest
from my_service_pb2_grpc import GreeterStub


async def main() -> None:
    async with ChannelPool() as pool:  # owns the channels
        client = GrpcClient(  # owns nothing, cheap to create
            GreeterStub,
            config=GrpcClientConfig(target="localhost:50051", insecure=True),
            pool=pool,
        )
        async with client as stub:  # a stub on a pooled channel
            print(await stub.Greet(GreetRequest(name="world")))


asyncio.run(main())
```

`GrpcClient` is a stub factory, not a connection: it picks a target, asks the
pool for the matching channel, and hands you a stub. The pool owns the
channels and outlives every client built on it.

## The factory does the wiring

`GrpcClientFactory` maps one settings object onto the pool, the balancer, the
health checker and a per-target interceptor chain, so services declare
behaviour instead of assembling it:

```python
from grpc_client_kit import GrpcClientFactory

async with GrpcClientFactory(settings=settings) as factory:  # starts health checking
    users = factory.create_client(UserStub)  # both share the pool
    orders = factory.create_client(OrderStub)

    async with users as stub:
        await stub.GetUser(request)
```

Any object carrying the fields of `GrpcClientSettingsProtocol` works —
a pydantic model, a dataclass, a plain class. Everything optional
(`credentials`, `options`, `compression`, `metrics_registry`,
`sensitive_headers`) is read through `getattr`, so a minimal settings object
stays valid. See the
[configuration guide](https://bedrock-python.github.io/grpc-client-kit/guide/configuration/)
for the full field list.

## Channels are pooled by identity, not by address

A pooled channel is filed under **everything** gRPC baked into it at creation:
target, `insecure`, credentials, options, compression, and the identity of the
interceptor chain. Asking for `host:50051` over TLS never returns the insecure
channel someone opened for the same address, and a client never inherits
another client's interceptors.

That last field is the deliberate one: `grpc.aio` binds interceptors to a
channel when the channel is created and offers no way to attach them later. A
channel built for one chain therefore *cannot* serve another, so two clients
with different chains get different channels — the alternative is silently
running RPCs through somebody else's retry policy and circuit breaker.

`GrpcClient` caches the chain it builds per target for exactly this reason:
rebuilding it per call would mint a new channel identity every time, and the
pool would open a channel per RPC. Pooling, reuse and idle eviction are covered
in the [channels guide](https://bedrock-python.github.io/grpc-client-kit/guide/channels/).

`ConnectivityConfig` belongs to the same story. Keepalive pings and reconnect
backoff are channel arguments — fixed at creation, spelled in milliseconds,
and part of the pool key — so the kit takes them in seconds, validates them,
and composes them with your explicit `options` by dropping any derived argument
whose key you already used, rather than handing gRPC the same key twice. It is
opt-in: a server left at its own defaults answers a client that pings too often
with `GOAWAY` and `ENHANCE_YOUR_CALM`.

## The interceptor chain

`InterceptorChainBuilder` fixes the order, because where a layer sits decides
what it observes and what it repeats. Outermost first:

| # | Layer | Why here |
| :-: | :--- | :--- |
| 1 | extra outer (e.g. `AsyncClientContextInterceptor`) | metadata must be injected before the layers that correlate on it |
| 2 | `AsyncLoggingInterceptor` | one record per logical call, with `request-id` already attached |
| 3 | tracing | one CLIENT span covering the retries nested below it |
| 4 | metrics | latency as the caller experiences it, retry backoff included |
| 5 | `AsyncTimeoutInterceptor` | installs the budget for the **whole** call |
| 6 | `AsyncDeadlineBudgetInterceptor` | trims that budget to what the caller's *request* has left, before anything divides it |
| 7 | `AsyncWaitForReadyInterceptor` | decides whether a call waits for its connection, reading the deadline the two above settled |
| 8 | `AsyncRetryInterceptor` | divides the resulting budget between attempts |
| 9 | `AsyncCircuitBreakerInterceptor` | sees individual attempts, rejects tripped methods off-network |
| 10 | extra inner | custom layers that must re-run per attempt (credential refresh, ...) |

Layers 6 and 7 appear only when configured (`deadline_budget=`,
`wait_for_ready=`), and layer 6 also needs the `deadline` extra.

**Every layer covers all four call kinds.** A channel files an interceptor into
one of its four lists *by class*, so one object claiming all four kinds is
registered for unary-unary only and every streaming call runs past it. A chain
built here reaches the channel with each layer expanded into four adapters, one
per kind — which is why a stream gets the same log record, span, latency sample,
deadline, retry and breaker verdict a unary call gets, all of them landing when
the stream ends rather than when its first message arrives.

**A layer learns the outcome by awaiting the call.** In `grpc.aio` a
continuation resolves to a `Call` the moment the RPC is *created*, identically
for a call that will succeed and one that will fail, and it never raises. The
kit awaits that call, so a failure — including one halfway through a stream —
reaches every layer as the error it is, instead of being reported as an instant
success.

**A timeout is the budget of a whole call, not of one attempt.** The retry
interceptor converts it into a deadline once, on entry, issues every attempt
with the budget that is left, and abandons a retry whose backoff alone would
outlive it. `max_attempts × timeout` is not a thing this kit does; the
[resilience guide](https://bedrock-python.github.io/grpc-client-kit/guide/resilience/)
walks through deadlines, backoff and the breaker together.

## Your own layer is one async generator

```python
from collections import Counter
from collections.abc import AsyncIterator

import grpc.aio

from grpc_client_kit.interceptors import AsyncAroundClientInterceptor, ClientCall


class FailureCounter(AsyncAroundClientInterceptor):
    """Count the calls of each method that came back with an error."""

    def __init__(self) -> None:
        self.failures: Counter[str] = Counter()

    async def around_call(self, call: ClientCall) -> AsyncIterator[None]:
        try:
            yield  # the whole RPC happens here — a response stream to its last item
        except grpc.aio.AioRpcError:
            self.failures[call.method] += 1
            raise
```

Code before the `yield` runs before the RPC exists, so that is where call
details are rewritten and where raising refuses a call outright. Code after it
runs once the call is over, whichever of the four kinds it was. Layers that
re-issue a call — retries — subclass `AsyncClientInterceptor` and issue it
themselves; see the
[advanced guide](https://bedrock-python.github.io/grpc-client-kit/guide/advanced/).

**`INTERNAL` is not retryable by default.** `DEFAULT_RETRYABLE_CODES` holds
`UNAVAILABLE` and `RESOURCE_EXHAUSTED` only — both mean the request was
rejected before the server application saw it. `INTERNAL` is raised by the
handler itself, so retrying it duplicates whatever write it already performed.
Widen the set per method with `idempotent_methods`, not globally.

## Health checking

```python
from grpc_client_kit import HealthChecker, create_balancer  # HealthChecker needs [health]

checker = HealthChecker(check_interval=30.0, timeout=5.0)
await checker.start(["api-1:50051", "api-2:50051"])
await checker.wait_until_ready(timeout=5.0)  # await the first pass

balancer = create_balancer(targets=targets, health_checker=checker)
```

**An unchecked target is not a healthy target.** Health comes from evidence:
`is_healthy()` is `True` only after a check saw `SERVING`, and a checker that
was never started raises `HealthCheckerNotRunningError` instead of guessing.
On a cold start that means the balancer raises `NoHealthyTargetsError` until
the first pass lands — call `wait_until_ready()` after `start()` if the first
RPC must not see it.

`HealthChecker` lives behind the `[health]` extra. It is resolved lazily, so
`import grpc_client_kit` still works without it; touching
`grpc_client_kit.HealthChecker` on a bare install raises an `ImportError` that
names the extra to install.

## What's inside

| Module | Responsibility | Extra |
| :--- | :--- | :--- |
| `config.GrpcClientConfig` | Zero-dependency channel settings dataclass | core |
| `config.ConnectivityConfig` | Keepalive and reconnect backoff in seconds, composed into the channel options | core |
| `channel.ChannelPool` | Channels pooled by full identity, idle eviction, health flags | core |
| `client.GrpcClient` | Stub factory: target selection + channel acquisition | core |
| `factory.GrpcClientFactory` | Settings → pool, balancer, health checker, per-target chains | core |
| `balancers.*` | Round-robin / random / weighted selection with health filtering | core |
| `interceptors.*` | Context, logging, timeout, wait-for-ready, retry, circuit breaker + chain builder | core |
| `deadline` + `interceptors.deadline` | The request budget in a contextvar, and the layer that trims every call to it | `deadline` |
| `interceptors.tracing` | OpenTelemetry CLIENT spans and `traceparent` injection | `tracing` |
| `interceptors.metrics` | Counters, latency histograms and an in-flight gauge | core¹ |
| `health.HealthChecker` | Background `grpc.health.v1` probing with per-target backoff | `health` |
| `protocols` / `validation` / `utils` | Settings seams, target validation, channel and metadata helpers | core |

¹ The metrics interceptor records through `GrpcClientMetricsProtocol` and works
with any backend you pass. The `[metrics]` extra only supplies the usual one.

## Optional dependencies

| Extra | Pulls in | Enables |
| :--- | :--- | :--- |
| `health` | `grpcio-health-checking` | `HealthChecker`, health-aware balancing and pooling |
| `tracing` | `opentelemetry-api` | `AsyncClientTracingInterceptor` (a pass-through without it) |
| `metrics` | `prometheus-client` | the default metrics backend; a custom registry needs no extra |
| `deadline` | `deadline-budget` | `AsyncDeadlineBudgetInterceptor` (the layer is skipped without it) |
| `observability` | `metrics` + `tracing` | both of the above |
| `all` | `deadline` + `health` + `metrics` + `tracing` | everything |

`deadline` is deliberately not part of `observability`: propagating a budget is
resilience, not telemetry, and an observability extra should not pull in a
dependency that changes what calls do.

## Examples

Runnable, self-contained scripts in [`examples/`](examples/) — each one starts the servers
it needs on ephemeral ports, prints what it is doing, and exits on its own:

- [`minimal_client.py`](examples/minimal_client.py) — pool, config, client, stub, and what channel pooling buys you.
- [`custom_interceptor.py`](examples/custom_interceptor.py) — your own layer with `AsyncAroundClientInterceptor.around_call`: one generator covering unary calls, whole streams, mid-stream failures and refusing a call outright.
- [`resilience.py`](examples/resilience.py) — retries against a failing server, the call budget divided between attempts, and the `fail_threshold ≤ max_attempts` trap where a call opens its own circuit.
- [`deadline_propagation.py`](examples/deadline_propagation.py) — one request budget across several calls, measured as the *server* saw each deadline: shrinking deadlines, a call refused before the wire, per-method caps, and `wait_for_ready` waiting out a server that starts late (needs the `deadline` extra).
- [`health_and_balancing.py`](examples/health_and_balancing.py) — `HealthChecker` feeding both the pool and the balancer, routing that follows the verdicts, and `NoHealthyTargetsError` (needs the `health` extra).
- [`observability.py`](examples/observability.py) — the log records and metric samples an RPC actually produces, redaction and request-id correlation included.
- [`factory_setup.py`](examples/factory_setup.py) — one settings object driving the whole factory, and why a breaker per target is not the same as one breaker shared by all of them.

## Documentation

Full documentation at [bedrock-python.github.io/grpc-client-kit](https://bedrock-python.github.io/grpc-client-kit/).

| | |
| :--- | :--- |
| [Quick start](https://bedrock-python.github.io/grpc-client-kit/guide/quickstart/) | pool, config, client, stub — a first call end to end |
| [Configuration](https://bedrock-python.github.io/grpc-client-kit/guide/configuration/) | `GrpcClientConfig`, the settings protocols, and what the factory reads off them |
| [Channels](https://bedrock-python.github.io/grpc-client-kit/guide/channels/) | the pool, channel identity, reuse and idle eviction |
| [Interceptors](https://bedrock-python.github.io/grpc-client-kit/guide/interceptors/) | the fixed chain order, the four call kinds, writing your own with `around_call` |
| [Resilience](https://bedrock-python.github.io/grpc-client-kit/guide/resilience/) | call budgets, waiting for a connection, retry safety and circuit breaker isolation |
| [Deadline budgets](https://bedrock-python.github.io/grpc-client-kit/guide/deadlines/) | propagating the caller's remaining time into every hop |
| [Load balancing](https://bedrock-python.github.io/grpc-client-kit/guide/load-balancing/) | round-robin, random and weighted selection with health filtering |
| [Health](https://bedrock-python.github.io/grpc-client-kit/guide/health/) | `grpc.health.v1` probing, per-target backoff and cold starts |
| [Observability](https://bedrock-python.github.io/grpc-client-kit/guide/observability/) | log records, CLIENT spans and the metrics an RPC emits |
| [Advanced](https://bedrock-python.github.io/grpc-client-kit/guide/advanced/) | interceptors that re-issue calls, target validation, ownership and DI wiring |
| [API reference](https://bedrock-python.github.io/grpc-client-kit/reference/) | generated from the source |

## License

Apache 2.0 — see [LICENSE](LICENSE).
