@@ -82,9 +82,7 @@ from your_service_connect import HelloServiceClient
8282
8383# Create async client
8484async def main():
85- async with HelloServiceClient(
86- base_url="https://api.example.com",
87- ) as client:
85+ async with HelloServiceClient("https://api.example.com") as client:
8886 # Make a unary RPC call
8987 response = await client.say_hello(HelloRequest(name="World"))
9088 print(response.message) # "Hello, World!"
@@ -116,9 +114,7 @@ from your_service_connect import HelloServiceClientSync
116114
117115# Create sync client
118116def main():
119- with HelloServiceClientSync(
120- base_url="https://api.example.com",
121- ) as client:
117+ with HelloServiceClientSync("https://api.example.com") as client:
122118 # Make a unary RPC call
123119 response = client.say_hello(HelloRequest(name="World"))
124120 print(response.message) # "Hello, World!"
@@ -292,14 +288,20 @@ Compression is automatically negotiated between client and server based on the `
292288Interceptors allow you to add cross-cutting concerns like authentication, logging, and metrics :
293289
294290` ` ` python
295- from connectrpc.interceptor import Interceptor
291+ from connectrpc.interceptor import MetadataInterceptor
292+ from connectrpc.request import RequestContext
293+
294+ class LoggingInterceptor:
295+ """Implements the MetadataInterceptor protocol."""
296+
297+ async def on_start(self, ctx: RequestContext) -> None:
298+ print(f"Handling {ctx.method.name} request")
296299
297- class LoggingInterceptor(Interceptor):
298- async def intercept(self, method, request, context, next_handler):
299- print(f"Handling {method} request")
300- response = await next_handler(request, context)
301- print(f"Completed {method} request")
302- return response
300+ async def on_end(self, token: None, ctx: RequestContext, error: Exception | None) -> None:
301+ if error:
302+ print(f"Failed {ctx.method.name}: {error}")
303+ else:
304+ print(f"Completed {ctx.method.name} request")
303305
304306# Add to your application
305307app = HelloServiceASGIApplication(
@@ -314,8 +316,7 @@ Clients also support interceptors for request/response processing:
314316
315317` ` ` python
316318client = HelloServiceClient(
317- base_url="https://api.example.com",
318- session=session,
319+ "https://api.example.com",
319320 interceptors=[AuthInterceptor(), RetryInterceptor()]
320321)
321322` ` `
@@ -373,8 +374,7 @@ app = YourServiceASGIApplication(
373374
374375# Client with message size limit
375376client = YourServiceClient(
376- base_url="https://api.example.com",
377- session=session,
377+ "https://api.example.com",
378378 read_max_bytes=1024 * 1024
379379)
380380` ` `
@@ -397,7 +397,7 @@ service YourService {
397397
398398# # Development
399399
400- We use `ruff` for linting and formatting, and `pyright` for type checking.
400+ We use `ruff` for linting and formatting, `pyright` for type checking, and `tombi` for TOML linting and formatting .
401401
402402We rely on the conformance test suit (in
403403[./conformance](./conformance)) to verify behavior.
0 commit comments