{"library":"schemainspect","title":"Schema Inspect","description":"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.","language":"python","status":"maintenance","last_verified":"Fri Apr 17","install":{"commands":["pip install schemainspect"],"cli":null},"imports":["from schemainspect import inspect"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from schemainspect import inspect\nimport os\n\n# Example for PostgreSQL connection string\n# Replace with your actual database URL or use an environment variable\ndsn = os.environ.get(\"DATABASE_URL\", \"postgresql://user:password@localhost:5432/mydb\")\n\n# Inspect the database schema\nprint(f\"Inspecting schema for: {dsn.split('@')[-1] if '@' in dsn else dsn}\")\nschema = inspect(dsn)\n\n# Print all table names\nprint(\"\\nTables found:\")\nif schema.tables:\n    for table in schema.tables:\n        print(f\"  - {table.name}\")\n        # Optionally print columns for the first table as an example\n        if table == list(schema.tables.values())[0]: # Get the first table\n            for column in table.columns:\n                print(f\"    - Column: {column.name}, Type: {column.type}, Nullable: {column.nullable}\")\nelse:\n    print(\"  No tables found.\")\n\n# Access a specific table (replace 'your_table_name' with an actual table in your DB)\n# if 'your_table_name' in schema.tables:\n#     my_table = schema.tables['your_table_name']\n#     print(f\"\\nDetails for table '{my_table.name}':\")\n#     for column in my_table.columns:\n#         print(f\"  Column: {column.name}, Type: {column.type}, Primary Key: {column.primary_key}\")\n","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}