Skip to main content

A tool to extract code elements from Python files

Project description

PyCodeLens

A Python code analysis tool to extract code elements like functions, decorators, classes, and print statements.

Installation

pip install pycodelens

Features

PyCodeLens allows you to extract and analyze:

  1. Functions

    • Count of functions in a file
    • Function names
    • Line numbers (start and end)
    • Associated decorators
  2. Decorators

    • Count of decorators in a file
    • Decorator names
    • Line numbers where they appear
  3. Classes

    • Count of classes in a file
    • Class names
    • Line numbers (start and end)
    • Methods within each class
  4. Print Statements

    • Count of print statements
    • Line numbers
    • Number of arguments

Usage

Command Line

# Basic usage (shows count of all elements)
pycodelens path/to/your_file.py

# Show detailed information about functions
pycodelens path/to/your_file.py --functions

# Show only decorators
pycodelens path/to/your_file.py --decorators

# Show information about all elements
pycodelens path/to/your_file.py --all

# Show only counts
pycodelens path/to/your_file.py --counts

# Output in JSON format
pycodelens path/to/your_file.py --json

# Show verbose information
pycodelens path/to/your_file.py --all --verbose

Python API

from pycodelens import analyze_file

# Analyze a file
analysis = analyze_file('path/to/your_file.py')

# Access the summary
summary = analysis['summary']
print(f"Number of functions: {summary['num_functions']}")
print(f"Function names: {summary['function_names']}")

# Access raw results
raw_results = analysis['raw_results']
for func in raw_results['functions']:
    print(f"Function {func['name']} on lines {func['line_start']}-{func['line_end']}")
    if func['decorators']:
        print(f"  Has decorators: {', '.join('@' + d['name'] for d in func['decorators'])}")

Example Output

File: example.py
  Functions: 5
  Decorators: 3
  Classes: 2
  Print statements: 7

FUNCTIONS:
  main (lines 10-20)
    Decorators: @app.route, @login_required
  process_data (lines 22-30)
  helper_function (lines 32-35)
    Decorators: @staticmethod
  ...

DECORATORS:
  @app.route: 2 occurrences (lines: 10, 45)
  @login_required: 1 occurrences (lines: 11)
  @staticmethod: 2 occurrences (lines: 32, 50)
  ...

Requirements

  • Python 3.7+
  • astroid library

License

MIT

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

pycodelens-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

pycodelens-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pycodelens-0.1.0.tar.gz.

File metadata

  • Download URL: pycodelens-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for pycodelens-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bf866d6170ef4660494bbe9b52a811a7e554b0a43280f6e14b816455db99f788
MD5 1ea4b6077f02416190bd1181158e0c74
BLAKE2b-256 a9cd15f65cba05dc80607b15e02e5299ca9a6bb1e703ff32da79c43014bcf239

See more details on using hashes here.

File details

Details for the file pycodelens-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycodelens-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for pycodelens-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b91f8cacf63d0ae7831f5bb08542b4bdff1cc8b88fd0babea359e2ee6f41b27
MD5 35baab034a8efc333e2be0eaf20e767f
BLAKE2b-256 ae44191fc52209f73d94755b281a631bb71fa97bd5dc39bedb130ccef3c7c03a

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