From 2cff1b6cd148b5183e7efd43d6bc328b19f190d3 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Thu, 2 Apr 2026 14:33:59 -0400 Subject: [PATCH] Various README updates Think we missed a couple of these after the refactoring to pyqwest and the interceptor refactor. Signed-off-by: Stefan VanBuren --- README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3b1172c..b6854fe 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,7 @@ from your_service_connect import HelloServiceClient # Create async client async def main(): - async with HelloServiceClient( - base_url="https://api.example.com", - ) as client: + async with HelloServiceClient("https://api.example.com") as client: # Make a unary RPC call response = await client.say_hello(HelloRequest(name="World")) print(response.message) # "Hello, World!" @@ -116,9 +114,7 @@ from your_service_connect import HelloServiceClientSync # Create sync client def main(): - with HelloServiceClientSync( - base_url="https://api.example.com", - ) as client: + with HelloServiceClientSync("https://api.example.com") as client: # Make a unary RPC call response = client.say_hello(HelloRequest(name="World")) print(response.message) # "Hello, World!" @@ -292,14 +288,20 @@ Compression is automatically negotiated between client and server based on the ` Interceptors allow you to add cross-cutting concerns like authentication, logging, and metrics: ```python -from connectrpc.interceptor import Interceptor +from connectrpc.interceptor import MetadataInterceptor +from connectrpc.request import RequestContext + +class LoggingInterceptor: + """Implements the MetadataInterceptor protocol.""" + + async def on_start(self, ctx: RequestContext) -> None: + print(f"Handling {ctx.method.name} request") -class LoggingInterceptor(Interceptor): - async def intercept(self, method, request, context, next_handler): - print(f"Handling {method} request") - response = await next_handler(request, context) - print(f"Completed {method} request") - return response + async def on_end(self, token: None, ctx: RequestContext, error: Exception | None) -> None: + if error: + print(f"Failed {ctx.method.name}: {error}") + else: + print(f"Completed {ctx.method.name} request") # Add to your application app = HelloServiceASGIApplication( @@ -314,8 +316,7 @@ Clients also support interceptors for request/response processing: ```python client = HelloServiceClient( - base_url="https://api.example.com", - session=session, + "https://api.example.com", interceptors=[AuthInterceptor(), RetryInterceptor()] ) ``` @@ -373,8 +374,7 @@ app = YourServiceASGIApplication( # Client with message size limit client = YourServiceClient( - base_url="https://api.example.com", - session=session, + "https://api.example.com", read_max_bytes=1024 * 1024 ) ``` @@ -397,7 +397,7 @@ service YourService { ## Development -We use `ruff` for linting and formatting, and `pyright` for type checking. +We use `ruff` for linting and formatting, `pyright` for type checking, and `tombi` for TOML linting and formatting. We rely on the conformance test suit (in [./conformance](./conformance)) to verify behavior.