---
title: Client
description: Client in the dltHub Runtime Python SDK (dlthub_sdk)
keywords: [dlthub, runtime, python sdk, dlthub_sdk, api]
---
# Client

<!-- generated from dlthub-client 0.33.1, do not edit -->

New to the SDK? [Getting started](getting-started.md) shows how to connect and use it.

## Connecting

### `connect()` {#connect}

```python
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` | <code>str &#124; None</code> | 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` | <code><a href="#credentials">Credentials</a> &#124; None</code> | 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` | <code>str</code> | Base URL of the runtime. Set it for a local or staging runtime. |
| `organization_id` | <code>str &#124; None</code> | Default organization, so `workspaces.list()` needs no argument. |
| `verify_ssl` | <code>bool</code> | Whether the SDK verifies the TLS certificate of the runtime, on both planes. |
| `headers` | <code>Mapping[str, str] &#124; None</code> | Headers that the SDK sends with every request, on both planes. |

**Returns:** <code><a href="#runtime">Runtime</a>[<a href="#sync">Sync</a>]</code> — A blocking [`Runtime`](#runtime).

**Raises**

| Exception | When |
| --- | --- |
| `ValueError` | Both `token` and `credentials`, or neither. |

### `connect_async()` {#connect_async}

```python
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` | <code>str &#124; None</code> | As for [`connect()`](#connect). |
| `credentials` | <code><a href="#asynccredentials">AsyncCredentials</a> &#124; None</code> | As for [`connect()`](#connect), awaited. |
| `base_url` | <code>str</code> | Base URL of the runtime. Set it for a local or staging runtime. |
| `organization_id` | <code>str &#124; None</code> | Default organization, so `workspaces.list()` needs no argument. |
| `verify_ssl` | <code>bool</code> | As for [`connect()`](#connect). |
| `headers` | <code>Mapping[str, str] &#124; None</code> | As for [`connect()`](#connect). |

**Returns:** <code><a href="#runtime">Runtime</a>[<a href="#async">Async</a>]</code> — An awaiting [`Runtime`](#runtime).

**Raises**

| Exception | When |
| --- | --- |
| `ValueError` | As for [`connect()`](#connect). |

## Runtime

### `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](getting-started.md#collections-and-attributes)**

| Name | Type | Example | Description |
| --- | --- | --- | --- |
| `runtime.organizations` | <code><a href="organizations-and-workspaces#organizations">Organizations</a></code> | `runtime.organizations.list()` | The organizations of the caller. |
| `runtime.dataplanes` | <code><a href="organizations-and-workspaces#dataplanes">Dataplanes</a></code> | `runtime.dataplanes.list()` | The data planes that can hold a workspace. |
| `runtime.workspaces` | <code><a href="organizations-and-workspaces#workspaces">Workspaces</a></code> | `runtime.workspaces.list()` | The workspaces of the organization in scope. |

#### `Runtime.me()` {#runtime-me}

```python
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()`](organizations-and-workspaces.md#organization-me)
and [`Workspace.me()`](organizations-and-workspaces.md#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:** <code><a href="organizations-and-workspaces#caller">Caller</a></code> — The caller, with every organization that the person belongs to. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`NotAuthorized`](errors.md#notauthorized) | The caller lacks the access that this call needs, for example with a workspace API key. `message` says why. |
| [`NotAuthenticated`](errors.md#notauthenticated) | The token is missing, malformed, or rejected. |

#### `Runtime.close()` {#runtime-close}

```python
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:** <code>Any</code> — `None`. Async mode returns an awaitable.

## Credentials

### `AsyncCredentials` {#asynccredentials}

The awaited twin of [`Credentials`](#credentials), for `connect_async`.

#### `AsyncCredentials.token()` {#asynccredentials-token}

```python
token() -> str
```

Return the credential to send now.

**Returns:** <code>str</code> — The bearer token.

#### `AsyncCredentials.refreshed()` {#asynccredentials-refreshed}

```python
refreshed() -> str | None
```

Renew the credential after the runtime rejected it.

**Returns:** <code>str &#124; None</code> — A token to retry with, or `None` to give up.

### `Credentials` {#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()` {#credentials-token}

```python
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:** <code>str</code> — The bearer token.

#### `Credentials.refreshed()` {#credentials-refreshed}

```python
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:** <code>str &#124; None</code> — 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}

```python
Async = Literal['async']
```

Mode of a client from [`connect_async()`](#connect_async), as in `Runtime[Async]`.

Calls return awaitables and listings return async iterables.

### `KEEP` {#KEEP}

```python
KEEP = _Keep.KEEP
```

Leaves the field as it is.

It is the default of every optional update argument. `None` clears the field.

### `Keep` {#keep}

```python
Keep = Literal[_Keep.KEEP]
```

The type of [`KEEP`](#KEEP), for annotating an update argument: `str | None | Keep`.

### `Sync` {#sync}

```python
Sync = Literal['sync']
```

Mode of a client from [`connect()`](#connect), as in `Runtime[Sync]`.

Calls return values and listings return iterables.
