Static analysis tool for Python code optimization suggestions
Project description
smart_code
Current version: 0.5.0
smart_code is a static analysis tool that detects inefficient Python code patterns (AST-based) and provides optimization suggestions. It covers Pandas/NumPy anti-patterns, algorithmic inefficiencies, and common Python pitfalls.
Features
- AST-Based Analysis: Accurately detects code patterns without executing code.
- Rich Pattern Library: Covers a wide range of anti-patterns from Pandas usage to algorithmic mistakes.
- Click-to-Navigate Output: Terminal output is formatted as
file:line: message, allowing you to jump directly to the code in modern IDEs (like VS Code or PyCharm). - Multi-language Support: Suggestions can be displayed in English or Chinese.
- Codemod Refactoring: Optionally rewrite code in-place using built-in transformations.
Usage
Command-Line Interface
Analyze one or more Python files:
smart_code path/to/your_script.py [another_file.py ...]
To receive suggestions in Chinese, use the --lang zh flag:
smart_code path/to/your_script.py --lang en
To automatically rewrite files with codemods while still printing the detected issues, add the --codemod flag:
smart_code --codemod your_script.py
Python API
You can also use smart_code programmatically in your own scripts.
from smart_code.analyzer import CodeAnalyzer
from smart_code.suggest import format_issue
# Initialize the analyzer in a specific language ('zh' or 'en')
analyzer = CodeAnalyzer(lang='en')
issues = analyzer.analyze_file("script.py")
for issue in issues:
# Format the output for printing
formatted_message = format_issue(issue, lang='en')
print(f"script.py:{issue['lineno']}: {formatted_message}")
# The raw issue dictionary is also available
# print(issues)
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 smart_code-0.5.0.tar.gz.
File metadata
- Download URL: smart_code-0.5.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.10 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c617f2e2dbd50e40f458dc9e97df6f910ac03e06e1104014b76476e42f10d5a1
|
|
| MD5 |
07340034e3b9cd6ab2bed4ce0c086c5e
|
|
| BLAKE2b-256 |
b7bbf487d38ea4035012b676da932ae8e56836fa7b8c5d353ffbca5b49300a7f
|
File details
Details for the file smart_code-0.5.0-py3-none-any.whl.
File metadata
- Download URL: smart_code-0.5.0-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.10 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2187c419e5b645dc3ed219d390ec6b7b9b9b42c29070b046d35b76ee72eab068
|
|
| MD5 |
96900830049bec304d77fcc4fe15567a
|
|
| BLAKE2b-256 |
cae0bed70dcb9933804546184f5fdb312b9b0c94263c92650a110d0dfb258b51
|