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 |
|---|---|
CacheConfig |
Configuration for gRPC response caching. |
CacheMode |
Cache behavior modes. |
GrpcClient |
A simple wrapper around sift_py/grpc/transport.py for making gRPC API calls. |
GrpcConfig |
Configuration for gRPC API clients. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
DEFAULT_CACHE_CONFIG |
|
DEFAULT_CACHE_FOLDER |
|
DEFAULT_CACHE_SIZE_LIMIT_BYTES |
|
DEFAULT_CACHE_TTL_SECONDS |
|
logger |
|
CacheConfig
¶
CacheConfig(
mode: CacheMode = ENABLED,
ttl: int = DEFAULT_CACHE_TTL_SECONDS,
cache_folder: Path | str = DEFAULT_CACHE_FOLDER,
size_limit: int = DEFAULT_CACHE_SIZE_LIMIT_BYTES,
)
Configuration for gRPC response caching.
| ATTRIBUTE | DESCRIPTION |
|---|---|
mode |
Cache behavior mode (enabled, disabled, clear_on_init).
|
ttl |
Time-to-live for cached entries in seconds. Default is 1 week.
|
cache_folder |
Path to the cache directory. Default is system temp directory.
|
size_limit |
Maximum size of the cache in bytes. Default is 5GB.
|
Initialize the cache configuration.
| PARAMETER | DESCRIPTION |
|---|---|
mode
|
Cache behavior mode (use CacheMode constants). |
ttl
|
Time-to-live for cached entries in seconds.
TYPE:
|
cache_folder
|
Path to the cache directory.
TYPE:
|
size_limit
|
Maximum size of the cache in bytes.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
to_sift_cache_config |
Convert to a SiftCacheConfig for use with sift_py.grpc.transport. |
should_clear_on_init
property
¶
should_clear_on_init: bool
Check if cache should be cleared on initialization.
to_sift_cache_config
¶
to_sift_cache_config() -> SiftCacheConfig
Convert to a SiftCacheConfig for use with sift_py.grpc.transport.
| RETURNS | DESCRIPTION |
|---|---|
SiftCacheConfig
|
A SiftCacheConfig dictionary. |
CacheMode
¶
Cache behavior modes.
- ENABLED: Cache is enabled and persists across sessions
- DISABLED: Cache is completely disabled
- CLEAR_ON_INIT: Cache is cleared when client is initialized (useful for notebooks)
| ATTRIBUTE | DESCRIPTION |
|---|---|
CLEAR_ON_INIT |
|
DISABLED |
|
ENABLED |
|
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:
|
| METHOD | DESCRIPTION |
|---|---|
__aenter__ |
|
__aexit__ |
|
__enter__ |
|
__exit__ |
|
close |
Close sync and async channels and stop the default loop. |
close_sync |
Close the sync channel and all async channels. |
get_stub |
Get an async stub bound to the current event loop. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
cache |
|
default_loop |
Return the default event loop used for synchronous API operations.
TYPE:
|
default_loop
property
¶
default_loop: AbstractEventLoop
Return the default event loop used for synchronous API operations.
| RETURNS | DESCRIPTION |
|---|---|
AbstractEventLoop
|
The default asyncio event loop. |
GrpcConfig
¶
GrpcConfig(
url: str,
api_key: str,
use_ssl: bool = True,
cert_via_openssl: bool = False,
metadata: dict[str, str] | None = None,
cache_config: CacheConfig | None = None,
)
Configuration for gRPC API clients.
Initialize the gRPC configuration.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
The URI of the gRPC server.
TYPE:
|
api_key
|
The API key for authentication.
TYPE:
|
use_ssl
|
Whether to use SSL/TLS.
TYPE:
|
cert_via_openssl
|
Whether to use OpenSSL for SSL/TLS.
TYPE:
|
metadata
|
Additional metadata to include in all requests. |
cache_config
|
Optional cache configuration. If None, caching is disabled.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
api_key |
|
cache_config |
|
cert_via_openssl |
|
metadata |
|
uri |
|
use_ssl |
|