Registry / database / schemainspect

schemainspect

JSON →
library3.1.1663587362pypypiunverified

Schema Inspect is a Python library for programmatically inspecting database schemas, with a strong focus on PostgreSQL. It integrates with SQLAlchemy to provide a structured representation of tables, columns, constraints, and other schema objects. The current version is 3.1.1663587362, which uses a unique timestamp-based versioning scheme, reflecting its last significant update in late 2022.

pip install schemainspect
INSTALL
IMPORT
SIG · SCHEMAINSPECT
S
schemainspect
databasepythonv3.1.1663587362
Install
3.2s avg
Import
—
Disk
42MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.1.1663587362 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 43.5MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 3.2s · import 0.000s · 42MB
42MB installed
● package 42MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inspect
✓ from schemainspect import inspect
✗ from schemainspect import inspect

This quickstart demonstrates how to connect to a database using a DSN (Data Source Name) and use `schemainspect` to retrieve and print the names of all tables and basic column details from the inspected schema. It uses an environment variable for the DSN for security.

from schemainspect import inspect import os # Example for PostgreSQL connection string # Replace with your actual database URL or use an environment variable dsn = os.environ.get("DATABASE_URL", "postgresql://user:password@localhost:5432/mydb") # Inspect the database schema print(f"Inspecting schema for: {dsn.split('@')[-1] if '@' in dsn else dsn}") schema = inspect(dsn) # Print all table names print("\nTables found:") if schema.tables: for table in schema.tables: print(f" - {table.name}") # Optionally print columns for the first table as an example if table == list(schema.tables.values())[0]: # Get the first table for column in table.columns: print(f" - Column: {column.name}, Type: {column.type}, Nullable: {column.nullable}") else: print(" No tables found.") # Access a specific table (replace 'your_table_name' with an actual table in your DB) # if 'your_table_name' in schema.tables: # my_table = schema.tables['your_table_name'] # print(f"\nDetails for table '{my_table.name}':") # for column in my_table.columns: # print(f" Column: {column.name}, Type: {column.type}, Primary Key: {column.primary_key}")
Debug
Known issues
gotchaThe library uses timestamp-based versioning (e.g., 3.1.1663587362) instead of semantic versioning. This means minor updates could potentially introduce behavioral changes without a major version increment, making it harder to track breaking changes.
fix
Always test `schemainspect` thoroughly after updating, especially if relying on specific schema inspection behaviors.
affects: All versions
gotchaWhile the project aims to support 'possibly others,' its strong dependency on `pgspecial` and the project's focus imply a primary and most robust support for PostgreSQL. Full feature parity for other database backends (e.g., specific data types, constraints, or unique database objects) is not explicitly guaranteed and might require explicit testing.
fix
Thoroughly test schema inspection results if using a database other than PostgreSQL. Refer to SQLAlchemy's dialect documentation for specifics of your chosen database.
affects: All versions
gotchaViews might not be fully supported or behave differently than tables, leading to unexpected results or incomplete metadata when iterating `schema.tables` or accessing `.columns` for view-like objects.
fix
Explicitly check for view types if your database contains views and you need to inspect them. For advanced view introspection, consider using database-specific tools or raw SQLAlchemy reflection if `schemainspect` provides insufficient detail.
affects: All versions
Upgrade
Version history
3.1.1663587362latest on PyPI · released Sep 19, 2022
Audit
Dependencies
pgspecialrequiredProvides PostgreSQL-specific introspection capabilities.
sqlalchemyrequiredCore ORM and database toolkit for database interaction.
sqlparserequiredSQL parser for various SQL dialects.
Agent activity
12 hits · last 30 days
node
8
Resources
schemainspect — pip install schemainspect · libregistry