High-performance dead code elimination analysis tool for Python (Rust implementation).
Project description
CytoScnPy - High-Performance Python Static Analysis 🦀🐍
A lightning-fast static analysis tool for Python codebases, powered by Rust with hybrid Python integration. Detects dead code, security vulnerabilities (including taint analysis), and code quality issues with extreme speed. Code quality metrics include cyclomatic complexity, Halstead metrics, maintainability index, nesting depth, and more.
🚀 Why CytoScnPy?
- 🔥 Blazing Fast: Faster in dead code detection.
- 💾 Memory Efficient: Uses less memory.
- 🐍 Python Native: Installable via
pip, importable in Python code - ⚡ CLI Ready: Standalone command-line tool with rich output
- 🔍 Comprehensive: Dead code, secrets, security, taint analysis, quality metrics
- 🎯 Framework Aware: Understands Flask, Django, FastAPI patterns
- 📊 Benchmarked: Continuous benchmarking with 126-item ground truth suite
📦 Installation
# Install from PyPI (when published)
pip install cytoscnpy
# Or install from source
git clone https://github.com/djinn09/CytoScnPy.git
cd CytoScnPy
pip install maturin
maturin develop -m cytoscnpy/Cargo.toml
🛠️ Usage
Command Line
# Basic usage
cytoscnpy [PATHS]... [OPTIONS]
# Examples:
cytoscnpy . # Analyze current directory
cytoscnpy /path/to/project --json # Output as JSON
cytoscnpy . --secrets --danger --quality # Enable specific checks
cytoscnpy . --taint # Enable taint analysis
# Options:
# -c, --confidence <CONFIDENCE> Set confidence threshold (0-100)
# --secrets Scan for secrets
# --danger Scan for dangerous code patterns
# --quality Scan for code quality issues
# --taint Enable taint analysis
# --json Output results as JSON
# --include-tests Include test files in analysis
# --exclude-folders <FOLDERS> Exclude specific folders
# --include-folders <FOLDERS> Force include specific folders
# --include-ipynb Include Jupyter notebooks
# --ipynb-cells Report findings per cell
# -h, --help Print help
# -V, --version Print version
# Subcommands
# -----------------------------------------------------------------------
# Raw Metrics (LOC, SLOC, Comments)
cytoscnpy raw /path/to/project
cytoscnpy raw . --json --exclude-folder venv
# Cyclomatic Complexity (McCabe)
# Calculates complexity for each function/method
cytoscnpy cc .
cytoscnpy cc /path/to/file.py --json
# Halstead Metrics
# Calculates Difficulty, Effort, Volume, Bugs, Time
cytoscnpy hal .
cytoscnpy hal . --exclude-folder tests
# Maintainability Index
# Combined metric (0-100) indicating code maintainability
# < 65 = Hard to maintain
# > 85 = Easy to maintain
cytoscnpy mi .
cytoscnpy mi . --json
> **Note**: Average Complexity and Maintainability Index are automatically calculated and shown in the summary of the main `cytoscnpy .` command.
✨ Features
Dead Code Detection
- Unused functions, classes, methods with cross-module tracking
- Unused imports and variables with scope-aware analysis
- Entry point detection (
if __name__ == "__main__") to prevent false positives - Dynamic pattern recognition (
hasattr,getattr,globals()) - Pragma support (
# pragma: no cytoscnpyto suppress findings)
Security Analysis
CytoScnPy comes with built-in security features to keep your codebase safe:
- Taint Analysis: Tracks untrusted user input to prevent SQL Injection and XSS.
- Secret Scanning: Finds hardcoded API keys and credentials using high-entropy checks.
- Dangerous Code: Alerts you to unsafe usage of
eval(),pickle, andsubprocess.
For deep technical details on how the security engine works, see cytoscnpy/README.md.
Code Quality Metrics
| Metric | Description |
|---|---|
| Raw Metrics | LOC, LLOC, SLOC, Comments, Multi-line strings, Blanks |
| Cyclomatic Complexity | Control flow complexity (McCabe) |
| Halstead Metrics | Difficulty, Effort, Volume, Bugs, Time |
| Maintainability Index | Combined metric (0-100 scale) |
| Nesting Depth | Maximum indentation level analysis |
Framework Support
| Framework | Detected Patterns |
|---|---|
| Flask | @app.route, request object sources, render_template |
| Django | request handling, ORM patterns, template rendering |
| FastAPI | @app.get/post/..., Request parameter sources |
Smart Heuristics
- Dataclass fields automatically marked as used
- Settings/Config classes with uppercase variables ignored
- Visitor pattern methods (
visit_*,leave_*,transform_*) marked as used __all__exports prevent flagging as unused- Base class tracking for inheritance-aware analysis
Configuration
Create .cytoscnpy.toml or add to pyproject.toml:
[tool.cytoscnpy]
# General Settings
confidence = 60 # Minimum confidence threshold (0-100)
exclude_folders = ["venv", ".tox", "build", "node_modules", ".git"]
include_folders = ["src", "tests"] # Optional: whitelist folders
include_tests = false
# Analysis Features
secrets = true
danger = true
quality = true
# Code Quality Thresholds
max_lines = 100 # Max lines per function
max_args = 5 # Max arguments per function
complexity = 10 # Max cyclomatic complexity
nesting = 4 # Max indentation depth
min_mi = 65.0 # Minimum Maintainability Index
ignore = ["R001"] # Ignore specific rule IDs
# CI/CD Integration
fail_threshold = 5.0 # Exit with code 1 if unused code % exceeds this
# Advanced Secret Scanning
[tool.cytoscnpy.secrets_config]
entropy_enabled = true
entropy_threshold = 4.0 # Higher = more random (API keys usually > 4.0)
min_length = 16 # Min length to check for entropy
scan_comments = true # Scan comments for secrets
# Custom Secret Patterns
[[tool.cytoscnpy.secrets_config.patterns]]
name = "Slack Token"
regex = "xox[baprs]-([0-9a-zA-Z]{10,48})"
severity = "HIGH"
Environment Variables
You can also configure CytoScnPy via environment variables (useful for CI/CD):
| Variable | Description |
|---|---|
CYTOSCNPY_FAIL_THRESHOLD |
Fail threshold % (overrides config) |
📊 Performance
Speed Comparison
| Metric | CytoScnPy |
|---|---|
| Time | 0.07s |
| Memory | ~14MB |
Accuracy (Benchmark Suite: 126 items)
| Detection Type | Precision | Recall | F1 Score |
|---|---|---|---|
| Classes | 0.75 | 0.82 | 0.78 |
| Functions | 0.57 | 0.74 | 0.64 |
| Methods | 1.00 | 0.59 | 0.74 |
| Imports | 0.50 | 0.37 | 0.42 |
| Variables | 0.25 | 0.16 | 0.19 |
| Overall | 0.61 | 0.57 | 0.59 |
See benchmark/README.md for detailed comparison against Vulture, Flake8, Pylint, Ruff, and others.
🏗️ Architecture
See cytoscnpy/README.md for detailed architecture and technology stack information.
🧪 Testing
See CONTRIBUTING.md for testing instructions.
🤝 Contributing
See CONTRIBUTING.md for development setup and guidelines.
📝 License
Apache-2.0 License - see License file for details.
🔗 Links
- Rust Core Documentation: cytoscnpy/README.md
- Benchmarks & Accuracy: BENCHMARK.md
- Roadmap: ROADMAP.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
📚 References
CytoScnPy's design and implementation in Rust are inspired by and reference the following Python libraries:
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 Distributions
Built Distributions
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 cytoscnpy-1.0.0-cp314-cp314-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp314-cp314-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.14, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a6ceeba9f5dcfa920d31bec0756eb1d86e052f35cdcaedfa8b30268b96979eb
|
|
| MD5 |
1d6a37d138fdca192c0a1f91b6e78776
|
|
| BLAKE2b-256 |
64b0c4227255c4df501a59574341f4f0548a92dfed1114aedf5d23bee9e55bfa
|
File details
Details for the file cytoscnpy-1.0.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e53eafd9fd5a432018c2ad76d49c28acef13dced01c8a4319f46091da363e77
|
|
| MD5 |
439323af9ff31fa059fe16402484c6c4
|
|
| BLAKE2b-256 |
ea029b6ed54b4ebb09e6befdb0352691f4bdcf5e532803208a3b0a3cfcacaeeb
|
File details
Details for the file cytoscnpy-1.0.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20db5d44e38894908c0fb3a6aeb9d6dfd81a43ed4331995d88debc2b95e9bedf
|
|
| MD5 |
9b10a974b572949e1fb3a0c6ed5be9df
|
|
| BLAKE2b-256 |
774850d00d86dc18b62f55f1fd08af59d33ba5a74b3a6440276705dcc2a9b5a6
|
File details
Details for the file cytoscnpy-1.0.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07d08cd68b9099d7e5c8b39149bd67a4afc0df5a9a65d097fae2190f7b02f7d0
|
|
| MD5 |
32d25ae89bea0f65bb88d47fef5f1ad6
|
|
| BLAKE2b-256 |
e7e1087b30b837b8f9337f3a794304d1003b5b6c1466b1da6a682f03abed17ed
|
File details
Details for the file cytoscnpy-1.0.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eed5b8b55c557fea1060ae36f418c174002b2c15fb4a11f5b92e6e261facb9e
|
|
| MD5 |
7410d8033e776cc41cf4bf9bdf565358
|
|
| BLAKE2b-256 |
25f994ad3b0e2b208db26ea0ebd8e450d909e43f351087652f13da0506e1b47a
|
File details
Details for the file cytoscnpy-1.0.0-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp312-cp312-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e8bb93453b36506fb5e220f82f97f29d1fdae870547e54f1a02027cf4ff4de5
|
|
| MD5 |
13c5572ee72e0c8dd7e798e4fba6aa50
|
|
| BLAKE2b-256 |
403e0aa4a0ff35b06549ef52ec9d14e9e6baffde2b7ef00cb53e0e0438a35be1
|
File details
Details for the file cytoscnpy-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbafc377aa35d35c1e5a309d58e6cca29256f95ad3172cade46bba15f6aeabf2
|
|
| MD5 |
187eba74550988c4cf0ce35e943ef865
|
|
| BLAKE2b-256 |
496c3bd51d3404df63a238e2b94084e9ffae8c52609e41958a18c75f4fdf05f2
|
File details
Details for the file cytoscnpy-1.0.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f18759665a3eb228fc14ffdf1296c0198f2898aa1bb9142f5b0163795e1e1360
|
|
| MD5 |
ba6c983dcbba9b01bc390209155a173e
|
|
| BLAKE2b-256 |
698f8e88ec4df3b900f5a21ada04cffa03cc122fe54a5de563ce77a5c8033637
|
File details
Details for the file cytoscnpy-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e251d3e1dee1ec539b83f022f603c2a0df4b874d9bdb3264f3b3427c5237d3f3
|
|
| MD5 |
ff22127e36f9ffaf6b31b9a143c2a173
|
|
| BLAKE2b-256 |
50e2e2b71e9890375769c8d88417cdea90e1ba6d79150a0fa65829d4f3748998
|
File details
Details for the file cytoscnpy-1.0.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd24ed9ab2efa1fac0ccaa20552ce0dece651242f9c6393f1eac7255cf594f7a
|
|
| MD5 |
867cf300c3829e7ccf8b5cfafa5a0f8c
|
|
| BLAKE2b-256 |
d4cf10483e6afe888b3c79edaacde469ba29ab59533b2dc344c5340e3805425b
|
File details
Details for the file cytoscnpy-1.0.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.0.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47385f283dd4ccf8265e41602a39ad9f14be582e59708cff2ffea4822ce262c5
|
|
| MD5 |
171aef1f9e33aaa36a1d521f1b8475cf
|
|
| BLAKE2b-256 |
f3bac4d74df0393e43571acbbe375f338683306d26cebe19413ca1925e098e06
|