Skip to content

sift_client.transport

MODULE DESCRIPTION
base_connection
cache
grpc_transport

Transport layer for gRPC communication.

rest_transport

Transport layer for REST communication.

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.

RestClient

A client wrapper for REST APIs.

RestConfig

Configuration for REST API clients.

SiftConnectionConfig

Configuration for Grpc and Rest connections.

WithGrpcClient

Abstract base class for classes that require a gRPC client.

WithRestClient

Abstract base class for classes that require a REST client.

__all__ module-attribute

__all__ = [
    "CacheConfig",
    "CacheMode",
    "GrpcClient",
    "GrpcConfig",
    "RestClient",
    "RestConfig",
    "SiftConnectionConfig",
    "WithGrpcClient",
    "WithRestClient",
]

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).

TYPE: CacheMode DEFAULT: ENABLED

ttl

Time-to-live for cached entries in seconds.

TYPE: int DEFAULT: DEFAULT_CACHE_TTL_SECONDS

cache_folder

Path to the cache directory.

TYPE: Path | str DEFAULT: DEFAULT_CACHE_FOLDER

size_limit

Maximum size of the cache in bytes.

TYPE: int DEFAULT: DEFAULT_CACHE_SIZE_LIMIT_BYTES

METHOD DESCRIPTION
to_sift_cache_config

Convert to a SiftCacheConfig for use with sift_py.grpc.transport.

cache_path instance-attribute

cache_path = str(Path(cache_folder) / 'grpc_cache')

is_enabled property

is_enabled: bool

Check if caching is enabled.

mode instance-attribute

mode = mode

should_clear_on_init property

should_clear_on_init: bool

Check if cache should be cleared on initialization.

size_limit instance-attribute

size_limit = size_limit

ttl instance-attribute

ttl = ttl

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

Bases: str, Enum

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

CLEAR_ON_INIT class-attribute instance-attribute

CLEAR_ON_INIT = 'clear_on_init'

DISABLED class-attribute instance-attribute

DISABLED = 'disabled'

ENABLED class-attribute instance-attribute

ENABLED = '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: GrpcConfig

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: AbstractEventLoop

cache instance-attribute

cache = _init_cache()

default_loop property

default_loop: AbstractEventLoop

Return the default event loop used for synchronous API operations.

RETURNS DESCRIPTION
AbstractEventLoop

The default asyncio event loop.

__aenter__ async

__aenter__()

__aexit__ async

__aexit__(exc_type, exc_val, exc_tb)

__enter__

__enter__()

__exit__

__exit__(exc_type, exc_val, exc_tb)

close async

close()

Close sync and async channels and stop the default loop.

close_sync

close_sync()

Close the sync channel and all async channels.

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,
    cache_config: CacheConfig | None = None,
)

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

metadata

Additional metadata to include in all requests.

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

cache_config

Optional cache configuration. If None, caching is disabled.

TYPE: CacheConfig | None DEFAULT: None

ATTRIBUTE DESCRIPTION
api_key

cache_config

cert_via_openssl

metadata

uri

use_ssl

api_key instance-attribute

api_key = api_key

cache_config instance-attribute

cache_config = cache_config

cert_via_openssl instance-attribute

cert_via_openssl = cert_via_openssl

metadata instance-attribute

metadata = metadata or {}

uri instance-attribute

uri = url

use_ssl instance-attribute

use_ssl = use_ssl

RestClient

RestClient(config: RestConfig)

A client wrapper for REST APIs.

This class provides a wrapper around sift_py/rest.py for making REST API calls. It handles authentication, retries, and error mapping.

Initialize the REST client.

PARAMETER DESCRIPTION
config

The REST client configuration.

TYPE: RestConfig

METHOD DESCRIPTION
close

Close the REST client session.

delete

Execute a DELETE request.

get

Execute a GET request.

patch

Execute a PATCH request.

post

Execute a POST request.

put

Execute a PUT request.

ATTRIBUTE DESCRIPTION
base_url

Get the base URL of the REST client.

TYPE: str

base_url property

base_url: str

Get the base URL of the REST client.

RETURNS DESCRIPTION
str

The base URL string.

close

close() -> None

Close the REST client session.

delete

delete(
    endpoint: str, headers: dict | None = None, **kwargs
) -> Response

Execute a DELETE request.

PARAMETER DESCRIPTION
endpoint

The API endpoint to call.

TYPE: str

headers

Additional headers to include in the request.

TYPE: dict | None DEFAULT: None

**kwargs

Additional arguments to pass to the request.

DEFAULT: {}

RETURNS DESCRIPTION
Response

The HTTP response.

get

get(
    endpoint: str, headers: dict | None = None, **kwargs
) -> Response

Execute a GET request.

PARAMETER DESCRIPTION
endpoint

The API endpoint to call.

TYPE: str

headers

Additional headers to include in the request.

TYPE: dict | None DEFAULT: None

**kwargs

Additional arguments to pass to the request.

DEFAULT: {}

RETURNS DESCRIPTION
Response

The HTTP response.

patch

patch(
    endpoint: str,
    headers: dict | None = None,
    data=None,
    **kwargs,
) -> Response

Execute a PATCH request.

PARAMETER DESCRIPTION
endpoint

The API endpoint to call.

TYPE: str

headers

Additional headers to include in the request.

TYPE: dict | None DEFAULT: None

data

The data to send in the request body.

DEFAULT: None

**kwargs

Additional arguments to pass to the request.

DEFAULT: {}

RETURNS DESCRIPTION
Response

The HTTP response.

post

post(
    endpoint: str,
    headers: dict | None = None,
    data=None,
    **kwargs,
) -> Response

Execute a POST request.

PARAMETER DESCRIPTION
endpoint

The API endpoint to call.

TYPE: str

headers

Additional headers to include in the request.

TYPE: dict | None DEFAULT: None

data

The data to send in the request body.

DEFAULT: None

**kwargs

Additional arguments to pass to the request.

DEFAULT: {}

RETURNS DESCRIPTION
Response

The HTTP response.

put

put(
    endpoint: str,
    headers: dict | None = None,
    data=None,
    **kwargs,
) -> Response

Execute a PUT request.

PARAMETER DESCRIPTION
endpoint

The API endpoint to call.

TYPE: str

headers

Additional headers to include in the request.

TYPE: dict | None DEFAULT: None

data

The data to send in the request body.

DEFAULT: None

**kwargs

Additional arguments to pass to the request.

DEFAULT: {}

RETURNS DESCRIPTION
Response

The HTTP response.

RestConfig

RestConfig(
    base_url: str,
    api_key: str,
    use_ssl: bool = True,
    cert_via_openssl: bool = False,
    retry: Retry = _DEFAULT_REST_RETRY,
)

Configuration for REST API clients.

Initialize the REST configuration.

PARAMETER DESCRIPTION
base_url

The base URL of the API.

TYPE: str

api_key

The API key for authentication.

TYPE: str

use_ssl

Whether to use HTTPS.

TYPE: bool DEFAULT: True

cert_via_openssl

Whether to use OpenSSL for SSL/TLS.

TYPE: bool DEFAULT: False

retry

The retry configuration for requests.

TYPE: Retry DEFAULT: _DEFAULT_REST_RETRY

ATTRIBUTE DESCRIPTION
api_key

base_url

cert_via_openssl

retry

use_ssl

api_key instance-attribute

api_key = api_key

base_url instance-attribute

base_url = base_url

cert_via_openssl instance-attribute

cert_via_openssl = cert_via_openssl

retry instance-attribute

retry = retry

use_ssl instance-attribute

use_ssl = use_ssl

SiftConnectionConfig

SiftConnectionConfig(
    grpc_url: str,
    rest_url: str,
    api_key: str,
    use_ssl: bool = True,
    cert_via_openssl: bool = False,
    cache_config: CacheConfig | None = DEFAULT_CACHE_CONFIG,
)

Configuration for Grpc and Rest connections.

This class provides a unified configuration for both gRPC and REST connections, allowing for consistent settings across different transport protocols.

Initialize the connection configuration.

PARAMETER DESCRIPTION
grpc_url

The URL for the gRPC service.

TYPE: str

rest_url

The URL for the REST service.

TYPE: str

api_key

The API key for authentication.

TYPE: str

use_ssl

Whether to use SSL/TLS for secure connections.

TYPE: bool DEFAULT: True

cert_via_openssl

Whether to use OpenSSL for certificate validation.

TYPE: bool DEFAULT: False

cache_config

Optional cache configuration for gRPC responses.

TYPE: CacheConfig | None DEFAULT: DEFAULT_CACHE_CONFIG

METHOD DESCRIPTION
get_grpc_config

Create and return a GrpcConfig with the current settings.

get_rest_config

Create and return a RestConfig with the current settings.

ATTRIBUTE DESCRIPTION
api_key

cache_config

cert_via_openssl

grpc_url

rest_url

use_ssl

api_key instance-attribute

api_key = api_key

cache_config instance-attribute

cache_config = cache_config

cert_via_openssl instance-attribute

cert_via_openssl = cert_via_openssl

grpc_url instance-attribute

grpc_url = grpc_url

rest_url instance-attribute

rest_url = rest_url

use_ssl instance-attribute

use_ssl = use_ssl

get_grpc_config

get_grpc_config()

Create and return a GrpcConfig with the current settings.

RETURNS DESCRIPTION

A GrpcConfig object configured with this instance's settings.

get_rest_config

get_rest_config()

Create and return a RestConfig with the current settings.

RETURNS DESCRIPTION

A RestConfig object configured with this instance's settings.

WithGrpcClient

WithGrpcClient(grpc_client: GrpcClient)

Bases: ABC

Abstract base class for classes that require a gRPC client.

This class provides access to a gRPC client for making API calls.

Initialize with a gRPC client.

PARAMETER DESCRIPTION
grpc_client

The gRPC client to use for API calls.

TYPE: GrpcClient

METHOD DESCRIPTION
get_asyncio_loop

Gets the default asyncio loop used by the gRPC client.

get_asyncio_loop

get_asyncio_loop() -> AbstractEventLoop

Gets the default asyncio loop used by the gRPC client.

RETURNS DESCRIPTION
AbstractEventLoop

The default asyncio loop.

WithRestClient

WithRestClient(rest_client: RestClient)

Bases: ABC

Abstract base class for classes that require a REST client.

This class provides access to a REST client for making API calls.

Initialize with a REST client.

PARAMETER DESCRIPTION
rest_client

The REST client to use for API calls.

TYPE: RestClient