Skip to content

pythonicforge/pyinspector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PyInspect

PyInspect is a Python-based Command Line Interface (CLI) tool designed to inspect Python objects. It provides detailed information about Python literals and objects, including their type, memory ID, mutability, hashability, size, and available methods. This tool is useful for developers who want to explore and debug Python objects interactively.


Features

  • Object Inspection: Analyze Python literals and objects to retrieve detailed information such as type, memory ID, mutability, hashability, size, and methods.
  • Interactive CLI: Provides an interactive command-line interface for inspecting objects and executing commands.
  • Custom Commands:
    • inspect: Inspect a Python literal or object.
    • clear: Clear the terminal screen.
    • bye: Exit the CLI.

Installation

  1. Clone the repository:

    git clone https://github.com/pythonicforge/Pyinspect
    cd Pyinspect
  2. Install dependencies: Ensure you have Python 3.9+ installed. Install required dependencies using pip:

    pip install -r requirements.txt
  3. Run the CLI:

    python main.py

Usage

Once the CLI is running, you can use the following commands:

inspect <object>

Inspect a Python literal or object. For example:

inspect [1, 2, 3]

This will output:

  • Type of the object
  • Memory ID
  • Hashability
  • Mutability
  • Size in bytes
  • Whether the object is interned
  • List of available methods

clear

Clears the terminal screen.

bye

Exits the PyInspect CLI.


Code Overview

shell.py

The shell.py file contains the main implementation of the PyInspect CLI. It uses the cmd module to provide an interactive shell. Key methods include:

  • is_hashable: Checks if an object is hashable.
  • is_mutable: Determines if an object is mutable.
  • is_interned: Checks if a string object is interned.
  • get_methods: Retrieves a list of callable methods for an object.
  • do_inspect: Implements the inspect command to analyze Python objects.
  • do_bye: Implements the bye command to exit the CLI.
  • do_clear: Implements the clear command to clear the terminal.

logger.py

The logger.py file (assumed to exist) provides logging functionality for the CLI. It is used to log information, errors, and success messages in a structured format.


Example

Here is an example session with PyInspect:

Welcome to PyInspect β€” the Python Object Inspector CLI
Type 'help' to list commands. Type 'bye' to exit.

(pyinspect) inspect {'key': 'value'}
πŸ” Inspecting: {'key': 'value'}

β€’ Type       : <class 'dict'>
β€’ Memory ID  : 140123456789456
β€’ Hashable   : ❌
β€’ Mutable    : βœ…
β€’ Size       : 240 bytes
β€’ Interned   : ❌
β€’ Methods    : clear, copy, fromkeys, get, items, keys, pop, popitem, setdefault, update, values

(pyinspect) bye
Shutting down PyInspect..
Done!

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.


License

This project is licensed under the MIT License. See the LICENSE file for details.

About

πŸš€ The ultimate cli tool for deep-diving into python objects, tracking mutability, hashability, and more!

Topics

Resources

License

Stars

Watchers

Forks