Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down Expand Up @@ -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!"
Expand Down Expand Up @@ -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(
Expand All @@ -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()]
)
```
Expand Down Expand Up @@ -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
)
```
Expand All @@ -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.
Expand Down
Loading