See it in action
Try the getting started Jupyter notebook for a hands-on walkthrough.
Installation
Quick start
Query builder
The SDK provides two patterns for building queries: single-call and chainable builder.Single-call pattern
Pass all parameters at once for simple queries:Chainable builder pattern
Build queries incrementally with method chaining. Each method returns a new immutableQuery object:
- Immutable — each method returns a new
Queryobject, safe for reuse - Lazy evaluation — API calls only happen when
.execute()is called - Order-independent — methods can be called in any order
- Composable — create base queries and extend them
Dimensions and metrics
Access dimensions and metrics as attributes on the model:- Lazy loading — fetched from API on first access, then cached
- Fuzzy matching — typos suggest closest matches
- Tab completion — works in Jupyter/IPython for discovery
- Rich display — HTML rendering in notebooks
Filters
Use Python comparison operators on dimensions to create filters:Supported operators by data type
| Operator | Numeric | String | Boolean | Date |
|---|---|---|---|---|
is null | Yes | Yes | Yes | Yes |
is not null | Yes | Yes | Yes | Yes |
equals / is | Yes | Yes | Yes | Yes |
is not | Yes | Yes | - | Yes |
is less than | Yes | - | - | - |
is greater than | Yes | - | - | - |
starts with | - | Yes | - | - |
ends with | - | Yes | - | - |
includes | - | Yes | - | - |
in the last | - | - | - | Yes |
in the next | - | - | - | Yes |
in the current | - | - | - | Yes |
is before | - | - | - | Yes |
is after | - | - | - | Yes |
is between | Yes | - | - | Yes |
is not between | Yes | - | - | Yes |
Combining filters
Use& (AND) and | (OR) to combine filters:
.filter() calls on a query are combined with AND logic:
Sorting
Sort results using the.sort() method:
Results
Query results implement a unifiedResultSet interface.
Converting results
Iterating over results
Pagination
For large result sets, results are paginated automatically:result.query_uuid— unique identifier for the queryresult.total_results— total number of rowsresult.total_pages— number of pagesresult.fields— field metadata
SQL runner
Execute raw SQL queries directly against your data warehouse:Exception handling
The SDK provides specific exceptions for different error conditions:LightdashError— base exception for all SDK errorsQueryError— query execution failed (HTTP 400)QueryTimeout— query exceeded timeout (HTTP 408)QueryCancelled— query was cancelled (HTTP 499)
Complete example
For the full SDK source and more examples, see the Python SDK on GitHub.