Skip to main content

Outil d'inspection et d'analyse de bases de donnรฉes

Project description

๐Ÿ—‚๏ธ DB Inspector

A powerful and flexible tool to inspect and analyze any SQLAlchemy-compatible database.
Visualize your table structures, browse data, analyze relationships, and manage your database schema directly from the command line.


โœจ Features

  • ๐Ÿ” Complete Inspection : Analyze the structure of all your tables
  • ๐Ÿ“Š Data Visualization : Browse the content of your tables
  • ๐Ÿ”— Relationships : Discover foreign keys and relationships between tables
  • ๐Ÿ—‘๏ธ Management : Delete tables if needed (with confirmation)
  • ๐ŸŽฏ Multi-database : Support for PostgreSQL, MySQL, SQLite and all SQLAlchemy-compatible databases
  • โš™๏ธ Flexible Configuration : Full URL or separate variables
  • ๐ŸŽจ Colorful Output : Enhanced readability with color-coded information (table names, types, keys, errors, warnings)

๐Ÿ“‹ Prerequisites

  • Python 3.8 or higher
  • Access to a database (PostgreSQL, MySQL, SQLite, etc.)

๐Ÿš€ Installation

Installation from PyPI

pip install dbinpect

This will install the analyze-db command in your environment.

Installation from Source

Clone the project and install dependencies:

git clone https://github.com/AshBrud/dbinpect.git
cd dbinpect
pip install -r requirements.txt

Development Installation

To install the package in development mode (useful if you modify the code):

pip install -e .

This will also install the analyze-db command in your environment.

Installation from GitHub

pip install git+https://github.com/AshBrud/dbinpect.git

โš™๏ธ Configuration

The project offers three methods to configure the database connection, with a clear priority order:

Priority order : CLI Arguments > Environment Variables > .env File > Default

Method 1: CLI Arguments (Highest Priority) โญ

Configure directly from the command line:

# With full URL
analyze-db --database-url "postgresql://user:password@localhost:5432/mydb" --all

# With separate variables
analyze-db --db-host localhost --db-port 5432 --db-user user --db-password pass --db-name mydb --all

# Mixed: partial override
analyze-db --db-password "new_password" --all

Available arguments :

  • --database-url, --db-url, -u : Full database URL
  • --db-type : Database type (postgresql, mysql, sqlite, etc.)
  • --db-host : Database host
  • --db-port : Database port
  • --db-user : Username
  • --db-password : Password
  • --db-name : Database name

Method 2: Environment Variables

Set variables in your shell before executing the command:

# Linux/Mac/Windows Git Bash
DATABASE_URL="postgresql://user:password@localhost:5432/mydb" analyze-db --all

# Or export for the session
export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
analyze-db --all

# Separate variables
DB_HOST=localhost DB_USER=user DB_NAME=mydb analyze-db --all

Windows PowerShell :

$env:DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
analyze-db --all

Windows CMD :

set DATABASE_URL=postgresql://user:password@localhost:5432/mydb
analyze-db --all

Method 3: .env File (For Local Development)

Create a .env file at the project root:

# Option 1: Full URL
DATABASE_URL=postgresql://user:password@localhost:5432/mydb

# Option 2: Separate variables
DB_TYPE=postgresql
DB_HOST=localhost
DB_PORT=5432
DB_USER=user
DB_PASSWORD=password
DB_NAME=mydb

Create the file :

# Linux/Mac
cp env.example .env

# Windows
copy env.example .env

Then edit the .env file with your connection information.

Supported Database Types

  • PostgreSQL : postgresql://user:pass@host:port/db
  • MySQL : mysql://user:pass@host:port/db
  • SQLite : sqlite:///path/to/database.db
  • Others : All databases supported by SQLAlchemy

Configuration Examples

# PostgreSQL via CLI
analyze-db --database-url "postgresql://postgres:mypass@localhost:5432/testdb" --all

# MySQL via environment variables
DATABASE_URL="mysql://root:password@localhost:3306/mydb" analyze-db --table users

# SQLite via CLI
analyze-db --database-url "sqlite:///./database.db" --all

# Partial override: .env contains DB_HOST, DB_USER, DB_NAME, override only password
analyze-db --db-password "new_password" --all

๐Ÿ’ก Note : If DATABASE_URL is defined (via CLI, env or .env), it takes priority over separate variables.


๐Ÿ“– Usage

Once installed, you can use the analyze-db command:

analyze-db --help

Available Options

Inspection Options

Option Description
--all, -a Display details of all tables
--table <name>, -t <name> Display the schema of a specific table
--data [n], -d [n] Display the first rows of data (default 10)
--drop <name> Delete a specific table โš ๏ธ irreversible

Configuration Options (see Configuration section)

Option Description
--database-url, --db-url, -u Full database URL
--db-host Database host
--db-port Database port
--db-user Username
--db-password Password
--db-name Database name
--db-type Database type (postgresql, mysql, sqlite, etc.)

Usage Examples

List all tables

analyze-db

Displays the list of all tables with the number of rows.

Display details of all tables

analyze-db --all

Displays the complete schema (columns, types, primary keys, foreign keys) of all tables.

Inspect a specific table

analyze-db --table users

Displays the detailed schema of the users table:

  • Columns with their types
  • Primary keys
  • Foreign keys
  • Number of rows

Browse table data

# Display the first 10 rows (default)
analyze-db --table users --data

# Display the first 20 rows
analyze-db --table users --data 20

Delete a table

analyze-db --drop old_table

โš ๏ธ Warning : This action is irreversible. A confirmation will be requested before deletion.


๐ŸŽจ Color-Coded Output

DB Inspector uses colors to make the output more readable and easier to analyze:

Color Scheme

  • Cyan Bright : Table names, titles, and important identifiers
  • Bold : Section headers, column names, and emphasis
  • Blue : Data types (INTEGER, VARCHAR, TEXT, etc.)
  • Yellow : Primary keys [PK]
  • Red : NOT NULL constraints and error messages
  • Green : Referenced tables in foreign keys and success messages
  • Gray (Dim) : Secondary information (row counts, separators, hints)
  • Yellow Bright : Warnings and important alerts

Examples

  • Table schemas : Column names in bold, types in blue, constraints in red/yellow
  • Foreign keys : Referenced tables in green with gray arrows
  • Messages : Success (green), errors (red), warnings (yellow), info (cyan)
  • Help command : Color-coded options and descriptions

๐Ÿ’ก Note : Colors are automatically handled by Colorama for cross-platform compatibility. If your terminal doesn't support colors, the output will still be readable without them.


๐Ÿ› ๏ธ Development

Project Structure

dbinpect/
โ”‚
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ””โ”€โ”€ config.py          # Configuration with Pydantic Settings
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ colors.py           # Color formatting utilities
โ”‚
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ db_inspector.py        # Main script
โ”‚
โ”œโ”€โ”€ .env.example               # Configuration example
โ”œโ”€โ”€ requirements.txt           # Python dependencies
โ”œโ”€โ”€ pyproject.toml             # Modern package configuration
โ””โ”€โ”€ README.md                  # This file

Technologies Used

  • SQLAlchemy : ORM and database connection management
  • Pydantic : Data validation and configuration management
  • Python-dotenv : Environment variable loading
  • Colorama : Cross-platform colored terminal output (Windows/Linux/Mac)

Development Dependencies Installation

pip install -r requirements.txt

๐Ÿ› Troubleshooting

Error: "DATABASE_URL is not configured"

Solution : Check that your .env file exists and contains DATABASE_URL or the variables DB_HOST, DB_USER, DB_NAME.

Error: "Unable to connect to database"

Solutions :

  1. Check that your database is accessible
  2. Verify credentials in your .env file
  3. Check that the database service is running
  4. For PostgreSQL, verify that port 5432 is open

Command analyze-db not found

Solution : Reinstall the package in development mode:

pip install -e .

๐Ÿค Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a branch for your feature (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m 'Add a new feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

Future Improvements

Future improvements and features are planned. Check the GitHub repository for updates.


๐Ÿ“œ License

This project is licensed under the MIT License. You are free to use, modify, and share it.

See the LICENSE file for more details.


๐Ÿ™ Acknowledgments

  • SQLAlchemy for the excellent ORM
  • Pydantic for data validation
  • All contributors who improve this project

๐Ÿ“ž Support

To report a bug or suggest a feature, open an issue on GitHub.


Made with โค๏ธ for the Python community

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

dbinpect-0.2.1.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

dbinpect-0.2.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file dbinpect-0.2.1.tar.gz.

File metadata

  • Download URL: dbinpect-0.2.1.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbinpect-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cdb0d4eb578ae4551891715ecd7e43f3963ba45e2c2c6cfab4001c87c44fa6a6
MD5 b3b219d9cba11e3991b49a0ae0c1e4a9
BLAKE2b-256 86909610f26adcb96f09e5c3496ba13778c7fa256b8579b709091c402e43e626

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbinpect-0.2.1.tar.gz:

Publisher: publish.yml on AshBrud/dbinpect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbinpect-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dbinpect-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbinpect-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcb9d3898dfb6455317bd73bff33f5b9bdac35538d1dd17ca4fecc94b3bb94d9
MD5 c3e0760b052e15d7e870648e6cdcdc89
BLAKE2b-256 ebef185a0f916c952bc8a882d8d2d330a5972d700c01d4202f4983e1bd3774d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbinpect-0.2.1-py3-none-any.whl:

Publisher: publish.yml on AshBrud/dbinpect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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