Skip to content

sift_client.transport.grpc_transport

Transport layer for gRPC communication.

This module provides a simple wrapper around sift_py/grpc/transport.py for making gRPC API calls. It just stores the channel and the stubs, without any additional functionality.

CLASS DESCRIPTION
GrpcClient

A simple wrapper around sift_py/grpc/transport.py for making gRPC API calls.

GrpcConfig

Configuration for gRPC API clients.

ATTRIBUTE DESCRIPTION
logger

logger module-attribute

logger = getLogger(__name__)

GrpcClient

GrpcClient(config: GrpcConfig)

A simple wrapper around sift_py/grpc/transport.py for making gRPC API calls.

This class just stores the channel and the stubs, without any additional functionality.

Initialize the gRPC client.

PARAMETER DESCRIPTION
config

The gRPC client configuration.

TYPE: GrpcConfig

METHOD DESCRIPTION
close

Close sync and async channels and stop the default loop. Idempotent.

close_sync

Close the sync channel and all async channels. Idempotent.

get_stub

Get an async stub bound to the current event loop.

ATTRIBUTE DESCRIPTION
default_loop

Return the default event loop used for synchronous API operations.

TYPE: AbstractEventLoop

is_loop_running

Whether the default loop is accepting synchronous API work.

TYPE: bool

default_loop property

default_loop: AbstractEventLoop

Return the default event loop used for synchronous API operations.

RETURNS DESCRIPTION
AbstractEventLoop

The default asyncio event loop.

is_loop_running property

is_loop_running: bool

Whether the default loop is accepting synchronous API work.

False once a close has begun, so callers can fail fast instead of scheduling a coroutine onto a loop that will never run it.

close async

close()

Close sync and async channels and stop the default loop. Idempotent.

close_sync

close_sync()

Close the sync channel and all async channels. Idempotent.

get_stub

get_stub(stub_class: type[Any]) -> Any

Get an async stub bound to the current event loop. Creates a channel and stub for this loop if needed.

GrpcConfig

GrpcConfig(
    url: str,
    api_key: str,
    use_ssl: bool = True,
    cert_via_openssl: bool = False,
    metadata: dict[str, str] | None = None,
    request_timeout: float
    | None = DEFAULT_REQUEST_TIMEOUT_SECONDS,
)

Configuration for gRPC API clients.

Initialize the gRPC configuration.

PARAMETER DESCRIPTION
url

The URI of the gRPC server.

TYPE: str

api_key

The API key for authentication.

TYPE: str

use_ssl

Whether to use SSL/TLS.

TYPE: bool DEFAULT: True

cert_via_openssl

Whether to use OpenSSL for SSL/TLS.

TYPE: bool DEFAULT: False

use_async

Whether to use async gRPC client.

metadata

Additional metadata to include in all requests.

TYPE: dict[str, str] | None DEFAULT: None

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.

TYPE: float | None DEFAULT: DEFAULT_REQUEST_TIMEOUT_SECONDS

ATTRIBUTE DESCRIPTION
api_key

cert_via_openssl

metadata

request_timeout

uri

use_ssl

api_key instance-attribute

api_key = api_key

cert_via_openssl instance-attribute

cert_via_openssl = cert_via_openssl

metadata instance-attribute

metadata = metadata or {}

request_timeout instance-attribute

request_timeout = request_timeout

uri instance-attribute

uri = normalized_url

use_ssl instance-attribute

use_ssl = use_ssl