Skip to main content
This class is used to interact with a Squirrels project from Python. For example, you can create a SquirrelsProject object in Python (or Jupyter Notebook) as such:
And then call methods on the SquirrelsProject object to perform various operations. This class can be imported from the squirrels module.

Constructor

Creates a SquirrelsProject object.

Methods

Methods that can be invoked from the SquirrelsProject object.

compile()

Async method to compile the SQL templates into files in the “target/” folder. Same functionality as the “sqrl compile” CLI.
None
No return value.

get_all_data_models()

Async method to list all data models in the project.
list[DataModelItem]
A list of DataModelItem objects. The DataModelItem object has the following properties:

get_all_data_lineage()

Async method to retrieve lineage across models, datasets, and dashboards.
LineageRelation[]
A list of LineageRelation objects. The LineageRelation object has the following properties:

seed()

Method to retrieve a seed as a polars LazyFrame given a seed name.
polars.LazyFrame
A polars LazyFrame of the seed data.

build()

Async method to build the virtual data environment. Same functionality as the “sqrl build” CLI.
None
No return value.

dataset_metadata()

Method to retrieve the metadata (descriptions, columns, etc.) for a dataset.
DatasetMetadata
A DatasetMetadata object.

dataset_result()

Async method to retrieve the dataset result given parameter selections. Unlike the dataset method of DashboardArgs, this method returns a DatasetResult object (which includes metadata) instead of a polars DataFrame. Furthermore, while the DashboardArgs method automatically borrows selections applied to the dashboard, this method requires selections to be explicitly provided through code.
DatasetResult
A DatasetResult object.

dashboard()

Async method to retrieve a dashboard given parameter selections.
PngDashboard | HtmlDashboard
A PngDashboard or HtmlDashboard object based on dashboard_type.

query_models()

Async method to query the data models with SQL given parameter selections.
DatasetResult
A DatasetResult object.

get_compiled_model_query()

Async method to compile a specific data model and return its language and compiled definition.
CompiledQueryModel
A CompiledQueryModel object with language, definition, and placeholders.

get_fastapi_components()

Get the FastAPI components for the Squirrels project including mount path, lifespan, and FastAPI app.
FastAPIComponents
A FastAPIComponents object with properties:
  • mount_path (str): The mount path for the Squirrels project.
  • lifespan (AsyncGeneratorContextManager): The lifespan context manager for the Squirrels project.
  • fastapi_app (FastAPI): The FastAPI app for the Squirrels project.

close()

Use this method to deliberately close any database connections opened by the SquirrelsProject object. The database connections may still be opened again by other methods invoked on the SquirrelsProject object after this method is called.
None
No return value.

Examples

Here are some common usage patterns for the SquirrelsProject class. It is assumed that the code is running in an async context (e.g. inside an async function or a Jupyter Notebook cell).

Basic project initialization

Compiling and building models

Querying a dataset

Working with authentication

Working with dashboards

Render a PNG dashboard in a Jupyter Notebook:
Render an HTML dashboard in a Jupyter Notebook:

Querying models directly

Working with seeds

Exploring project metadata

Close database connections