Skip to main content

Database inspection extension for half-orm

Project description

half-orm-inspect

Database inspection extension for halfORM - powerful PostgreSQL database introspection and exploration tools.

PyPI version Python Support License: GPL v3

๐ŸŽฏ Overview

half-orm-inspect provides comprehensive database inspection capabilities for halfORM projects. Explore your PostgreSQL database structure, analyze tables, views, and schemas with ease through both CLI and programmatic interfaces.

โœจ Features

  • ๐Ÿ“Š Database Overview: List all relations with type indicators and statistics
  • ๐Ÿ” Detailed Inspection: Deep dive into specific tables, views, and schemas
  • ๐Ÿ“ˆ Schema Analysis: Explore schema organization and relationship mapping
  • ๐Ÿ“‹ Multiple Output Formats: Human-readable console output and JSON export
  • ๐ŸŽฏ Smart Filtering: Filter by relation type with intelligent target parsing
  • ๐Ÿ”— halfORM Integration: Seamless integration with halfORM CLI ecosystem
  • ๐Ÿง  Smart Target Parsing: Handles dots in schema and table names automatically

๐Ÿš€ Installation

# Install via pip
pip install half-orm-inspect

# Or install from source
git clone https://github.com/half-orm/half-orm-inspect.git
cd half-orm-inspect
pip install -e .

Prerequisites

  • Python 3.7+
  • halfORM >= 0.16.0
  • PostgreSQL database with halfORM configuration

๐Ÿ“– Usage

Through halfORM CLI (Recommended)

# List all database relations
half_orm inspect mydatabase

# Inspect specific schema
half_orm inspect mydatabase.public

# Inspect specific table
half_orm inspect mydatabase.public.users

# Show only schema list
half_orm inspect mydatabase --schema-only

# Filter by relation type
half_orm inspect mydatabase --type table
half_orm inspect mydatabase.public --type view

# JSON output for scripting
half_orm inspect mydatabase --json

Advanced Target Parsing

The inspect command intelligently handles dots in schema and table names:

# These all work correctly:
half_orm inspect mydatabase
half_orm inspect mydatabase.my_schema
half_orm inspect mydatabase.my.complex.schema
half_orm inspect mydatabase.my.schema.table_name

๐Ÿ’ก Examples

Basic Database Exploration

$ half_orm inspect ecommerce

=== Database: ecommerce ===

๐Ÿ“‚ Schema: public
  ๐Ÿ“‹ users
  ๐Ÿ“‹ products
  ๐Ÿ“‹ orders
  ๐Ÿ‘๏ธ  order_summary
  ๐Ÿ”— sales_report

๐Ÿ“‚ Schema: inventory
  ๐Ÿ“‹ stock_items
  ๐Ÿ“‹ suppliers
  ๐Ÿ“Š product_stats

Total: 8 relations
   ๐Ÿ“‹: 5 tables
   ๐Ÿ‘๏ธ : 1 views
   ๐Ÿ”—: 1 materialized views
   ๐Ÿ“Š: 1 partitioned tables

Use 'half_orm inspect ecommerce.<schema>[.<table>]' for detailed information

Schema-Only Listing

$ half_orm inspect ecommerce --schema-only

=== Database: ecommerce ===
๐Ÿ“‚ Schema: public
๐Ÿ“‚ Schema: inventory
๐Ÿ“‚ Schema: analytics

Schema Inspection

$ half_orm inspect ecommerce.public

=== Schema: public (Database: ecommerce) ===
  ๐Ÿ“‹ users
  ๐Ÿ“‹ products
  ๐Ÿ“‹ orders
  ๐Ÿ‘๏ธ  order_summary
  ๐Ÿ”— sales_report

Total: 5 relations
   ๐Ÿ“‹: 3 tables
   ๐Ÿ‘๏ธ : 1 views
   ๐Ÿ”—: 1 materialized views

Table Details

$ half_orm inspect ecommerce.public.users

=== ecommerce.public.users ===
Table: users
Columns:
  โ€ข id (integer, PRIMARY KEY)
  โ€ข email (varchar(255), NOT NULL, UNIQUE)
  โ€ข created_at (timestamp with time zone, DEFAULT now())
  โ€ข profile_data (jsonb)

Indexes:
  โ€ข users_pkey (PRIMARY KEY on id)
  โ€ข users_email_idx (UNIQUE on email)

Foreign Keys: None
Referenced By:
  โ€ข orders.user_id โ†’ users.id

Filtering by Type

# Show only tables in database
$ half_orm inspect ecommerce --type table

# Show only views in specific schema
$ half_orm inspect ecommerce.public --type view

# Available types: table, view, partitioned, materialized

JSON Output for Scripts

$ half_orm inspect ecommerce --json | jq '.relations[] | select(.type=="table")'

{
  "schema": "public",
  "table": "users", 
  "type": "table"
}
{
  "schema": "public",
  "table": "products",
  "type": "table"
}
$ half_orm inspect ecommerce.public --json

{
  "database": "ecommerce",
  "schema": "public",
  "relations": [
    {
      "schema": "public",
      "table": "users",
      "type": "table"
    },
    {
      "schema": "public", 
      "table": "products",
      "type": "table"
    }
  ],
  "total": 5
}

๐Ÿ”ง Configuration

half-orm-inspect uses your existing halfORM database configuration. Ensure your database is properly configured in your halfORM project:

# Verify your database configuration
export HALFORM_CONF_DIR=/path/to/your/config
half_orm inspect yourdatabase

๐Ÿ”ง Command Options

Target Formats

Format Description Example
DATABASE List all relations in database half_orm inspect mydb
DATABASE.SCHEMA List relations in specific schema half_orm inspect mydb.public
DATABASE.SCHEMA.RELATION Inspect specific relation half_orm inspect mydb.public.users

Available Options

Option Short Description
--json Output as JSON format
--type -t Filter by relation type (table, view, partitioned, materialized)
--schema-only -s Show only schema list (database level only)

Type Filters

  • table - Regular tables (๐Ÿ“‹)
  • view - Database views (๐Ÿ‘๏ธ)
  • partitioned - Partitioned tables (๐Ÿ“Š)
  • materialized - Materialized views (๐Ÿ”—)

๐Ÿ› ๏ธ Development

Setting up Development Environment

# Clone the repository
git clone https://github.com/half-orm/half-orm-inspect.git
cd half-orm-inspect

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run linting
black half_orm_inspect/
flake8 half_orm_inspect/

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=half_orm_inspect --cov-report=html

# Run specific test categories
pytest tests/test_cli.py -v

๐Ÿ“Š Output Formats

Console Output

  • Emoji indicators: ๐Ÿ“‹ tables, ๐Ÿ‘๏ธ views, ๐Ÿ”— materialized views, ๐Ÿ“Š partitioned tables
  • Color coding: Schema names, relation types, and statistics
  • Hierarchical display: Grouped by schema for easy navigation
  • Smart parsing: Handles complex schema and table names with dots

JSON Output

Perfect for scripting and automation:

{
  "database": "ecommerce",
  "relations": [
    {
      "schema": "public",
      "table": "users",
      "type": "table"
    }
  ],
  "total": 8
}

For schema-specific inspection:

{
  "database": "ecommerce", 
  "schema": "public",
  "relations": [...],
  "total": 5
}

๐Ÿ“Œ Integration with halfORM CLI

This extension integrates seamlessly with the halfORM CLI ecosystem:

# List all extensions
half_orm --list-extensions

# Show extension info
half_orm version

# Manage extension trust (for non-official extensions)
half_orm --untrust half-orm-inspect

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

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

๐Ÿ“„ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

The GPL-v3 ensures that this software remains free and open source, and that any derivative works are also made available under the same terms. This helps maintain and grow the open source ecosystem around halfORM.

๐Ÿ”— Links

๐Ÿ“ˆ Version Compatibility

The <major>.<minor> version of half-orm-inspect must match your half-orm core version for compatibility.

๐Ÿ’ฌ Support


Made with โค๏ธ by the halfORM Team

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

half_orm_inspect-0.17.0.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

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

half_orm_inspect-0.17.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file half_orm_inspect-0.17.0.tar.gz.

File metadata

  • Download URL: half_orm_inspect-0.17.0.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for half_orm_inspect-0.17.0.tar.gz
Algorithm Hash digest
SHA256 9ae6af9edc2ae2bb31ee0db49f5ae162fc346adb19d5b3a81854468ba765f246
MD5 dcf06d794f538ccb76a10a7fe07d30e1
BLAKE2b-256 65f02dbdee0daea70746f4458e1f2413f9306d97a685cc8067718739292832ac

See more details on using hashes here.

File details

Details for the file half_orm_inspect-0.17.0-py3-none-any.whl.

File metadata

File hashes

Hashes for half_orm_inspect-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ae72280b03ca2559e3896e206eb694b443b156d2213a4e046f93ab708cffdd6
MD5 84bf49a132fe0a514a874b157af69460
BLAKE2b-256 5cab1709102717771039634708177e5a908741535a62d2414c1c579cd299a656

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