A tool to track where Python constructs are used and update docstrings
Project description
uzpy
A production-ready Python tool that automatically analyzes code usage patterns and updates docstrings with "Used in:" documentation.
uzpy scans Python codebases to find where each function, class, and method is used, then automatically updates their docstrings with comprehensive usage information. This helps developers understand code dependencies and maintain better documentation.
โจ Features
- ๐ Smart Analysis: Uses Tree-sitter for fast, error-resilient Python parsing
- ๐ฏ Accurate References: Combines Rope and Jedi for comprehensive usage detection
- ๐ Safe Modifications: Preserves code formatting using LibCST with lossless editing
- โก High Performance: Optimized for large codebases with hybrid analysis strategies
- ๐จ Beautiful Output: Rich terminal interface with progress indicators and summaries
- ๐ก๏ธ Error Recovery: Graceful handling of syntax errors and edge cases
- ๐๏ธ Production Ready: Complete implementation with comprehensive error handling
๐ Installation
# Install dependencies with uv (recommended)
uv venv && source .venv/bin/activate
uv pip install -e .
# Or with pip
pip install tree-sitter tree-sitter-python rope jedi libcst fire rich loguru pathspec
pip install -e .
๐ Quick Start
# Analyze and update docstrings in a project
python -m uzpy -e src/myproject/
# Preview changes without modification
python -m uzpy -e src/myproject/ --dry-run --verbose
# Analyze a single file
python -m uzpy -e src/myproject/module.py --dry-run
# Get help
python -m uzpy --help
๐ก Usage Examples
Basic Analysis
# Analyze and update docstrings in a project directory
python -m uzpy -e src/myproject/
# Analyze a single file
python -m uzpy -e src/myproject/utils.py
Preview Mode
# See what would change without modifying files
python -m uzpy -e src/myproject/ --dry-run --verbose
# Get detailed analysis information
python -m uzpy -e src/myproject/ --dry-run --verbose
Real-World Examples
# Analyze your entire src directory
python -m uzpy -e src/ --verbose
# Check a specific module before refactoring
python -m uzpy -e src/core/database.py --dry-run
# Update documentation for API modules
python -m uzpy -e src/api/ --verbose
๐ง How It Works
uzpy uses a sophisticated four-phase pipeline:
- ๐ Discovery Phase: Finds all Python files while respecting gitignore patterns
- ๐ Parsing Phase: Uses Tree-sitter to extract functions, classes, and methods with their docstrings
- ๐ Analysis Phase: Employs a hybrid approach combining Rope and Jedi to find usage patterns
- ๐ Modification Phase: Uses LibCST to safely update docstrings while preserving formatting
Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ File Discovery โโโโโถโ Tree-sitter โโโโโถโ Hybrid Analyzerโโโโโถโ LibCST Modifierโ
โ (gitignore + โ โ Parser โ โ (Rope + Jedi) โ โ (docstring โ
โ pathspec) โ โ (AST + constructs)โ โ (usage finding)โ โ updates) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
What Gets Updated
uzpy automatically adds "Used in:" sections to docstrings:
Before:
def calculate_total(items):
"""Calculate the total price of items."""
return sum(item.price for item in items)
After:
def calculate_total(items):
"""Calculate the total price of items.
Used in:
- src/main.py
- src/billing/invoice.py
- tests/test_calculations.py"""
return sum(item.price for item in items)
Example Output
When you run uzpy, you'll see beautiful terminal output like this:
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ uzpy Configuration โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Edit Path โ src/myproject/ โ
โ Reference Path โ . โ
โ Dry Run โ No โ
โ Verbose โ Yes โ
โโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ File Discovery Summary โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Edit Files โ 23 โ utils.py, models.py, ... โ
โ Reference Files โ 156 โ main.py, tests.py, ... โ
โโโโโโโโโโโโโโโโโโโดโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Construct Parsing Summary โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Module โ 23 โ 12/23 โ
โ Class โ 45 โ 31/45 โ
โ Function โ 128 โ 89/128โ
โ Method โ 267 โ 156/267โ
โ Total โ 463 โ 288/463โ
โโโโโโโโโโโโดโโโโโโโดโโโโโโโโ
๐ง CLI Reference
Main Command
python -m uzpy [OPTIONS]
Options
| Option | Short | Description | Default |
|---|---|---|---|
--edit |
-e |
Path to analyze and modify | Required |
--ref |
-r |
Reference path to search for usage | Same as edit |
--verbose |
-v |
Enable detailed logging | False |
--dry-run |
Show changes without modifying files | False |
|
--methods-include |
Include method definitions | True |
|
--classes-include |
Include class definitions | True |
|
--functions-include |
Include function definitions | True |
|
--exclude-patterns |
Comma-separated glob patterns to exclude | None |
๐ ๏ธ Development
uzpy is built with modern Python practices and comprehensive testing.
Setup Development Environment
# Clone the repository
git clone https://github.com/yourusername/uzpy.git
cd uzpy
# Setup with uv (recommended)
uv venv && source .venv/bin/activate
uv pip install -e .
# Or with pip
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e .
Development Workflow
# Run tests
python -m pytest
# Lint and format code
ruff check --fix
ruff format
# Full development pipeline (from CLAUDE.md)
fd -e py -x autoflake {}; fd -e py -x pyupgrade --py311-plus {}; fd -e py -x ruff check --output-format=github --fix --unsafe-fixes {}; fd -e py -x ruff format --respect-gitignore --target-version py311 {}; python -m pytest;
Architecture Overview
uzpy is designed with modularity and extensibility in mind:
src/uzpy/cli.py- Command-line interface using Fire and Richsrc/uzpy/discovery.py- File discovery with gitignore supportsrc/uzpy/parser/- Tree-sitter based Python parsingsrc/uzpy/analyzer/- Hybrid reference analysis (Rope + Jedi)src/uzpy/modifier/- LibCST-based safe code modification
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Tree-sitter for fast, error-resilient parsing
- Rope for accurate cross-file analysis
- Jedi for fast symbol resolution
- LibCST for safe code modification
- Rich for beautiful terminal output
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uzpy-1.3.0.tar.gz.
File metadata
- Download URL: uzpy-1.3.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02fbac89181633862fc5fa86f454018fa93b87c22a9c4a05387dd4e66883fb44
|
|
| MD5 |
6cebf9806554a67ad8501490a4fdcc56
|
|
| BLAKE2b-256 |
2705d280307e007827578608bdf471cef573b592e30a73754da1da919de1ff8e
|
File details
Details for the file uzpy-1.3.0-py3-none-any.whl.
File metadata
- Download URL: uzpy-1.3.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbc62e7db29c76b8afe4a0d1d70c2472bf62b252b7ce28459864891aa8e2a751
|
|
| MD5 |
221f4c075f126424c5168d6a83cb6b0b
|
|
| BLAKE2b-256 |
e71b67b575343ad71cade50b1d5c0933684d62476c0fb0e39203339447e0e335
|