Skip to content

sift_client

Warning

The Sift Client is experimental and is subject to change.

Sift Client Library

This library provides a high-level Python client for interacting with Sift APIs. It offers both synchronous and asynchronous interfaces, strong type checking, and a Pythonic API design.

Installation

pip install sift-stack-py

Getting Started

Initializing the Client

You can initialize the Sift client with your API key and service URLs:

from sift_client import SiftClient
from datetime import datetime

# Initialize with individual parameters
client = SiftClient(
    api_key="your-api-key",
    grpc_url="your-sift-grpc-url",
    rest_url="your-sift-rest-url"
)

# Or use a connection configuration
from sift_client.transport import SiftConnectionConfig

config = SiftConnectionConfig(
    api_key="your-api-key",
    grpc_url="your-sift-grpc-url",
    rest_url="your-sift-rest-url"
)
client = SiftClient(connection_config=config)

The SiftConnectionConfig provides access to additional configuration options such as use_ssl and cert_via_openssl.

Using Synchronous and Asynchronous APIs

The Sift client provides both synchronous and asynchronous versions of all APIs. You can choose the one that best fits your application's needs.

Synchronous API

The synchronous API is perfect for scripts, notebooks, and applications that don't need asynchronous operation:

# Get an asset by ID
asset = client.assets.get(asset_id="asset123")

# List assets with filtering
assets = client.assets.list_(
    name_contains="example",
    created_after=datetime(2023, 1, 1),
    include_archived=False
)

# Find a single asset matching criteria
asset = client.assets.find(name="my-asset")
Asynchronous API

The asynchronous API is ideal for high-performance applications and services that need to make concurrent API calls:

import asyncio


async def get_asset_async():
    # Get an asset by ID asynchronously
    asset = await client.assets_async.get(asset_id="asset123")

    # Running Sync within async also works
    some_other_asset = client.assets.get(asset_id="asset456")

    return asset


# Run in an async context
asset = asyncio.run(get_asset_async())

Working with Sift Types

Sift types (like Asset, Run, etc.) are immutable Pydantic models that provide a convenient interface for working with Sift resources.

Accessing Properties
# Get an asset
asset = client.assets.get(asset_id="asset123")

# Access properties
print(f"Asset name: {asset.name}")
print(f"Created on: {asset.created_date}")
print(f"Tags: {', '.join(asset.tags)}")
print(f"Is archived: {asset.is_archived}")
Using Methods on Sift Types

Sift types have convenient methods for common operations. These methods use the synchronous API internally. Using these methods will update the instance in-place.

# Get an asset
asset = client.assets.get(asset_id="asset123")

# Archive the asset
asset.archive(archive_runs=True)

# Update the asset
asset.update({
    "tags": ["updated", "example"]
})

Note: Type methods only work with the synchronous API. If you need to use the asynchronous API, you should use the resource APIs directly.

Creating Update Models

For more complex updates, you can create update models (instead of a key-value dictionary):

from sift_client.types.asset import AssetUpdate

# Create an update model
update = AssetUpdate(tags=["new", "tags"])

# Apply the update
asset = client.assets.update(asset="asset123", update=update)

# Or using the asset method
asset = client.assets.get(asset_id="asset123").update(update)

Advanced Usage

Working with Tags

Tags are a powerful way to organize and filter your assets:

# Add tags when updating an asset
asset.update({
    "tags": ["production", "model-v1", "trained"]
})

# Filter assets by tags
production_assets = client.assets.list_(
    tags=["production"]
)

Filtering Assets

The client provides various ways to filter different Sift types:

# Filter by name (exact match)
assets = client.assets.list_(name="my-model")

# Filter by name (contains)
assets = client.assets.list_(name_contains="model")

# Filter by name (regex)
assets = client.assets.list_(name_regex="model-v[0-9]+")

# Filter by creation date
assets = client.assets.list_(
    created_after=datetime(2023, 1, 1),
    created_before=datetime(2023, 12, 31)
)

# Filter by modification date
assets = client.assets.list_(
    modified_after=datetime(2023, 6, 1)
)

# Include archived assets
all_assets = client.assets.list_(include_archived=True)

# Limit the number of results
recent_assets = client.assets.list_(
    limit=10,
    order_by="modified_date desc"
)
MODULE DESCRIPTION
client
errors
examples
resources
sift_types
transport
util

Utility modules for the sift_client package.

CLASS DESCRIPTION
SiftClient

SiftClient is a high-level client for interacting with Sift's APIs.

SiftConnectionConfig

Configuration for Grpc and Rest connections.

__all__ module-attribute

__all__ = ['SiftClient', 'SiftConnectionConfig']

handler module-attribute

handler = StreamHandler(stdout)

logger module-attribute

logger = getLogger('sift_client')

SiftClient

SiftClient(
    api_key: str | None = None,
    grpc_url: str | None = None,
    rest_url: str | None = None,
    connection_config: SiftConnectionConfig | None = None,
)

Bases: WithGrpcClient, WithRestClient

SiftClient is a high-level client for interacting with Sift's APIs.

It provides both synchronous and asynchronous interfaces, strong type checking, and a Pythonic API design.

Warning

The Sift Client is experimental and is subject to change.

Initialize the SiftClient with specific connection parameters or a connection_config.

PARAMETER DESCRIPTION
api_key

The Sift API key for authentication.

TYPE: str | None DEFAULT: None

grpc_url

The Sift gRPC API URL.

TYPE: str | None DEFAULT: None

rest_url

The Sift REST API URL.

TYPE: str | None DEFAULT: None

connection_config

A SiftConnectionConfig object to configure the connection behavior of the SiftClient.

TYPE: SiftConnectionConfig | None DEFAULT: None

ATTRIBUTE DESCRIPTION
assets

Instance of the Assets API for making synchronous requests.

TYPE: AssetsAPI

async_

Accessor for the asynchronous APIs. All asynchronous APIs are available as attributes on this accessor.

TYPE: AsyncAPIs

calculated_channels

Instance of the Calculated Channels API for making synchronous requests.

TYPE: CalculatedChannelsAPI

channels

Instance of the Channels API for making synchronous requests.

TYPE: ChannelsAPI

grpc_client

The gRPC client used by the SiftClient for making gRPC API calls.

TYPE: GrpcClient

ingestion

Instance of the Ingestion API for making synchronous requests.

TYPE: IngestionAPIAsync

ping

Instance of the Ping API for making synchronous requests.

TYPE: PingAPI

rest_client

The REST client used by the SiftClient for making REST API calls.

TYPE: RestClient

rules

Instance of the Rules API for making synchronous requests.

TYPE: RulesAPI

runs

Instance of the Runs API for making synchronous requests.

TYPE: RunsAPI

assets instance-attribute

assets: AssetsAPI = AssetsAPI(self)

Instance of the Assets API for making synchronous requests.

async_ instance-attribute

async_: AsyncAPIs = AsyncAPIs(
    ping=PingAPIAsync(self),
    assets=AssetsAPIAsync(self),
    calculated_channels=CalculatedChannelsAPIAsync(self),
    channels=ChannelsAPIAsync(self),
    ingestion=IngestionAPIAsync(self),
    rules=RulesAPIAsync(self),
    runs=RunsAPIAsync(self),
)

Accessor for the asynchronous APIs. All asynchronous APIs are available as attributes on this accessor.

calculated_channels instance-attribute

calculated_channels: CalculatedChannelsAPI = (
    CalculatedChannelsAPI(self)
)

Instance of the Calculated Channels API for making synchronous requests.

channels instance-attribute

channels: ChannelsAPI = ChannelsAPI(self)

Instance of the Channels API for making synchronous requests.

grpc_client property

grpc_client: GrpcClient

The gRPC client used by the SiftClient for making gRPC API calls.

ingestion instance-attribute

Instance of the Ingestion API for making synchronous requests.

ping instance-attribute

ping: PingAPI = PingAPI(self)

Instance of the Ping API for making synchronous requests.

rest_client property

rest_client: RestClient

The REST client used by the SiftClient for making REST API calls.

rules instance-attribute

rules: RulesAPI = RulesAPI(self)

Instance of the Rules API for making synchronous requests.

runs instance-attribute

runs: RunsAPI = RunsAPI(self)

Instance of the Runs API for making synchronous requests.

SiftConnectionConfig

SiftConnectionConfig(
    grpc_url: str,
    rest_url: str,
    api_key: str,
    use_ssl: bool = False,
    cert_via_openssl: bool = False,
)

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

cert_via_openssl

Whether to use OpenSSL for certificate validation.

TYPE: bool DEFAULT: False

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

cert_via_openssl

grpc_url

rest_url

use_ssl

api_key instance-attribute

api_key = api_key

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.