client
pixel_client ¶
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 | |