An open API service indexing awesome lists of open source software.

https://github.com/pythonicforge/pyinspect

The ultimate Python CLI tool for deep-diving into your objects, tracking their mutability, hashability, and more with a single command! 🚀
https://github.com/pythonicforge/pyinspect

cli python typescript

Last synced: 6 months ago
JSON representation

The ultimate Python CLI tool for deep-diving into your objects, tracking their mutability, hashability, and more with a single command! 🚀

Awesome Lists containing this project

README

          

# 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:
```bash
git clone https://github.com/pythonicforge/Pyinspect
cd Pyinspect
```

2. Install dependencies:
Ensure you have Python 3.9+ installed. Install required dependencies using `pip`:
```bash
pip install -r requirements.txt
```

3. Run the CLI:
```bash
python main.py
```


### Usage

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

#### `inspect `
Inspect a Python literal or object. For example:
```bash
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:
```bash
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 :
• 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.