Skip to main content

Export DB schema as JSON (types & relations) generating DDL and ER Diagrams.

Project description

DB Schema Extractor

A robust, modular Python tool to extract database schema metadata (tables, columns, relationships, indexes) into a structured JSON format. It supports multiple dialects and standard connection strings.

Features

  • Multi-Dialect Support: SQLite, PostgreSQL, MySQL, MSSQL.
  • Comprehensive Metadata: Extracts tables, columns, primary keys, foreign keys (including ON DELETE/ON UPDATE rules), indexes, and unique constraints.
  • Modular Architecture: Easy to extend with new providers.
  • Dual Usage: Use as a Command Line Interface (CLI) or import as a Python library.

Installation

Ensure you have Python installed. Install the required dependencies using the provided requirements file:

pip install -r requirements.txt

This installs sqlalchemy and drivers for PostgreSQL, MySQL, and MSSQL. SQLite support is built-in.

Usage

1. Command Line Interface (CLI)

Run the tool locally providing the database URL.

# Basic usage
python -m dbcatalog.main --url "postgresql://user:pass@localhost:5432/mydb"

# Pretty print output to a file
python -m dbcatalog.main --url "sqlite:///chinook.db" --out schema.json --pretty

# Include indexes in the export
python -m dbcatalog.main --url "mysql://user:pass@localhost/db" --include-indexes

2. Python Library

You can integrate the extractor into your own Python scripts.

from dbcatalog import DBDriver

# Initialize driver
driver = DBDriver("postgresql://user:pass@localhost:5432/mydb")

# Option 1: Full Schema Export
schema_json = driver.get_db_schema(include_indexes=True)
print(schema_json)

# Option 2: Granular Access
schemas = driver.get_schemas()
for schema in schemas:
    tables = driver.get_tables(schema)
    for table in tables:
        columns = driver.get_columns(schema, table)
        relations = driver.get_relations(schema, table)
        print(f"Table: {table}, Columns: {len(columns)}, Relations: {len(relations)}")

Supported Output

The tool exports a JSON object containing:

  • Database name & engine
  • List of Schemas
  • For each Table:
    • Columns (name, type, nullable, default)
    • Primary Keys
    • Foreign Keys (referenced table/cols, on_delete/on_update actions)
    • Indexes (unique/non-unique)
    • Unique Constraints

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

dbcatalog-0.1.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

dbcatalog-0.1.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file dbcatalog-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for dbcatalog-0.1.1.tar.gz
Algorithm Hash digest
SHA256 77f8093aa8f753ebc527407cb973176d4826bfb2e8ac7f762bd254b281c50ab5
MD5 782b4edf5c12f9141556156b3e13ea50
BLAKE2b-256 3b0499fd5ad313c014a4b439e6920128fdf621c6fac5c531649fa5a1f5748672

See more details on using hashes here.

File details

Details for the file dbcatalog-0.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dbcatalog-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e0a2a69a5c5d68504f0c35ca6334927b732063c110e1dcdd8dd723dedba28ca
MD5 efb1ed45be4a90987f69f32b6ae65b11
BLAKE2b-256 a1143145af37f9815558f474c9432e7ab3f09fd6eba90accf0c3c60b494914d3

See more details on using hashes here.

Supported by

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