Skip to main content
Version: 1.33.0 (latest) 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 runtime for blocking use.

Arguments

NameTypeDescription
tokenstr | NoneA 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.
credentialsCredentials | NoneWhere 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_urlstrBase URL of the runtime. Set it for a local or staging runtime.
organization_idstr | NoneDefault organization, so workspaces.list() needs no argument.
verify_sslboolWhether the SDK verifies the TLS certificate of the runtime, on both planes.
headersMapping[str, str] | NoneHeaders that the SDK sends 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 runtime for awaited use.

Arguments

NameTypeDescription
tokenstr | NoneAs for connect().
credentialsAsyncCredentials | NoneAs for connect(), awaited.
base_urlstrBase URL of the runtime. Set it for a local or staging runtime.
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 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.

Collections

NameTypeExampleDescription
runtime.organizationsOrganizationsruntime.organizations.list()The organizations of the caller.
runtime.dataplanesDataplanesruntime.dataplanes.list()The data planes that can hold a workspace.
runtime.workspacesWorkspacesruntime.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

ExceptionWhen
NotAuthorizedThe caller lacks the access that this call needs, for example with a workspace API key. message says why.
NotAuthenticatedThe 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.

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.