High-performance dead code elimination analysis tool for Python.
Project description
CytoScnPy - High-Performance Python Static Analysis
A 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 are also provided.
Why CytoScnPy?
- Blazing Fast: Faster in dead code detection.
- Memory Efficient: Uses less memory.
- Comprehensive: Dead code, secrets, security, taint analysis, quality metrics
- Framework Aware: Flask, Django, FastAPI, Pydantic, Azure Functions
- Benchmarked: Continuous benchmarking with 135-item ground truth suite
Installation
Linux / macOS:
# Install
curl -fsSL https://raw.githubusercontent.com/djinn09/CytoScnPy/main/install.sh | bash
Windows (PowerShell):
# Install
irm https://raw.githubusercontent.com/djinn09/CytoScnPy/main/install.ps1 | iex
Via Pip:
pip install cytoscnpy
From Source:
git clone https://github.com/djinn09/CytoScnPy.git
cd CytoScnPy
pip install maturin
maturin develop -m cytoscnpy/Cargo.toml
MCP Server (for AI Assistants)
CytoScnPy includes an MCP server for AI assistant integration:
# Start MCP server (after pip install)
cytoscnpy mcp-server
For Claude Desktop, Cursor, or GitHub Copilot configuration, see the MCP Server Documentation.
Features
- Dead Code Detection: Unused functions, classes, imports, and variables with cross-module tracking.
- Cascading Detection: Methods inside unused classes are automatically flagged as unused.
- Auto-Fix: Remove dead code automatically with
--fix(preview by default, use--applyto execute).
- Clone Detection: Find duplicate code with
--clones. - Security Analysis: Taint analysis (SQLi, XSS), secret scanning (API keys, suspicious variables), and dangerous code patterns (
eval,exec). - Code Quality Metrics: Cyclomatic complexity, Halstead metrics, Maintainability Index, and raw metrics (LOC, SLOC).
- Framework Support: Native understanding of Flask, Django, FastAPI, Pydantic, and Azure Functions v2 patterns.
- Smart Heuristics: Handles dataclasses,
__all__exports, visitor patterns, and dynamic attributes intelligently. - Cross-File Detection: Tracks symbol usage across the entire codebase, including nested packages and complex import chains, to ensure code used in other modules is never incorrectly flagged.
Usage
[!IMPORTANT] Behavioral Change: Starting from version 1.2.2, tests are excluded by default across both the CLI and the library API to reduce noise in production analysis. Use the
--include-testsflag or setinclude_tests = truein your configuration to scan test files.
Command Line
cytoscnpy [PATHS]... [OPTIONS]
Examples:
# Dead code analysis
cytoscnpy . # Analyze current directory
cytoscnpy /path/to/project --json # JSON output for CI/CD
# Security checks (short flags: -s, -d, -q)
cytoscnpy . --secrets --danger --quality
cytoscnpy . -s -d -q # Same with short flags
# Confidence threshold (0-100)
cytoscnpy . --confidence 80
# Path filtering
cytoscnpy . --exclude-folder venv --exclude-folder build
cytoscnpy . --include-folder specific_venv # Override defaults
cytoscnpy . --include-tests
# Jupyter notebooks
cytoscnpy . --include-ipynb --ipynb-cells
# Clone detection (find duplicate code)
cytoscnpy . --clones --clone-similarity 0.8
# Auto-fix dead code (preview first, then apply)
cytoscnpy . --fix # Preview changes (dry-run by default)
cytoscnpy . --fix --apply # Apply changes
cytoscnpy . --fix -a # Apply changes (short flag)
# Generate HTML report (quality auto-enabled; add --secrets --danger for security)
cytoscnpy . --html --secrets --danger
# Pre-commit integration
# See https://djinn09.github.io/CytoScnPy/pre-commit/ for setup
Common Options:
| Flag | Description |
|---|---|
-s, --secrets |
Scan for API keys and hardcoded credentials |
-d, --danger |
Scan for dangerous code + taint analysis |
-q, --quality |
Scan for code quality issues (complexity, etc.) |
--clones |
Activate duplicate code detection |
--fix |
Preview/dry-run dead code removal |
-a, --apply |
Apply fixes to files (use with --fix) |
--json |
Output results in machine-readable JSON |
[!TIP] > View the Full CLI Reference for detailed usage, advanced configuration, and quality gate options.
CI/CD Gate Options:
| Flag | Description |
|---|---|
--fail-threshold <N> |
Exit code 1 if unused code % > N |
--max-complexity <N> |
Exit code 1 if any function complexity > N |
--min-mi <N> |
Exit code 1 if maintainability index < N |
--fail-on-quality |
Exit code 1 if any quality issues found |
--max-nesting <N> |
Exit code 1 if any block nesting > N |
--max-args <N> |
Exit code 1 if any function has > N args |
--max-lines <N> |
Exit code 1 if any function has > N lines |
Full CLI Reference: See docs/CLI.md for complete command documentation.
Metric Subcommands
cytoscnpy raw . # Raw Metrics (LOC, SLOC, Comments)
cytoscnpy cc . # Cyclomatic Complexity
cytoscnpy hal . # Halstead Metrics
cytoscnpy mi . # Maintainability Index
cytoscnpy stats . --all # Full project report (secrets, danger, quality)
cytoscnpy stats . --all -o report.md # Save report to file
cytoscnpy files . # Per-file metrics table
Tip: Add
--jsonfor machine-readable output,--exclude-folder <DIR>to skip directories globally, or--ignore <PATTERN>for subcommand-specific glob filtering.
⚙️ Configuration
Create .cytoscnpy.toml (uses [cytoscnpy]) or add to pyproject.toml (uses [tool.cytoscnpy]):
.cytoscnpy.toml example:
[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 # Note: include_ipynb and ipynb_cells are CLI-only (use flags)
# Analysis Features
secrets = true
danger = true
quality = true
# Fail Threshold (exit code 1 if exceeded)
fail_threshold = 10.0 # Fail if >10% of code is unused
# fail_threshold = 0.0 # Zero tolerance: fail on any unused code
# Code Quality Thresholds
max_lines = 100 # Max lines per function
max_args = 5 # Max arguments per function
max_complexity = 10 # Max cyclomatic complexity
max_nesting = 4 # Max indentation depth
min_mi = 65.0 # Minimum Maintainability Index
ignore = ["R001"] # Ignore specific rule IDs
# Advanced Secret Scanning
[cytoscnpy.secrets_config]
entropy_enabled = true
entropy_threshold = 4.5 # Higher = more random (API keys usually >4.0)
min_length = 16 # Min length to check for entropy
scan_comments = true # Scan comments for secrets
skip_docstrings = false # Skip docstrings in entropy scanning
min_score = 50 # Minimum confidence score (0-100)
suspicious_names = ["db_config", "oauth_token"] # Add custom suspicious variable names
# Custom Secret Patterns
[[cytoscnpy.secrets_config.patterns]]
name = "Slack Token"
regex = "xox[baprs]-([0-9a-zA-Z]{10,48})"
severity = "HIGH"
Note: Notebook options (
include_ipynb,ipynb_cells) are currently CLI-only but will be added to the configuration file in a future release.
CI/CD Quality Gates
Configure quality gates for CI/CD pipelines. Set thresholds and the CLI exits with code 1 if exceeded.
CLI Flags:
# Unused code percentage gate
cytoscnpy . --fail-threshold 5 # Fail if >5% unused
# Complexity gate
cytoscnpy . --max-complexity 10 # Fail if any function >10
# Maintainability Index gate
cytoscnpy . --min-mi 40 # Fail if MI <40
# Quiet mode for clean CI output
cytoscnpy . --fail-threshold 5 --quiet
Priority: CLI flag > config file > environment variable > default
Environment Variable: CYTOSCNPY_FAIL_THRESHOLD=5.0
Performance
Accuracy (Benchmark Suite: 135 items)
| Detection Type | Precision | Recall | F1 Score |
|---|---|---|---|
| Classes | 0.73 | 0.79 | 0.76 |
| Functions | 0.71 | 0.74 | 0.73 |
| Methods | 0.86 | 0.93 | 0.89 |
| Imports | 0.67 | 0.40 | 0.50 |
| Variables | 0.30 | 0.15 | 0.20 |
| Overall | 0.71 | 0.64 | 0.68 |
See benchmark/README.md for detailed comparison against Vulture, Flake8, Pylint, Ruff, and others.
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
- Documentation: CytoScnPy
- PyPI: PyPi
- VS Code Extension: VS Code Marketplace
- Roadmap: docs/roadmap.md
References
CytoScnPy's design and implementation are inspired by:
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.2.4-cp314-cp314-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp314-cp314-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 2.3 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 |
0e44a0d74a1732f33cff1e9a68ee18b891a12762a91683b67d7da8ca38b9d21a
|
|
| MD5 |
92476fda8120d741b474eb10551160fd
|
|
| BLAKE2b-256 |
bcd928c1f8fe5270d2eb8f9f273927489fe1245ad9a09ee04c6e28817e33417f
|
File details
Details for the file cytoscnpy-1.2.4-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.1 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 |
eb1672ce347acd615968cc5ed47efc317415f5b6844b32610b2fdccddbd5a0a8
|
|
| MD5 |
7f850e24f0e849b54446465ab43be841
|
|
| BLAKE2b-256 |
efaed49ca93dce4e23504f8c60efd5bf65c19be57945c81c443a8001c9c35391
|
File details
Details for the file cytoscnpy-1.2.4-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 2.1 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 |
b9255c0a5da02c32902a2c3dcc299608f32577eb3f12d9624e841a60f7b5a17a
|
|
| MD5 |
b307d93e6f8957729bcf62fb898a4f62
|
|
| BLAKE2b-256 |
7d1e4ff2626011557e9b27d3a8b36c3f1604b15ec7c6dc1ce7c8917b5f5c46ef
|
File details
Details for the file cytoscnpy-1.2.4-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.1 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 |
5ff7b2c68369c8f81163e5770e757b348e47a3512f0372ccaacc8060f58ac538
|
|
| MD5 |
cd45afd52c290bcb08a1e05060d0d05c
|
|
| BLAKE2b-256 |
39fb089503760f47712e6b610785b2d80e8f8871c1b0dfedfe4342aa984fdd90
|
File details
Details for the file cytoscnpy-1.2.4-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 2.1 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 |
18485a04ebbd25dfc7165f2ccd5277a02dd048d92da17085987bdb9475062b44
|
|
| MD5 |
ddbb4a504c6bba8f7de55a1eb1fec1c6
|
|
| BLAKE2b-256 |
f69a83a155eda0ce06a25d7c330bc179841644c22a34d019705b6d390fcbb522
|
File details
Details for the file cytoscnpy-1.2.4-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp312-cp312-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 2.3 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 |
746baebc186fa96a4066c8067f8aa1660d8780d9c219a0a169f488301c22f993
|
|
| MD5 |
5c92f8962607807f8b3948daa0abc062
|
|
| BLAKE2b-256 |
4480f531e5aa57d539fc9cef975c2f2fc0dc769731a2ba6b136f9587897c8eff
|
File details
Details for the file cytoscnpy-1.2.4-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.1 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 |
9894a32e5244c21d9a777fee3065857805a333e080b028c3ba4a25c304707df4
|
|
| MD5 |
2c92de4b23b51d2473b6ebd80ebd52a3
|
|
| BLAKE2b-256 |
f27b8cdd69993e4c8032197ef680eb9dbaa673fad244d87a22679bfdce448dfb
|
File details
Details for the file cytoscnpy-1.2.4-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 2.1 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 |
c7be585fd7b11c2982ca633cd96dabd708a0b1b7e6799bba66a4a83b8a5ecc7c
|
|
| MD5 |
6f4e12bbc0cb5ffbca0bd2acb34c7d93
|
|
| BLAKE2b-256 |
b9ac58746107552fb48d1d45e11ac7c98ccf9a5c20c09b299ca7021b43bbbec5
|
File details
Details for the file cytoscnpy-1.2.4-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.1 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 |
a32268bd220bf070d6cee04b4c9291a5a84c514d2ca928bc1e170b84044ed16f
|
|
| MD5 |
a04c9c01491fa97e04b37be21b0464ad
|
|
| BLAKE2b-256 |
aca4429ed9df27fd16dd8d8e32796511c10ea5618970165499cc28f4ded5cce9
|
File details
Details for the file cytoscnpy-1.2.4-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 2.1 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 |
a335c4bec237d8874280bfc23ae7f0db9539571cf2355841049d4e8a7921e45f
|
|
| MD5 |
3164283fcbf182ec3f532398c0556512
|
|
| BLAKE2b-256 |
ebd77da37026a09f434ab07552723d8987e034c501333f7f21cf0b97c11d920d
|
File details
Details for the file cytoscnpy-1.2.4-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: cytoscnpy-1.2.4-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 2.1 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 |
84ccf5ac65585f54e7f6f0cee8c23eef8bdb4e0fdb73e6e3ead58bd1153ac77a
|
|
| MD5 |
dda9949f584c58565f4d3eb1317530de
|
|
| BLAKE2b-256 |
4f2ed14f72af95941c31d5aa485116216f6beed38f43109b0ee73b030ab48893
|