Model Providers Reference

See also

Model Reference

Model Providers

class cubes.ModelProvider(metadata=None)

Base class for model providers. Initializes a model provider and sets metadata – a model metadata dictionary.

Subclasses should call this method at the beginning of the custom __init__().

If a model provider subclass has a metadata that should be pre-pended to the user-provided metadta, it should return it in default_metadata().

Subclasses should implement at least: cubes.ModelProvider.cube(), cubes.ModelProvider.dimension() and cubes.ModelProvider.list_cubes() methods.


Set’s the provider’s store.

cube(name, locale=None)

Returns a cube with name provided by the receiver. If receiver does not have the cube NoSuchCube exception is raised.

Note: The returned cube will not have the dimensions assigned. It is up to the caller’s responsibility to assign appropriate dimensions based on the cube’s dimension_links.

Subclasses of ModelProvider might override this method if they would like to create the Cube object directly.

cube_metadata(name, locale=None)

Returns a cube metadata by combining model’s global metadata and cube’s metadata. Merged metadata dictionaries: browser_options, mappings, joins.

Subclasses should override this method and call the super if they would like to merge metadata provided in a model file.


Returns an options dictionary for cube name. The options dictoinary is merged model options metadata with cube’s options metadata if exists. Cube overrides model’s global (default) options.


Returns metadata that are prepended to the provided model metadata. metadata is user-provided metadata and might be used to decide what kind of default metadata are returned.

The metadata are merged as follows:

  • cube lists are concatenated (no duplicity checking)
  • dimension lists are concatenated (no duplicity checking)
  • joins are concatenated
  • default mappings are updated with the model’s mappings

Default implementation returns empty metadata.

dimension(name, templates=, []locale=None)

Returns a dimension with name provided by the receiver. dimensions is a dictionary of dimension objects where the receiver can look for templates. If the dimension requires a template and the template is missing, the subclasses should raise TemplateRequired(template) error with a template name as an argument.

If the receiver does not provide the dimension NoSuchDimension exception is raised.

dimension_metadata(name, locale=None)

Returns a metadata dictionary for dimension name and optional locale.

Subclasses should override this method and call the super if they would like to merge metadata provided in a model file.


This method is called after the provider’s store was set. Override this method if you would like to perform post-initialization from the store.


Get a list of metadata for cubes in the workspace. Result is a list of dictionaries with keys: name, label, category, info.

The list is fetched from the model providers on the call of this method.

Subclassees should implement this method.


Returns a list of public dimension names. Default implementation returs all dimensions defined in the model metadata. If public_dimensions model property is set, then this list is used.

Subclasses might override this method for alternative behavior. For example, if the backend uses dimension metadata from the model, but does not publish any dimension it can return an empty list.


Return True if the provider requires a store. Subclasses might override this method. Default implementation returns False

class cubes.StaticModelProvider(*args, **kwargs)

Returns a list of cubes from the metadata.

Model Metadata


Reads a model description from source which can be a filename, URL, file-like object or a path to a directory. Returns a model description dictionary.


Load logical model a directory specified by path. Returns a model description dictionary. Model directory bundle has structure:

  • model.cubesmodel/
    • model.json
    • dim_*.json
    • cube_*.json

The dimensions and cubes lists in the model.json are concatenated with dimensions and cubes from the separate files.

cubes.write_model_metadata_bundle(path, metadata, replace=False)

Writes a model metadata bundle into new directory target from metadata. Directory should not exist.


Expands metadata to be as complete as possible cube metadata. metadata should be a dictionary.

Expands links to dimensions. metadata should be a list of strings or dictionaries (might be mixed). Returns a list of dictionaries with at least one key name. Other keys are: hierarchies, default_hierarchy_name, nonadditive, cardinality, template

cubes.expand_dimension_metadata(metadata, expand_levels=False)

Expands metadata to be as complete as possible dimension metadata. If expand_levels is True then levels metadata are expanded as well.


Returns a level description as a dictionary. If provided as string, then it is going to be used as level name and as its only attribute. If a dictionary is provided and has no attributes, then level will contain only attribute with the same name as the level name.


Fixes metadata of an attribute. If metadata is a string it will be converted into a dictionary with key “name” set to the string value.