Skip to main content

InspectLab Logo

InspectLab

InspectLab is a lightweight Python CLI for inspecting Python source code directly from the terminal.

It uses Python's built-in ast module to analyze source files without executing them. InspectLab can quickly show functions, classes, imports, and the full AST structure of a file.

Features

  • Inspect functions and async functions
  • Detect generators and return/yield expressions
  • Inspect classes, inheritance, metaclasses, and methods
  • Show imports and aliases
  • Show arguments and type annotations
  • Show decorators and docstrings
  • Show source line ranges
  • Print the complete Python AST

Why InspectLab?

InspectLab is useful when you want a fast structural overview of a Python file without opening it manually or running its code.

Advantages

  • Safe static inspection — analyzes source code without executing the target file.
  • Fast CLI workflow — inspect a file with one command.
  • No parser setup — built on Python's standard ast module.
  • Useful for debugging and review — quickly understand unfamiliar Python code.
  • Detailed output — includes annotations, decorators, docstrings, return values, line numbers, and more.

Installation

Install InspectLab from PyPI:

pip install inspectlab

Then verify that the CLI is available:

inspectlab --help

InspectLab relies on modern Python AST features such as ast.unparse, so Python 3.9 or newer is recommended.

Basic Usage

InspectLab provides four commands:

inspectlab functions FILE
inspectlab classes FILE
inspectlab imports FILE
inspectlab tree FILE

FILE is the Python filename you want to inspect.

InspectLab searches for that filename recursively from your current working directory.

Example:

inspectlab functions app.py

1. functions

Inspect all functions found in a Python file.

Usage

inspectlab functions FILE

Example:

inspectlab functions app.py

What it outputs

For each function, InspectLab shows:

  • Function name
  • Function type
  • Arguments and argument kinds
  • Argument type annotations
  • Return and yield expressions
  • Return type annotation
  • Decorators
  • Docstring
  • Start and end line numbers

It recognizes normal functions, async functions, generators, and async generators.

Example output:

Name: add
Type: Function with Return
Arguments:
  - a: int [Normal]
  - b: int [Normal]
Returns: [{'Return': 'a + b'}]
Return Data Type: int
Decorators: []
Docstring: Add two integers.
Lines: {'Start': 9, 'End': 11}

2. classes

Inspect classes and their methods.

Usage

inspectlab classes FILE

Example:

inspectlab classes models.py

What it outputs

For each class, InspectLab shows:

  • Class name
  • Inherited classes
  • Metaclass
  • Class decorators
  • Docstring
  • Start and end line numbers
  • Methods defined directly inside the class
  • Detailed function information for each method

Example output:

Class: Admin
Inherits: User
Metaclass: None
Decorators: None
Docstring: Represents an administrator.
Lines: 54 - 65
Methods:
  Name: validate
  Type: Function with Return
  Arguments:
    - value: int [Normal]
  Returns: [{'Return': 'value > 0'}]
  Return Data Type: bool
  Decorators: ['staticmethod']
  Docstring: None
  Lines: {'Start': 64, 'End': 65}

3. imports

List imports used by a Python file.

Usage

inspectlab imports FILE

Example:

inspectlab imports app.py

What it outputs

The command shows:

  • Import type: import or from ... import ...
  • Imported module or name
  • Import aliases
  • Source line number

Example output:

Type: Import
Line: 2
Imports:
  - sys as system

Type: ImportFrom
Line: 6
Module: collections
Imports:
  - defaultdict as dd

4. tree

Print the complete Abstract Syntax Tree of a Python file.

Usage

inspectlab tree FILE

Example:

inspectlab tree app.py

What it outputs

This command prints Python's AST representation using an indented tree. It is useful when you need to see the exact syntax nodes generated from the source code.

Example output:

Module(
    body=[
        Import(
            names=[
                alias(name='os')]),
        FunctionDef(
            name='add',
            args=arguments(...),
            body=[...])
    ])

Example Workflow

# See the functions in a file
inspectlab functions main.py

# Inspect its classes
inspectlab classes main.py

# Check its dependencies/imports
inspectlab imports main.py

# View the raw AST
inspectlab tree main.py

Error Handling

If InspectLab cannot find or parse the requested file, the CLI currently prints:

Wrong file name or typed out command

Make sure you run the command from a directory where InspectLab can find the requested filename.

License

Add your project license here.

Metadata

Release files for inspectlab 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for inspectlab 0.1.0
File Size Uploaded Provenance Actions
inspectlab-0.1.0.tar.gz 9.3 kB Without provenance Details for inspectlab-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for inspectlab 0.1.0
File Interpreter ABI Platform Actions
inspectlab-0.1.0-py3-none-any.whl Python 3 none any Details for inspectlab-0.1.0-py3-none-any.whl

Total release size: 18.1 kB

Release files / inspectlab-0.1.0.tar.gz

Download URL inspectlab-0.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1ac193a54adea0362591c7966842957b3f8d22a6db6af2d7b5f05201124d7286
BLAKE2b-256 checksum
How to use checksums
27ed9ea57a1116c892f5d3e9c1359f52047b4cba196e90fd6e3266cda7925304
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / inspectlab-0.1.0-py3-none-any.whl

Download URL inspectlab-0.1.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2598918a69d98571af5ec0ecb49a2e13e1c576dd7dc836be83dcf3308cf7b4a3
BLAKE2b-256 checksum
How to use checksums
c5c9e1162129ec785e5906811a2359ff0c99ff680f57a17bd2d40ca909b912d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for inspectlab 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page