cube_dbt package
cube_dbt package simplifies defining the data model in the semantic layer
on top of dbt models. It provides convenient tools for
loading the metadata of a dbt project, inspecting dbt models, and rendering
them as cubes in YAML.
- Install
cube_dbtpackage from PyPI - Check the source code in
cube_dbton GitHub - Submit issues to
cubeon GitHub
Installation
Cube Cloud
Add thecube_dbt package to the requirements.txt file in the root
directory of your Cube project. Cube Cloud will install the dependencies
automatically.
Reference
Dbt class
Encapsulates tools for working with the metadata of a dbt project.
Dbt.__init__
The constructor accepts the metadata of a dbt project as a dict with the
contents of a manifest.json file.
Dbt.from_file and Dbt.from_url aren’t applicable,
e.g., when manifest.json is loaded from a private AWS S3 bucket.
Dbt.from_file
This static method loads the metadata of a dbt project from a manifest.json
file by its path and returns an instance of the Dbt class.
Dbt.from_url
This static method loads the metadata of a dbt project from a manifest.json
file by its URL and returns an instance of the Dbt class.
Dbt.filter
This method filters loaded dbt models by their path prefixes, tags, or names.
paths should not be prefixed with models/.
Dbt.models
This property exposes a list of loaded dbt models as instances of the
Model class.
Dbt.filter rules and are not
materialized as ephemeral will be returned.
Dbt.model
This method returns a loaded dbt model by its name as an instance of the
Model class.
Dbt.filter rules and are not
materialized as ephemeral will be returned.
Model class
Encapsulates tools for working with the metadata of a dbt model.
Model.name
This property exposes the name of a dbt model.
Model.description
This property exposes the description of a dbt model.
Model.sql_table
This property exposes the fully-qualified SQL relation name of a dbt model
that can be used as the sql_table parameter of a cube.
Model.columns
This property exposes a list of columns that belong to this dbt model as
instances of the Column class.
Model.column
This method exposes a column that belongs to this dbt model by its name as
an instance of the Column class.
Model.primary_key
This method returns the primary key column, if this dbt model has any, as an
instance of the Column class. Returns None if there’s no primary key in
this dbt model.
Column.primary_key for details on the detection of
primary key columns.
Model.as_cube
This method renders this dbt model as a YAML snippet that can be inserted
into YAML data models. Includes name, description (if present), and
sql_table.
Model.as_dimensions
This method renders the list of columns that belong to this dbt model as
a YAML snippet that can be inserted into YAML data models.
Optionally, accepts a list of column names that should be ignored in skip.
Column.as_dimension for details on the
dimension rendering.
In the returned multiline string, all lines except for the first one are
left-padded with 6 spaces for easier use in YAML data models:
Column class
Encapsulates tools for working with the metadata of a column that belongs
to a dbt model.
Column.name
This property exposes the name of a column.
Column.description
This property exposes the description of a column.
Column.sql
This property exposes the name of a column that can be used as the
sql parameter of a dimension.
Column.type
This property exposes the data type of a column that can be used as the
type parameter of a dimension.
cube_dbt package applies a set of heuristics to map database-specific
types to dimension types. You can check the source
code
for implementation details.
If a column type is not defined in the metadata of a dbt project, string
is used by default.
Column.meta
This property exposes the meta data of a column as a dict that can be
used as the meta parameter of a dimension.
Column.primary_key
This property exposes a bool value that indicates if a column is
a primary key or not.
primary_key tag in the metadata of a dbt project.
Column.as_dimension
This method renders this column as a YAML snippet that can be inserted
into YAML data models. Includes name, description (if present), sql,
type, primary_key (if True), and meta (if present).