Skip to main content

High-performance dead code elimination analysis tool for Python.

Project description

CytoScnPy - High-Performance Python Static Analysis 🦀🐍

CI License Version

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 are also provided.

🚀 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

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

🤖 MCP Server (for AI Assistants)

To use CytoScnPy MCP Server, see the MCP Server Documentation for installation instructions.

✨ Features

  • Dead Code Detection: Unused functions, classes, imports, and variables with cross-module tracking.
  • Security Analysis: Taint analysis (SQLi, XSS), secret scanning (API keys), 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, and FastAPI patterns.
  • Smart Heuristics: Handles dataclasses, __all__ exports, visitor patterns, and dynamic attributes intelligently.

🛠️ Usage

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 (--danger includes taint analysis)
cytoscnpy . --secrets --danger --quality

# 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

Options:

Flag Description
-c, --confidence <N> Set confidence threshold (0-100)
--secrets Scan for API keys, tokens, credentials
--danger Scan for dangerous code + taint analysis
--quality Scan for code quality issues
--json Output results as JSON
--include-tests Include test files in analysis
--exclude-folder <DIR> Exclude specific folders
--include-folder <DIR> Force include folders
--include-ipynb Include Jupyter notebooks
--ipynb-cells Report findings per notebook cell

Metric Subcommands

cytoscnpy raw .                    # Raw Metrics (LOC, SLOC, Comments)
cytoscnpy cc .                     # Cyclomatic Complexity
cytoscnpy hal .                    # Halstead Metrics
cytoscnpy mi .                     # Maintainability Index

Tip: Add --json for machine-readable output, --exclude-folder <DIR> to skip directories.

⚙️ 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

# 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
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"

Fail Threshold

Configure a fail threshold for unused code. If the percentage exceeds this threshold, the CLI exits with code 1.

  • Default: 100.0 (effectively disabled)
  • Zero Tolerance: Set to 0.0 to fail on any unused code

📊 Performance

Speed Comparison

Metric Rust (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.67 0.59 0.63

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

📚 References

CytoScnPy's design and implementation are inspired by:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cytoscnpy-1.1.0-cp314-cp314-manylinux_2_39_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

cytoscnpy-1.1.0-cp314-cp314-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cytoscnpy-1.1.0-cp313-cp313-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.1.0-cp313-cp313-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cytoscnpy-1.1.0-cp312-cp312-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.1.0-cp312-cp312-manylinux_2_39_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

cytoscnpy-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cytoscnpy-1.1.0-cp311-cp311-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cytoscnpy-1.1.0-cp310-cp310-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.1.0-cp39-cp39-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file cytoscnpy-1.1.0-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.1.0-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 c4e60583eab4203d66cd00db7f8bd593010d72e5c3c2be4e01b0d6190286b989
MD5 4cc071ca478b47e2b9f9aa9d58ee00eb
BLAKE2b-256 cac349e6b4c22fbe7fa68ebba987a3e9c3b5eb872f5907a699689f8bde4d3803

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d32297c27e929fffae026c79ef3d0b61966f208b4fa15c25334d60c927fa2a28
MD5 69716925769530a8fb2c624fb3875387
BLAKE2b-256 884856e498935446ad95bcc84925083f04677c19f4615036a2b3b4d4020b3f24

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.5 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

Hashes for cytoscnpy-1.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3143308ad9f69cad2b7033d3419ccca207e150a6fbf1b2ce3201e8a10083e25e
MD5 fed7a88731b122e82409f9880796e1fb
BLAKE2b-256 3aa4abe27c19b43f31c647115db406347501397c2437f7821cbbcfccdc39ba0e

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 27864e2c94faae8c8f487d9d29145e7c3c41e6118d2434c96279a44c4e411188
MD5 78a49ea9ded61a39f1034dd97299fdfe
BLAKE2b-256 d41ef23d2f89317a75b543ff80929570f75b966c830bbdd4fd9428b9f155026d

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.5 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

Hashes for cytoscnpy-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 485e7af7013a015b89c505804bc4ad4fbe4a36497c40cd0f0d9a58e88a3b7b1e
MD5 8f19f98b834d5bc53e56f6a1942b071c
BLAKE2b-256 395d924a284d7701f043aa237ca2109bc5cac8d0e50416836158f5d21c0e7d69

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.1.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1b773793781e4868c3e41aeb744b77ba7a081ec9c7344903fc09550898ee8aea
MD5 6495af8793fcda54304fed0b0cf8e2b8
BLAKE2b-256 ec905753ecb2b199d44e625fe8d0ed2d299efc30467134bff2e5102f1bea0c48

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd0159feacfdb90b942afa080047d7378fb11b838ba76f432719bf479cada7c3
MD5 1411d9cf6dd1d58d45c89cf72f6f9d9e
BLAKE2b-256 39451a04ec2bab5c777772cf828a9e846dcaf27f4c1f4d9c663cbd2bbcafdb11

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.5 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

Hashes for cytoscnpy-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2ca3a5948e2e77567e389849092b72127e0c27cc3cad7cca754bfb607baa2ca8
MD5 05168a2ac17720303f731472ff5083f7
BLAKE2b-256 a34f1c372d90811d74d2e48e0b840e571bfb8fb5202cdeb269dc99a47d234f66

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60db9e9f4f4c31082c4798c13decb29a4566703cb324afa0a8e5d24de919da17
MD5 f585afcdbd5521f6e6ae36442eda6d21
BLAKE2b-256 0213ad3ac5c20fee944042f0cbffed2b23af9931ebad363af1c79f30da90751b

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.5 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

Hashes for cytoscnpy-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 aa53d09d7dd3ae7350b681f5deb6c74854cc66df5299cdfddc2c72c544c72418
MD5 d32ab69b62232b4c981eb984a82608b9
BLAKE2b-256 41a96da684d3bb5fa402fa09385d3f1e1aa766c6374d19654cd9e0f31e628b99

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.5 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

Hashes for cytoscnpy-1.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2a7a7a8b1b69d932c78da10b6368cde002976ffb8856960338a599eff26a84e7
MD5 95a003fff72993e02d91026863adc469
BLAKE2b-256 f030755a2a4c211360e5c5540c874be8da28a06a9d246d2506dcdcce82000f0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page