Skip to main content

Configuring Metabase from Python

Project description

Mara Metabase

Build Status PyPI - License PyPI version Slack Status

Automating the setup and configuration of Metabase instances. Comes with

  • Functions for adding users, databases & settings

  • Syncing of field descriptions and metrics defined with Mara Schema to Metabase

  • Syncing of users and permissions to Metabase

  • A Makefile for running Metabase locally



To use the library directly, use pip:

pip install mara-metabase


pip install -e git+

For an example of an integration into a flask application, have a look at the mara example project 1.


Running Metabase

From within a project, include [] in your project Makefile (as for example in

Running make setup-metabase will download a Metabase jar file, run database migrations, add an admin user & create a database connection to the data warehouse. Then, running make run-metabase will start Metabase on port 3000:


You can log in with the default username and the password 123abc (configurable via mara_metabase/, please change in production).

For running Metabase in production, please have a look at



Programatically setting up Metabase

The file mara_metabase/ contains functions for configuring a Metabase instance by directly writing to its metadata database (rather than manually configuring an instance through the UI). These functions are particularly useful when multiple Metabase instances are maintained (e.g. one for each testing / staging environment).

There is a flask cli command for running the setup function: flask mara_metabase.setup.

Danger: this will remove any other configured database connections from metabase!


Metadata sync

If you have a data warehouse schema defined in Mara Schema, then you can automatically sync field descriptions and metric definitions with the update_metadata function in mara_metabase/

Here's an example of an automatically synced definition for the metric average order value:

Metabae metadata sync

This function assumes that all reporting tables were created using the sql-generation features of Mara Schema.

The schema sync can be triggered manually with flask mara_metabase.update-metadata.

Have a look at for how to integrate schema sync into a data pipeline.


Syncing of users, groups & permissions from Mara ACL

Once you add the Metabase ACL resource in mara_metabase/ to your project, you can easily control which users can query which data set:

Metabase ACL

The sync must be explicitly enabled in your setup code to not interfere with a metabase instance which has its own user management:

# e.g. in app/ui/ 
import mara_metabase.acl

Danger: Enabling this feature will overwrite any existing users, groups & permissions in Metabase

After enabling, all users in Mara ACL will be synced to Metabase together with their respective groups on "Save" of the permissions. Permissions in Metabase can be given for all or for individual data sets.

In this example, users from the "Management" group can query all data sets, and users from "Marketing" only "Customers" and "Leads" (with the exception of Thomas who can also query "Order items" and "Sellers").

This is the same data in the Metabase admin UI:

Metabase permissions


The easiest way to try out Mara Metabase is to run the mara example project 1.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mara-metabase-2.0.1.tar.gz (12.4 kB view hashes)

Uploaded source

Built Distribution

mara_metabase-2.0.1-py3-none-any.whl (13.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page