Model Providers Reference

See also

Model Reference

Loading Model Metadata

cubes.read_model_metadata(source)

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.

cubes.read_model_metadata_bundle(path)

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.

Model Providers

cubes.create_model_provider(name, metadata)

Gets a new instance of a model provider with name name.

class cubes.ModelProvider(metadata=None)

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

Instance variable store might be populated after the initialization. If the model provider requires an open store, it should advertise it through True value returned by provider’s requires_store() method. Otherwise no store is opened for the model provider. store_name is also set.

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()

cube(name)

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

Returned cube has no dimensions assigned. You should assign the dimensions according to the cubes linked_dimensions list of dimension names.

Subclassees should implement this method.

cube_metadata(name)

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

cube_options(cube_name)

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.

default_metadata(metadata=None)

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, dimensions=[])

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.

Subclassees should implement this method.

dimension_metadata(name)

Returns a metadata dictionary for dimension name.

initialize_from_store()

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

list_cubes()

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.

public_dimensions()

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.

requires_store()

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

set_store(store, store_name)

Set’s the provider’s store and store_name. The store can be used to retrieve model’s metadata. The store name is a handle that can be passed to the Cube objects for workspace to know where to find cube’s data.

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

Creates a cube name in context of workspace from provider’s metadata. The created cube has no dimensions attached. You sohuld link the dimensions afterwards according to the linked_dimensions property of the cube.

dimension(name, dimensions=None)

Create a dimension name from provider’s metadata within context (usualy a Workspace object).

list_cubes()

Returns a list of cubes from the metadata.

Table Of Contents

Previous topic

Model Reference

Next topic

Aggregation Browser Reference

This Page