Models
Models are the backbone of a vinyl project. Models are cleaned representations of your source data. Models can either be virtualized or backed by a table (common in data warehouses). Models can be published for use in the semantic layer or used internally for analysis. To create a model, import themodel decorator from vinyl and create function.
my_project/models.py
my_project/models.py
my_project/models.py
Use in Notebooks
Models can also be written and used outside of context of a Vinyl project (like in a jupyter notebook or a python script) using a context manager. We can write the model above as:my_script.py
Metrics
Timeseries data is an important component of many analytics projects. Vinyl comes with a powerful metrics abstraction to help aggregation and slice time series data without having to write long and complicated SQL. Let’s expand on our example above but now look at how sales for each store has changed over time. To use the metric layer of Vinyl, all we have to do is pass in theMetricStore object to our function and pass in the timestamp column to the metric method.
my_project/metrics.py
shop_sales can now be used throughout our Vinyl project. The Metrics layer allows for dynamic queries across dimensions and time buckets. Metrics also provide useful features like fill options and trailing windows.
If we want to get the sales across each shop location over the past trailing 3 months, we can query it like:
If we want to change the time grain to weeks and look at the last 2 weeks, it’s as easy as changing the metric select to:
We can wrap this metric as a model in our project:
Currently Vinyl does not support deploying metrics directly and they must be
wrapped as a model to be shared outside a vinyl project. This constraint will
be removed in future releases.

