Client
New to the SDK? Getting started shows how to connect and use it.
Connecting
connect()
connect(
*,
token: str | None = None,
credentials: Credentials | None = None,
base_url: str = 'https://api.dlthub.com',
organization_id: str | None = None,
verify_ssl: bool = True,
headers: Mapping[str, str] | None = None,
) -> Runtime[Sync]
Connect to the runtime for blocking use.
Arguments
| Name | Type | Description |
|---|---|---|
token | str | None | A personal or workspace API key (dlt_u_ or dlt_sa_ prefix) or a user JWT, when the credential does not change. The SDK does not renew a JWT. A long-lived client needs an API key or credentials. |
credentials | Credentials | None | Where the SDK reads a rotating credential before each request. The SDK renews it once if the runtime rejects it. The call needs exactly one of this and token. |
base_url | str | Base URL of the runtime. Set it for a local or staging runtime. |
organization_id | str | None | Default organization, so workspaces.list() needs no argument. |
verify_ssl | bool | Whether the SDK verifies the TLS certificate of the runtime, on both planes. |
headers | Mapping[str, str] | None | Headers that the SDK sends with every request, on both planes. |
Returns: Runtime[Sync] — A blocking Runtime.
Raises
| Exception | When |
|---|---|
ValueError | Both token and credentials, or neither. |
connect_async()
connect_async(
*,
token: str | None = None,
credentials: AsyncCredentials | None = None,
base_url: str = 'https://api.dlthub.com',
organization_id: str | None = None,
verify_ssl: bool = True,
headers: Mapping[str, str] | None = None,
) -> Runtime[Async]
Connect to the runtime for awaited use.
Arguments
| Name | Type | Description |
|---|---|---|
token | str | None | As for connect(). |
credentials | AsyncCredentials | None | As for connect(), awaited. |
base_url | str | Base URL of the runtime. Set it for a local or staging runtime. |
organization_id | str | None | Default organization, so workspaces.list() needs no argument. |
verify_ssl | bool | As for connect(). |
headers | Mapping[str, str] | None | As for connect(). |
Returns: Runtime[Async] — An awaiting Runtime.
Raises
| Exception | When |
|---|---|
ValueError | As for connect(). |
Runtime
Runtime
Entry point to the runtime.
dlthub_sdk.connect() and dlthub_sdk.connect_async() build one.
M records which one, so every object reached from it stays in the same mode.
It is also a context manager (with dlthub_sdk.connect(...) as runtime:),
which closes it at the end of the block.
A Runtime from connect_async needs async with. A plain with raises
TypeError.
| Name | Type | Example | Description |
|---|---|---|---|
runtime.organizations | Organizations | runtime.organizations.list() | The organizations of the caller. |
runtime.dataplanes | Dataplanes | runtime.dataplanes.list() | The data planes that can hold a workspace. |
runtime.workspaces | Workspaces | runtime.workspaces.list() | The workspaces of the organization in scope. |
Runtime.me()
me() -> Caller
Return the person that this token belongs to.
It works with a user token or a personal API key. The runtime refuses a
workspace API key and the identity of a job run. Organization.me()
and Workspace.me() answer for those too.
The call has side effects. It accepts the pending invitations of the person. On the first call, it also creates a personal organization and a playground workspace.
Returns: Caller — The caller, with every organization that the person belongs to. Async mode returns an awaitable.
Raises
| Exception | When |
|---|---|
NotAuthorized | The caller lacks the access that this call needs, for example with a workspace API key. message says why. |
NotAuthenticated | The token is missing, malformed, or rejected. |
Runtime.close()
close() -> Any
Release the connections that this client holds.
Every object reached from the client shares those connections. After
close, a call from any of them raises RuntimeError.
Returns: Any — None. Async mode returns an awaitable.
Credentials
AsyncCredentials
The awaited twin of Credentials, for connect_async.
AsyncCredentials.token()
token() -> str
Return the credential to send now.
Returns: str — The bearer token.
AsyncCredentials.refreshed()
refreshed() -> str | None
Renew the credential after the runtime rejected it.
Returns: str | None — A token to retry with, or None to give up.
Credentials
A control-plane credential that the SDK reads before each request.
A caller implements this protocol for a credential that changes during the
life of the client. The SDK never stores what token() returns, so a
rotation takes effect on the next request.
Credentials.token()
token() -> str
Return the credential to send now.
The SDK calls this method before every control-plane request. An implementation that renews early does it here.
Returns: str — The bearer token.
Credentials.refreshed()
refreshed() -> str | None
Renew the credential after the runtime rejected it.
The SDK calls this method at most once per request, and only after a 401.
A None return makes the rejection final, and the caller gets
NotAuthenticated.
Returns: str | None — A token to retry with, or None to give up.
Conventions
Update methods leave a field as it is when you pass KEEP, the default of every optional update argument, clear it when you pass None and set it when you pass a value.
Async
Async = Literal['async']
Mode of a client from connect_async(), as in Runtime[Async].
Calls return awaitables and listings return async iterables.
KEEP
KEEP = _Keep.KEEP
Leaves the field as it is.
It is the default of every optional update argument. None clears the field.
Keep
Keep = Literal[_Keep.KEEP]
The type of KEEP, for annotating an update argument: str | None | Keep.
Sync
Sync = Literal['sync']
Mode of a client from connect(), as in Runtime[Sync].
Calls return values and listings return iterables.