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.
- 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.
-
Clone the repository:
git clone https://github.com/pythonicforge/Pyinspect cd Pyinspect -
Install dependencies: Ensure you have Python 3.9+ installed. Install required dependencies using
pip:pip install -r requirements.txt
-
Run the CLI:
python main.py
Once the CLI is running, you can use the following commands:
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
Clears the terminal screen.
Exits the PyInspect CLI.
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 theinspectcommand to analyze Python objects.do_bye: Implements thebyecommand to exit the CLI.do_clear: Implements theclearcommand to clear the terminal.
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.
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!Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.