Skip to main content

Schema Scraper

PyPI version Python 3.10+ License: MIT

A Python CLI tool that connects to databases, extracts comprehensive schema metadata, and generates organized markdown documentation suitable for AI consumption and version control.

Supported Databases

Database Driver Installation
MS SQL Server pyodbc pip install schema-scraper[mssql]
PostgreSQL psycopg3 pip install schema-scraper[postgresql]
MySQL/MariaDB mysql-connector-python pip install schema-scraper[mysql]
Oracle oracledb pip install schema-scraper[oracle]
SQLite built-in sqlite3 pip install schema-scraper

Installation

# Base installation (SQLite only)
pip install schema-scraper

# With specific database support
pip install schema-scraper[mssql]
pip install schema-scraper[postgresql]
pip install schema-scraper[mysql]
pip install schema-scraper[oracle]

# With all database support
pip install schema-scraper[all]

# Development installation
pip install -e ".[all,dev]"

Driver Requirements

MS SQL Server:

# macOS
brew install microsoft/mssql-release/msodbcsql18

# Ubuntu/Debian
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18

# Windows
# Download from: https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server

Oracle:

# Oracle Instant Client may be required for some features
# See: https://www.oracle.com/database/technologies/instant-client.html

Quick Start

# SQLite (no extra dependencies)
schema-scraper scrape -t sqlite -d ./mydb.sqlite

# PostgreSQL
schema-scraper scrape -t postgresql -h localhost -d mydb -u postgres -p password

# MS SQL Server with Windows auth
schema-scraper scrape -t mssql -h localhost -d MyDatabase --trusted

# MySQL
schema-scraper scrape -t mysql -h localhost -d mydb -u root -p password

Output will be generated in ./schema_docs/{database_name}/.

Usage

CLI Options

Usage: schema-scraper scrape [OPTIONS]

Options:
  -t, --db-type [mssql|postgresql|mysql|oracle|sqlite]
                                  Database type (default: mssql)
  -h, --host TEXT                 Database server hostname
  -P, --port INTEGER              Database server port
  -d, --database TEXT             Database name (or file path for SQLite)
  -u, --username TEXT             Database username
  -p, --password TEXT             Database password
  --trusted                       Use Windows authentication (MSSQL only)
  -c, --connection-string TEXT    Full connection string (MSSQL only)
  --driver TEXT                   ODBC driver name (MSSQL only)
  --service-name TEXT             Oracle service name
  --sid TEXT                      Oracle SID
  -o, --output PATH               Output base directory (default: ./schema_docs)
  --schemas TEXT                  Include only specific schemas (repeatable)
  --exclude-schemas TEXT          Exclude specific schemas (repeatable)
  --object-types [tables|views|procedures|functions|triggers|types|sequences|synonyms|all]
                                  Object types to extract (default: all)
  -v, --verbose                   Increase verbosity (-v info, -vv debug)
  --dry-run                       Preview without writing files
  --help                          Show this message and exit.

Environment Variables

Connection parameters can be set via environment variables:

Variable Description
DB_HOST Database host
DB_PORT Database port
DB_NAME Database name
DB_USER Username
DB_PASSWORD Password
DB_CONNECTION_STRING Full connection string (MSSQL)

Additional Commands

# List available database drivers
schema-scraper drivers

# Test database connection
schema-scraper test-connection -t postgresql -h localhost -d mydb -u user -p pass

Output Structure

schema_docs/{database_name}/
├── README.md                        # Database overview + navigation
├── tables/
│   ├── README.md                    # Table index
│   └── {schema}.{table}.md          # Per-table documentation
├── views/
│   ├── README.md
│   └── {schema}.{view}.md
├── procedures/
│   ├── README.md
│   └── {schema}.{procedure}.md
├── functions/
│   ├── README.md
│   └── {schema}.{function}.md
├── triggers/
│   ├── README.md
│   └── {schema}.{trigger}.md
├── types/
│   ├── README.md
│   └── {schema}.{type}.md
├── sequences/
│   ├── README.md
│   └── {schema}.{sequence}.md
├── synonyms/
│   ├── README.md
│   └── {schema}.{synonym}.md
└── schemas/
    ├── README.md
    └── {schema}.md                  # All objects per schema

What Gets Documented

Tables

  • Full column list with data types, nullability, defaults, identity, computed columns
  • Primary key (name, columns, clustered/non-clustered)
  • Foreign keys (columns, referenced table, ON DELETE/UPDATE actions)
  • All indexes (type, columns, included columns, filters)
  • Check constraints with full definitions
  • Row count and space usage statistics
  • Relationship graph (what references this table, what it references)

Views

  • Column list with data types
  • Full SQL definition
  • Base tables referenced
  • Materialized view indicator (PostgreSQL)

Stored Procedures

  • All parameters with types, direction (IN/OUT), defaults
  • Full SQL definition
  • Language (T-SQL, PL/SQL, PL/pgSQL, etc.)

Functions

  • Function type (scalar, table-valued, aggregate, window)
  • Parameters with types and defaults
  • Return type (scalar) or return columns (table-valued)
  • Full SQL definition

Triggers

  • Trigger type (BEFORE/AFTER/INSTEAD OF)
  • Events (INSERT, UPDATE, DELETE)
  • Parent table
  • Full SQL definition
  • Disabled status

User-Defined Types

  • Type category (domain, composite, enum, table type, alias)
  • Base type and constraints
  • Column definitions (for composite/table types)
  • Enum values (PostgreSQL)

Sequences

  • Data type and range (min/max values)
  • Increment, start value, current value
  • Cycling behavior
  • Cache settings

Synonyms

  • Base object reference
  • Target server/database/schema/object

Database Feature Support

Feature MSSQL PostgreSQL MySQL Oracle SQLite
Tables
Views
Materialized Views
Stored Procedures
Functions
Triggers
User-Defined Types
Sequences
Synonyms

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Install development dependencies (pip install -e ".[all,dev]")
  4. Make your changes
  5. Run tests (pytest) and security checks (pip-audit)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Changelog

See CHANGELOG.md for a list of changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Download files

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

Source Distribution

schema_scraper-0.3.1.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

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

schema_scraper-0.3.1-py3-none-any.whl (67.5 kB view details)

Uploaded Python 3

File details

Details for the file schema_scraper-0.3.1.tar.gz.

File metadata

  • Download URL: schema_scraper-0.3.1.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for schema_scraper-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e9282729f937b293179d205751a87faf4481651d7c46986e88f7faddc628b5cc
MD5 cf07b4915a3c19d678b258af9debc82e
BLAKE2b-256 8b2c8f159e3901b3e51d57a8dfd1fe05920ef766df1b6734d2497013777d0e57

See more details on using hashes here.

File details

Details for the file schema_scraper-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: schema_scraper-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 67.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for schema_scraper-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f1fcf1f22ece9f399ce76fad6659919741c549cbf58be174a43901f0e264f72
MD5 d53c6d6af29ad810bff44e65f0accf4e
BLAKE2b-256 2e54c013760f85c24ac38d5feac4f09342ffd5bb75991aab25666f22e6996b5b

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 Sentry Error logging StatusPage Status page