Skip to main content

metabase-export

Export Metabase questions to .sql files that mirror your collection tree, so your SQL lives in git.

export METABASE_PG_PASSWORD='secret'
uvx metabase-export --output reports
reports/
  Occupancy/
    Rooms/TOTAL HOURS USED.sql
  Incidents/OPEN INCIDENTS.sql
-- Card: 129 | DB: Incidents | Viz: scalar
-- Collection: Incidents
-- Parameters: {{date}}

SELECT COUNT(*) FROM "Incident" WHERE {{date}}

Every run rewrites the output directory. A card deleted or archived in Metabase disappears from disk — it is a mirror, not a merge. Directories whose name starts with _ are never touched.

Usage

Needs read access to the Metabase application database (metabaseappdb), not to the databases Metabase reports against.

uvx metabase-export --output reports                      # everything
uvx metabase-export --output reports --root-collection 4  # one collection
uvx metabase-export --output reports --dry-run            # change nothing
uvx metabase-export --output reports --port 15433 --ssh-host prod-box

Collection id comes from its URL: /collection/4-my-reports4.

Option Default
--output DIR reports where to write the tree
--dry-run off list changes, write nothing
--root-collection ID all export only this collection and its children
--host --port --user --dbname 127.0.0.1 5432 postgres metabaseappdb connection
--ssh-host HOST tunnel --port through this host if it is closed
--remote-port PORT 5432 Postgres port on the far side

Each option has an env var (METABASE_EXPORT_DIR, METABASE_PG_HOST, …; see --help), so a project can pin its settings and run with no arguments. The password comes from METABASE_PG_PASSWORD or a prompt — never from a flag.

Notes

  • Only native (SQL) questions. Query-builder questions have no SQL and are skipped.
  • Reads MBQL5 (Metabase 50+) and the older native.query format.
  • Output is deterministic: two runs in a row leave the tree untouched.
  • Files keep {{parameter}} placeholders, so they are not runnable outside Metabase.

Development

uv sync && uv run pytest

MIT

Download files

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

Source Distribution

metabase_export-0.1.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metabase_export-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file metabase_export-0.1.0.tar.gz.

File metadata

  • Download URL: metabase_export-0.1.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for metabase_export-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a6ac832865f06b54f0d686eda843f4707d36b3800ea7fc0123f5d44fbac893a1
MD5 e22f9fd0a2a8caa5ebd80d30cafd7f08
BLAKE2b-256 4b7f48d5b2906cc8ff5b35d309c8576e805df1795a09c57b992f528708b67e39

See more details on using hashes here.

File details

Details for the file metabase_export-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: metabase_export-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for metabase_export-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8dc3c67183817587ed83d1b10bfd904651801132c2c65001aef31c37efb9d3e
MD5 5386801a92749d4ebf053750b2927ffe
BLAKE2b-256 154955371f2afe1c610b6dcd5ffd431dea83b6a8876f4ce17da17aad64f416b0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page