Skip to main content
Version: devel View Markdown

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 platform for blocking use.

Arguments

NameTypeDescription
tokenstr | NoneAn API key (dlt_u_/dlt_sa_ prefixed) or a user JWT, when the credential does not change. A JWT is not renewed, so a long-lived client should hold an API key or pass credentials.
credentialsCredentials | NoneWhere to read the credential before each request, for one that rotates. Renewed once if the platform rejects it. Exactly one of this and token is required.
base_urlstrPlatform base URL. Override for local or staging.
organization_idstr | NoneDefault organization, so workspaces.list() needs no argument.
verify_sslboolVerify the platform's TLS certificate. Applies on both planes.
headersMapping[str, str] | NoneSent with every request, on both planes.

Returns: Runtime[Sync] — A blocking Runtime.

Raises

ExceptionWhen
ValueErrorBoth 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 platform for awaited use.

Arguments

NameTypeDescription
tokenstr | NoneAs for connect().
credentialsAsyncCredentials | NoneAs for connect(), awaited.
base_urlstrPlatform base URL. Override for local or staging.
organization_idstr | NoneDefault organization, so workspaces.list() needs no argument.
verify_sslboolAs for connect().
headersMapping[str, str] | NoneAs for connect().

Returns: Runtime[Async] — An awaiting Runtime.

Raises

ExceptionWhen
ValueErrorAs for connect().

Runtime​

Runtime​

Entry point to the platform.

Build one with dlthub_sdk.connect() or dlthub_sdk.connect_async(); M records which, so every object reached from it stays in the same mode.

Usable as a context manager (with dlthub_sdk.connect(...) as runtime:), which closes it on the way out.

A runtime from connect_async needs async with; plain with raises TypeError.

Collections

NameTypeExampleDescription
runtime.organizationsOrganizationsruntime.organizations.list()Organization lookup.
runtime.dataplanesDataplanesruntime.dataplanes.list()The data planes a workspace can be placed on.
runtime.workspacesWorkspacesruntime.workspaces.list()Workspace lookup.

Runtime.me()​

me() -> Caller

Return the person this token belongs to.

Works with a user token or a user API key. A service-account API key or a platform run's identity is refused; Organization.me() and Workspace.me() answer for those too.

Not side-effect free: it accepts the person's pending invitations, and on their first call creates a personal organization and playground workspace.

Returns: Caller — The caller, with every organization they belong to; awaitable in async mode.

Raises

ExceptionWhen
NotAuthorizedThe caller lacks the access this call needs; message says why.
NotAuthenticatedThe token is missing, malformed, or rejected.

Runtime.close()​

close() -> Any

Release the connections held for this client.

Anything reached from it — a workspace, a job, a collection — shares those connections, so close only when done with all of them. Calls after close raise RuntimeError.

Returns: Any — None; awaitable in async mode.

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 platform rejected it.

Returns: str | None — A token to retry with, or None to give up.

Credentials​

A control-plane credential the SDK reads before each request.

Implement this for a credential that changes over the client's life. 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.

Called before every control-plane request, so an implementation that renews proactively does it here.

Returns: str — The bearer token.

Credentials.refreshed()​

refreshed() -> str | None

Renew the credential after the platform rejected it.

Called at most once per request, only for a 401. Returning None makes the rejection final and the caller sees 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

Leave this field as it is: the default of every optional update argument.

Pass None to clear a field instead.

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.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.