dbt Semantic Layer SDK for Python
A library for easily accessing dbt's Semantic Layer via Python.
Installation
To install the SDK, you'll need to specify optional dependencies depending on whether you want to use it synchronously (backed by requests) or via asyncio (backed by aiohttp).
# Sync installation
pip install "dbt-sl-sdk[sync]"
# Async installation
pip install "dbt-sl-sdk[async]"
Usage
To run operations against the Semantic Layer APIs, just instantiate a SemanticLayerClient with your specific connection parameters (learn more):
from dbtsl import SemanticLayerClient
client = SemanticLayerClient(
environment_id=123,
auth_token="<your-semantic-layer-api-token>",
host="semantic-layer.cloud.getdbt.com",
)
# query the first metric by `metric_time`
def main():
with client.session():
metrics = client.metrics()
table = client.query(
metrics=[metrics[0].name],
group_by=["metric_time"],
)
print(table)
main()
Note that all method calls that will reach out to the APIs need to be within a client.session() context manager. By using a session, the client can connect to the APIs only once, and reuse the same connection between API calls.
asyncio
If you're using asyncio, import AsyncSemanticLayerClient from dbtsl.asyncio. The APIs of SemanticLayerClient and AsyncSemanticLayerClient are the same. The only difference is that the asyncio version has async methods which need to be awaited.
That same sync example can be converted into asyncio code like so:
import asyncio
from dbtsl.asyncio import AsyncSemanticLayerClient
client = AsyncSemanticLayerClient(
environment_id=123,
auth_token="<your-semantic-layer-api-token>",
host="semantic-layer.cloud.getdbt.com",
)
async def main():
async with client.session():
metrics = await client.metrics()
table = await client.query(
metrics=[metrics[0].name],
group_by=["metric_time"],
)
print(table)
asyncio.run(main())
Integrating with dataframe libraries
By design, the SDK returns all query data as pyarrow tables. If you wish to use the data with libraries like pandas or polars, you need to manually download them and convert the data into their format.
If you're using pandas:
# ... initialize client
arrow_table = client.query(...)
pandas_df = arrow_table.to_pandas()
If you're using polars:
import polars as pl
# ... initialize client
arrow_table = client.query(...)
polars_df = pl.from_arrow(arrow_table)
Lazy loading
By default, the SDK will eagerly request for lists of nested objects. For example, in the list of Metric returned by client.metrics(), each metric will contain the list of its dimensions, entities and measures. This is convenient in most cases, but can make your returned data really large in case your project is really large, which can slow things down.
It is possible to set the client to lazy=True, which will make it skip populating nested object lists unless you explicitly load ask for it on a per-model basis. Check our lazy loading example to learn more.
More examples
Check out our usage examples to learn more.
Disabling telemetry
By default, dbt the SDK sends some platform-related information to dbt Labs. If you'd like to opt out, do
from dbtsl.env import PLATFORM
PLATFORM.anonymous = True
# ... initialize client
Contributing
If you're interested in contributing to this project, check out our contribution guidelines.
Metadata
Release files for dbt-sl-sdk 0.13.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dbt_sl_sdk-0.13.4.tar.gz | 29.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dbt_sl_sdk-0.13.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 78.1 kB
Release files / dbt_sl_sdk-0.13.4.tar.gz
| Download URL | dbt_sl_sdk-0.13.4.tar.gz |
|---|---|
| Size | 29.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3422d50dcc1d5b7c9f81ac4fe13fe61dfc25de0cb479a81003f1023cd6780697
|
|
BLAKE2b-256 checksum How to use checksums |
e4dbc8ec49d754305cbdb4520b4241312915db7c17a5f50dc8039771a459a5d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 27, 2026.
Transparency logRelease files / dbt_sl_sdk-0.13.4-py3-none-any.whl
| Download URL | dbt_sl_sdk-0.13.4-py3-none-any.whl |
|---|---|
| Size | 48.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea347f744cfdd14569a2c65428be8bc2115e222558d756fcdd58b914dc8203d2
|
|
BLAKE2b-256 checksum How to use checksums |
8c6ab551fd98c51e146ba6c7ef0af3499f221753f3fefb95aa4a20a2ff3e9a0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 27, 2026.
Transparency log