Skip to content

client

pixel_client

PixelClientKwargs

Bases: TypedDict

TypedDict for PixelClient constructor arguments.

Source code in src/pixel_client/_base.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
class PixelClientKwargs(TypedDict, total=False):
    """TypedDict for PixelClient constructor arguments."""

    timeout_pixel: httpx.Timeout
    """Timeout configuration for Pixel API requests. Defaults to DEFAULT_PIXEL_TIMEOUT."""

    timeout_upload: httpx.Timeout
    """Timeout configuration for file uploads. Defaults to DEFAULT_UPLOAD_TIMEOUT"""

    upload_num_retries: int
    """Number of retries for upload operations. Defaults to DEFAULT_UPLOAD_RETRIES."""

    upload_max_concurrency: int
    """Maximum number of concurrent uploads. Defaults to 10."""

timeout_pixel instance-attribute

timeout_pixel: httpx.Timeout

Timeout configuration for Pixel API requests. Defaults to DEFAULT_PIXEL_TIMEOUT.

timeout_upload instance-attribute

timeout_upload: httpx.Timeout

Timeout configuration for file uploads. Defaults to DEFAULT_UPLOAD_TIMEOUT

upload_num_retries instance-attribute

upload_num_retries: int

Number of retries for upload operations. Defaults to DEFAULT_UPLOAD_RETRIES.

upload_max_concurrency instance-attribute

upload_max_concurrency: int

Maximum number of concurrent uploads. Defaults to 10.

get_client

get_client(
    async_: Literal[False] = ...,
    settings: PixelApiSettings | None = None,
    **kwargs: Unpack[PixelClientKwargs],
) -> PixelClient
get_client(
    async_: Literal[True] = ...,
    settings: PixelApiSettings | None = None,
    **kwargs: Unpack[PixelClientKwargs],
) -> PixelClientAsync
get_client(
    async_: bool = False,
    settings: PixelApiSettings | None = None,
    **kwargs: Unpack[PixelClientKwargs],
) -> PixelClientAsync | PixelClient

Get the pixel client.

Parameters:

Name Type Description Default
async_ bool

Whether to return an asynchronous client.

False
settings PixelApiSettings | None

Settings for the Pixel API client. If None, defaults are used.

None
**kwargs Unpack[PixelClientKwargs]

Additional keyword arguments to pass to the client constructor.

{}
Example
from pixel_client import get_client, PixelApiSettings
# Settings from environment variables
async_client = get_client(async_=True)
# Settings from a .env file, see https://docs.pydantic.dev/latest/concepts/pydantic_settings/#dotenv-env-support
settings = PixelApiSettings(_env_file="path/to/.env")
# async_ defaults to False, so this will return a synchronous client
sync_client = get_client(settings=settings)
Note

The client is cached and will be reused on subsequent calls, unless the settings change.

Source code in src/pixel_client/__init__.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def get_client(
    async_: bool = False,
    settings: PixelApiSettings | None = None,
    **kwargs: Unpack[PixelClientKwargs],
) -> PixelClientAsync | PixelClient:
    """
    Get the pixel client.

    Args:
        async_ (bool): Whether to return an asynchronous client.
        settings (PixelApiSettings | None): Settings for the Pixel API client. If None, defaults are used.
        **kwargs: Additional keyword arguments to pass to the client constructor.
    Returns:
        PixelClientAsync | PixelClient: An instance of the Pixel API client, either synchronous or asynchronous.

    Example:
        ```python
        from pixel_client import get_client, PixelApiSettings
        # Settings from environment variables
        async_client = get_client(async_=True)
        # Settings from a .env file, see https://docs.pydantic.dev/latest/concepts/pydantic_settings/#dotenv-env-support
        settings = PixelApiSettings(_env_file="path/to/.env")
        # async_ defaults to False, so this will return a synchronous client
        sync_client = get_client(settings=settings)
        ```

    Note:
        The client is cached and will be reused on subsequent calls, unless the settings change.
    """
    return _cached_get_client(async_, settings or PixelApiSettings(), **kwargs)  # type: ignore