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_URLis 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 NULLconstraints 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 :
- Check that your database is accessible
- Verify credentials in your
.envfile - Check that the database service is running
- 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:
- Fork the repository
- Create a branch for your feature (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'Add a new feature') - Push to the branch (
git push origin feature/my-feature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdb0d4eb578ae4551891715ecd7e43f3963ba45e2c2c6cfab4001c87c44fa6a6
|
|
| MD5 |
b3b219d9cba11e3991b49a0ae0c1e4a9
|
|
| BLAKE2b-256 |
86909610f26adcb96f09e5c3496ba13778c7fa256b8579b709091c402e43e626
|
Provenance
The following attestation bundles were made for dbinpect-0.2.1.tar.gz:
Publisher:
publish.yml on AshBrud/dbinpect
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbinpect-0.2.1.tar.gz -
Subject digest:
cdb0d4eb578ae4551891715ecd7e43f3963ba45e2c2c6cfab4001c87c44fa6a6 - Sigstore transparency entry: 708750875
- Sigstore integration time:
-
Permalink:
AshBrud/dbinpect@50d795035f1e2cbd7da732b9be1f0a445e9ac956 -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/AshBrud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50d795035f1e2cbd7da732b9be1f0a445e9ac956 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcb9d3898dfb6455317bd73bff33f5b9bdac35538d1dd17ca4fecc94b3bb94d9
|
|
| MD5 |
c3e0760b052e15d7e870648e6cdcdc89
|
|
| BLAKE2b-256 |
ebef185a0f916c952bc8a882d8d2d330a5972d700c01d4202f4983e1bd3774d4
|
Provenance
The following attestation bundles were made for dbinpect-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on AshBrud/dbinpect
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbinpect-0.2.1-py3-none-any.whl -
Subject digest:
bcb9d3898dfb6455317bd73bff33f5b9bdac35538d1dd17ca4fecc94b3bb94d9 - Sigstore transparency entry: 708750898
- Sigstore integration time:
-
Permalink:
AshBrud/dbinpect@50d795035f1e2cbd7da732b9be1f0a445e9ac956 -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/AshBrud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50d795035f1e2cbd7da732b9be1f0a445e9ac956 -
Trigger Event:
release
-
Statement type: