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
Extract code signatures without the code :snake:
This program extracts information about the structure of Python code by analyzing the abstract syntax tree (AST) of a given Python file. It extracts information about classes, their attributes, and functions, as well as their signatures, parameters, return types, decorators, and docstrings. The script then print this information in a human-readable format with syntax highlighting. It can also copy the output to the clipboard. It is particularly useful for understanding and documenting complex codebases and writing design docs or when pasting in some code in ChatGPT.
:star: Features
- 🔎 Identifies class and function signatures without executing the code
- 📝 Retrieves class attributes
- 📚 Gathers function parameters and their corresponding types
- 🔄 Determines function return types
- 🎨 Recognizes decorators and docstrings
- 🌟 Presents the code in an easily understandable format with Syntax Highlighting
- ✅ Has 100% test coverage
:books: Table of Contents
- :package: Installation
- :book: Usage
- :memo: Example
- :busts_in_silhouette: Contributing
- :page_with_curl: License
: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 outputs:
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 (tests/example.py
) with the following content:
class MyClass:
my_attr: str
_my_private_attr: int
def my_method(self, arg1: int) -> bool:
"""My docstring."""
x = 1 + 2
...
def my_function(arg2: float) -> None:
arg2 = arg2 + 1
return arg2**2
def _private_function():
"""My private function."""
x = 1 + 2
y = x + 4
return y
CodeStructure will output:
codestructure --no-private tests/example.py
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file codestructure-1.1.0.tar.gz
.
File metadata
- Download URL: codestructure-1.1.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58f235ffa69c1a1cb055cb7f9cb427c794e6dd76d003910d9dbfcca6913ce45d |
|
MD5 | 6f0bbf25f181ec70cf77234e6cf1f8e0 |
|
BLAKE2b-256 | 62a762063f7232b76c58659fa65f5f2515a6a0063723917411b7c24996cbe7a7 |
File details
Details for the file codestructure-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: codestructure-1.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d05ae57bbee9f105b64d525bd7f18ce398e938a94ee9821f6ba3582b20d5300 |
|
MD5 | 66a5e982300496aef8115a0ad0b6513f |
|
BLAKE2b-256 | 530e6109d4bdabc0227e0914e750ef6c493d9517cd21944a52f6101ba0f7ed24 |