Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions src/connectrpc/_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@ def __init__(

Args:
address: The address of the server to connect to, including scheme.
proto_json: Whether to use JSON for the protocol
proto_json: Whether to use JSON for the protocol.
protocol: The [ProtocolType][] to use for requests.
accept_compression: Compression algorithms to accept from the server. If unset,
defaults to gzip. If set to empty, disables response compression.
send_compression: Compression algorithm to use for sending requests. If unset,
defaults to gzip. If set to None, disables request compression.
timeout_ms: The timeout for requests in milliseconds
read_max_bytes: The maximum number of bytes to read from the response
interceptors: A list of interceptors to apply to requests
http_client: A pyqwest Client to use for requests
timeout_ms: The timeout for requests in milliseconds.
read_max_bytes: The maximum number of bytes to read from the response.
interceptors: A list of interceptors to apply to requests.
http_client: A pyqwest Client to use for requests.
"""
self._address = address
self._codec = get_proto_json_codec() if proto_json else get_proto_binary_codec()
Expand Down
11 changes: 6 additions & 5 deletions src/connectrpc/_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ def __init__(

Args:
address: The address of the server to connect to, including scheme.
proto_json: Whether to use JSON for the protocol
proto_json: Whether to use JSON for the protocol.
protocol: The [ProtocolType][] to use for requests.
accept_compression: Compression algorithms to accept from the server. If unset,
defaults to gzip. If set to empty, disables response compression.
send_compression: Compression algorithm to use for sending requests. If unset,
defaults to gzip. If set to None, disables request compression.
timeout_ms: The timeout for requests in milliseconds
read_max_bytes: The maximum number of bytes to read from the response
interceptors: A list of interceptors to apply to requests
http_client: A pyqwest SyncClient to use for requests
timeout_ms: The timeout for requests in milliseconds.
read_max_bytes: The maximum number of bytes to read from the response.
interceptors: A list of interceptors to apply to requests.
http_client: A pyqwest SyncClient to use for requests.
"""
self._address = address
self._codec = get_proto_json_codec() if proto_json else get_proto_binary_codec()
Expand Down
2 changes: 1 addition & 1 deletion src/connectrpc/_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def decompress(self, data: bytes | bytearray | memoryview) -> bytes:
_identity = IdentityCompression()

_gzip = GzipCompression()
_default_compressions = {"gzip": _gzip, "identity": _identity}
_default_compressions: dict[str, Compression] = {"gzip": _gzip, "identity": _identity}


def resolve_compressions(
Expand Down
6 changes: 3 additions & 3 deletions src/connectrpc/_interceptor_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ class MetadataInterceptor(Protocol[T]):
access to metadata such as headers and trailers.

To access request and response bodies of a method, instead use an interceptor
corresponding to the type of method such as UnaryInterceptor.
corresponding to the type of method such as [UnaryInterceptor][].
"""

async def on_start(self, ctx: RequestContext) -> T:
"""Called when the RPC starts. The return value will be passed to on_end as-is.
"""Called when the RPC starts. The return value will be passed to [on_end][] as-is.
For example, if measuring RPC invocation time, on_start may return the current
time. If a return value isn't needed or on_end won't be used, return None.
time. If a return value isn't needed or [on_end][] won't be used, return None.
"""
...

Expand Down
8 changes: 4 additions & 4 deletions src/connectrpc/_interceptor_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ class MetadataInterceptorSync(Protocol[T]):
access to metadata such as headers and trailers.

To access request and response bodies of a method, instead use an interceptor
corresponding to the type of method such as UnaryInterceptorSync.
corresponding to the type of method such as [UnaryInterceptorSync][].
"""

def on_start_sync(self, ctx: RequestContext) -> T:
"""Called when the RPC starts. The return value will be passed to on_end as-is.
For example, if measuring RPC invocation time, on_start may return the current
time. If a return value isn't needed or on_end won't be used, return None.
"""Called when the RPC starts. The return value will be passed to [on_end_sync][] as-is.
For example, if measuring RPC invocation time, on_start_sync may return the current
time. If a return value isn't needed or [on_end_sync][] won't be used, return None.
"""
...

Expand Down
4 changes: 3 additions & 1 deletion src/connectrpc/_server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def __init__(

Args:
service: The service instance or async generator that yields the service during lifespan.
endpoints: A mapping of URL paths to endpoints resolved from service.
endpoints: A callable that takes the service instance and returns a mapping of URL
paths to endpoints. Typically provided directly by generated code from the
Connect Python plugin.
interceptors: A sequence of interceptors to apply to the endpoints.
read_max_bytes: Maximum size of request messages.
compressions: Supported compression algorithms. If unset, defaults to gzip.
Expand Down
4 changes: 2 additions & 2 deletions src/connectrpc/_server_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Endpoint(Generic[REQ, RES]):
Represents an endpoint in a service.

Attributes:
method: The method to map the the RPC function.
method: The method to map to the RPC function.
"""

method: MethodInfo[REQ, RES]
Expand Down Expand Up @@ -83,7 +83,7 @@ class EndpointSync(Generic[REQ, RES]):
Represents a sync endpoint in a service.

Attributes:
method: The method to map the RPC function.
method: The method to map to the RPC function.
"""

method: MethodInfo[REQ, RES]
Expand Down
12 changes: 6 additions & 6 deletions src/connectrpc/_server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ def _process_headers(headers: dict) -> Headers:
def prepare_response_headers(
base_headers: dict[str, list[str]], selected_encoding: str
) -> dict[str, list[str]]:
"""Prepare response headers and determine if compression should be used.
"""Prepare response headers with the selected compression encoding.

Args:
base_headers: Base response headers
selected_encoding: Selected compression encoding
compressed_size: Size of compressed content (if compression was attempted)
base_headers: Base response headers.
selected_encoding: Selected compression encoding.

Returns:
tuple[dict, bool]: Final headers and whether to use compression
The final response headers with content-encoding set.
"""
headers = base_headers.copy()

Expand Down Expand Up @@ -173,7 +172,8 @@ def __init__(
"""Initialize the WSGI application.

Args:
endpoints: A mapping of URL paths to service endpoints.
endpoints: A mapping of URL paths to endpoints. Typically provided directly
by generated code from the Connect Python plugin.
interceptors: A sequence of interceptors to apply to the endpoints.
read_max_bytes: Maximum size of request messages.
compressions: Supported compression algorithms. If unset, defaults to gzip.
Expand Down
8 changes: 5 additions & 3 deletions src/connectrpc/compression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class Compression(Protocol):

By default, gzip compression is used. Other compression methods can be
used by specifying implementations of this protocol. We provide standard
implementations for
implementations for:

- br (connectrpc.compression.brotli.BrotliCompression) - requires the `brotli` dependency
- zstd (connectrpc.compression.zstd.ZstdCompression) - requires the `zstandard` dependency
- br ([BrotliCompression][connectrpc.compression.brotli.BrotliCompression]) -
requires the `brotli` dependency.
- zstd ([ZstdCompression][connectrpc.compression.zstd.ZstdCompression]) -
requires the `zstandard` dependency.
"""

def name(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/connectrpc/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConnectError(Exception):
If a server raises a ConnectError, the same exception content will be
raised on the client as well. Errors surfacing on the client side such as
timeouts will also be raised as a ConnectError with an appropriate
code.
[Code][].
"""

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion src/connectrpc/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ class MethodInfo(Generic[REQ, RES]):
"""The output message type of the method."""

idempotency_level: IdempotencyLevel
"""The idempotency level of the method."""
"""The [IdempotencyLevel][] of the method."""
8 changes: 4 additions & 4 deletions src/connectrpc/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@


class ProtocolType(Enum):
"""A protocol supported by Connect"""
"""A protocol supported by Connect."""

CONNECT = 1
"""The Connect protocol"""
"""The Connect protocol."""

GRPC = 2
"""The gRPC protocol"""
"""The gRPC protocol."""

GRPC_WEB = 3
"""The gRPC-Web protocol"""
"""The gRPC-Web protocol."""
13 changes: 2 additions & 11 deletions src/connectrpc/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ def http_method(self) -> str:
return self._http_method

def request_headers(self) -> Headers:
"""
Returns the request headers associated with the context.

:return: A mapping of header keys to lists of header values.
"""
"""Returns the request headers associated with the context."""
return self._request_headers

def response_headers(self) -> Headers:
Expand All @@ -87,12 +83,7 @@ def response_trailers(self) -> Headers:
return self._response_trailers

def timeout_ms(self) -> float | None:
"""
Returns the remaining time until the timeout.

Returns:
float | None: The remaining time in milliseconds, or None if no timeout is set.
"""
"""Returns the remaining time until the timeout in milliseconds, or None if no timeout is set."""
if self._end_time is None:
return None
return (self._end_time - time.monotonic()) * 1000.0
Expand Down
2 changes: 1 addition & 1 deletion zensical.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ alternate_style = true

[project.plugins.mkdocstrings.handlers.python]
inventories = ["https://docs.python.org/3/objects.inv"]
paths = ["."]
paths = ["src"]

[project.plugins.mkdocstrings.handlers.python.options]
docstring_options = { ignore_init_summary = true }
Expand Down
Loading