Git Product home page Git Product logo

metabase_export_import's Introduction

Metabase Export/Import

This python library allows to export and import a community version instance of Metabase

Example scripts

Two scripts are provided to import and export fields, cards and dashboards of a specific database configuration of metabase :

python3 metabase_export.py http://localhost:3000/api/ my_user my_password my_database export_folder

The script produces 3 files for each exported elements (the name of the database is user as prefix) : my_database_fields_exported.csv, my_database_cards_exported.json and my_database_dashboard_exported.json

python3 metabase_import.py http://localhost:3000/api/ my_user my_password my_database import_folder

The script imports from 3 files, one for each elements : my_database_fields_forimport.csv, my_database_cards_forimport.json and my_database_dashboard_forimport.json

Library calls

database creation/deletion

import metabase

#connect to metabase
ametabase = metabase.MetabaseApi("http://localhost:3000/api/", "metabase_username", "metabase_password")

#add a sqlite database located at /path/to/database.sqlite. The metabase associated name is my_database
ametabase.create_database("my_database", 'sqlite', {"db":"/path/to/database.sqlite"})

#ametabase.delete_database('my_database')

users and permisssions

ametabase.create_user("[email protected]", "the_password", {'first_name': 'John', 'last_name': 'Doe'})

#Add a group and associate it with our new user
ametabase.membership_add('[email protected]', 'a_group')

#allow read data and create interraction with my_database for users members of our new group (a_group)
ametabase.permission_set_database('a_group', 'my_database', True, True)

collections and permissions

#create a collection and its sub collection
ametabase.create_collection('sub_collection', 'main_collection')

#allow write right on the new collections to the membres of a_group
ametabase.permission_set_collection('main_collection', 'a_group', 'write')
ametabase.permission_set_collection('sub_collection', 'a_group', 'write')

schema

#export and import the schema of fields
ametabase.export_fields_to_csv('my_database', 'my_database_fields.csv')
ametabase.import_fields_from_csv('my_database', 'my_database_fields.csv')

cards and dashboards

ametabase.export_cards_to_json('my_database', 'my_database_cards.json')
ametabase.export_dashboards_to_json('my_database', 'my_database_dashboard.json')

ametabase.import_cards_from_json('my_database', 'my_database_cards.json')
ametabase.import_dashboards_from_json('my_database', 'my_database_dashboard.json')

metabase_export_import's People

Contributors

teymour avatar wincelau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

znatali yuvigold

metabase_export_import's Issues

Error metabase_import

hi,

When importing the export into another metabase I am getting the following error. Can you help?

C:\_dev\metabase_export_import>python metabase_import.py http://192.168.1.152:3002/api/ [email protected] xxxxx123 Nuno c:\temp\1 Traceback (most recent call last): File "C:\_dev\metabase_export_import\metabase_import.py", line 15, in <module> ametabase.import_cards_from_json(metabase_base, metabase_exportdir) File "C:\_dev\metabase_export_import\metabase.py", line 715, in import_cards_from_json res.append(self.card_import(database_name, self.convert_names2ids(database_name, collection_name, card))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\_dev\metabase_export_import\metabase.py", line 483, in convert_names2ids [new_k, value] = self.convert_pcnames2id(database_name, collection_name, k, obj[k]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\_dev\metabase_export_import\metabase.py", line 436, in convert_pcnames2id return [new_k, self.collection_name2id_or_create_it(collection_name)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\_dev\metabase_export_import\metabase.py", line 403, in collection_name2id_or_create_it self.create_collection(collection_name) File "C:\_dev\metabase_export_import\metabase.py", line 421, in create_collection return self.query('POST', 'collection', param) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\_dev\metabase_export_import\metabase.py", line 74, in query raise ConnectionError(query_response) ConnectionError: {'errors': {'name': 'value must be a non-blank string.'}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.