Skip to main content

CodeStructure is a Python package that analyzes the structure of a Python file and extracts information about its classes, functions, and their associated attributes.

Project description

:building_construction: CodeStructure

CodeStructure is a Python package that analyzes the structure of a Python file and extracts information about its classes, functions, and their associated attributes. It is particularly useful for understanding and documenting complex codebases and writing design docs.

:star: Features

  • Extract class and function signatures
  • Extract class attributes
  • Extract function parameters and their types
  • Extract function return types
  • Extract decorators and docstrings
  • Display the extracted information in a human-readable format

:books: Table of Contents

:package: Installation

You can install CodeStructure via pip:

pip install codestructure

:book: Usage

To use CodeStructure, simply run the script with the path to the Python file you want to analyze:

codestructure path/to/your/python_file.py

The script will output the analyzed code structure and copy it to the clipboard if the pyperclip package is installed.

Run the script with the --help flag to see all available options:

codestructure --help

Which should output:

usage: codestructure [-h] [--no-private] [--no-copy] [--backticks] [--no-rich]
                     [--line-numbers]
                     module_file_path

Analyze the code structure of a Python file.

positional arguments:
  module_file_path  Path to the Python file.

options:
  -h, --help        show this help message and exit
  --no-private      Do not print private functions.
  --no-copy         Do not copy the output to the clipboard.
  --backticks       Use backticks for code blocks.
  --no-rich         Do not use rich to print the output.
  --line-numbers    Print line numbers for the code blocks.

:memo: Example

Given a Python file with the following content:

class MyClass:
    my_attr: str

    def my_method(self, arg1: int) -> bool:
        """My docstring."""
        a = 1 + 1
        ...

def my_function(arg2: float) -> None:
    arg2 = arg2 + 1
    ...

CodeStructure will output:

class MyClass:
    my_attr: str

    def my_method(self, arg1: int) -> bool:
        """My docstring."""

def my_function(arg2: float) -> None:
    ...

:busts_in_silhouette: Contributing

We welcome contributions to CodeStructure! If you find a bug or have a feature request, please create an issue on the GitHub repository. If you would like to contribute code, please fork the repository and submit a pull request.

:page_with_curl: License

CodeStructure is released under the Apache 2.0 License. For more information, please see the LICENSE file.

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

codestructure-1.0.0.tar.gz (15.9 kB view hashes)

Uploaded Source

Built Distribution

codestructure-1.0.0-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page