Skip to content
11 changes: 10 additions & 1 deletion python/lib/sift_client/_internal/grpc_transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,14 @@ def _compute_channel_options(opts: SiftChannelConfig) -> list[tuple[str, Any]]:
# Primary cannot be overriden:
# https://github.com/grpc/grpc/blob/0498194240f55d7f4b12633ad01339fb690621bf/src/core/ext/filters/http/client/http_client_filter.cc#L97
("grpc.secondary_user_agent", _compute_user_agent()),
("grpc.max_receive_message_length", MAX_DECODING_MESSAGE_SIZE),
(
"grpc.max_receive_message_length",
opts.get("max_receive_message_length", MAX_DECODING_MESSAGE_SIZE),
),
(
"grpc.max_send_message_length",
opts.get("max_send_message_length", MAX_DECODING_MESSAGE_SIZE),
),
]

enable_keepalive = opts.get("enable_keepalive", True)
Expand Down Expand Up @@ -251,3 +258,5 @@ class SiftChannelConfig(TypedDict):
use_ssl: NotRequired[bool]
cert_via_openssl: NotRequired[bool]
request_timeout: NotRequired[float | None]
max_receive_message_length: NotRequired[int]
max_send_message_length: NotRequired[int]
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Configure logging
logger = logging.getLogger(__name__)

CHANNELS_DEFAULT_PAGE_SIZE = 10_000
CHANNELS_DEFAULT_PAGE_SIZE = 100_000
# TODO: There is a pagination issue API side when requesting multiple channels in single request.
# If all data points for all channels in a single request don't fit into a single page, then
# paging seems to omit all but a single channel. We can increase this batch size once that issue
Expand Down
3 changes: 1 addition & 2 deletions python/lib/sift_client/_tests/_internal/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import pytest

from sift_client._internal.grpc_transport.transport import (
MAX_DECODING_MESSAGE_SIZE,
_compute_channel_options,
)
from sift_client.transport.grpc_transport import GrpcClient, GrpcConfig
from sift_client.transport.grpc_transport import MAX_DECODING_MESSAGE_SIZE, GrpcClient, GrpcConfig
from sift_client.transport.rest_transport import DEFAULT_REST_TIMEOUT, RestClient, RestConfig


Expand Down
13 changes: 13 additions & 0 deletions python/lib/sift_client/transport/grpc_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use_sift_async_channel,
)

MAX_DECODING_MESSAGE_SIZE = 50 * 1024 * 1024
"""Largest gRPC message the client will accept or send, in bytes (50 MiB)."""

# Configure logging
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -48,6 +51,8 @@ def __init__(
cert_via_openssl: bool = False,
metadata: dict[str, str] | None = None,
request_timeout: float | None = DEFAULT_REQUEST_TIMEOUT_SECONDS,
max_receive_message_length: int = MAX_DECODING_MESSAGE_SIZE,
max_send_message_length: int = MAX_DECODING_MESSAGE_SIZE,
):
"""Initialize the gRPC configuration.

Expand All @@ -60,6 +65,10 @@ def __init__(
metadata: Additional metadata to include in all requests.
request_timeout: Default deadline in seconds applied to unary RPCs that don't set
their own. Defaults to 60s. Set to None to disable the default deadline.
max_receive_message_length: Maximum gRPC message size the client will accept (bytes).
Defaults to `MAX_DECODING_MESSAGE_SIZE`.
max_send_message_length: Maximum gRPC message size the client will send (bytes).
Defaults to `MAX_DECODING_MESSAGE_SIZE`.
"""
parsed_url = urlparse(url)
normalized_url = url
Expand All @@ -77,6 +86,8 @@ def __init__(
self.cert_via_openssl = cert_via_openssl
self.metadata = metadata or {}
self.request_timeout = request_timeout
self.max_receive_message_length = max_receive_message_length
self.max_send_message_length = max_send_message_length

def _to_sift_channel_config(self) -> SiftChannelConfig:
"""Convert to a SiftChannelConfig.
Expand All @@ -90,6 +101,8 @@ def _to_sift_channel_config(self) -> SiftChannelConfig:
"use_ssl": self.use_ssl,
"cert_via_openssl": self.cert_via_openssl,
"request_timeout": self.request_timeout,
"max_receive_message_length": self.max_receive_message_length,
"max_send_message_length": self.max_send_message_length,
}


Expand Down
Loading