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 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, Celery, Starlette, Pydantic, Azure Functions v2
  • 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)

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 --apply to 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

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
cytoscnpy . --html --secrets --danger --quality

Options:

Flag Description
-c, --confidence <N> Set confidence threshold (0-100)
-s, --secrets Scan for API keys, tokens, credentials
-d, --danger Scan for dangerous code + taint analysis
-q, --quality Scan for code quality issues
-n, --no-dead Skip dead code detection (security/quality only)
--html Generate interactive HTML report
--json Output results as JSON
-v, --verbose Enable verbose output for debugging
-q, --quiet Quiet mode: summary only, no tables
--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
--clones Detect duplicate code
--clone-similarity <N> Clone similarity threshold (0.0-1.0)
--fix Preview dead code removal (dry-run by default)
-a, --apply Apply --fix changes to files

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 --json for 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 is CLI-only (use --include-ipynb flag)

# 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

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

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/BENCHMARK_REPORT.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.2.0-cp314-cp314-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

cytoscnpy-1.2.0-cp314-cp314-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cytoscnpy-1.2.0-cp313-cp313-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.2.0-cp313-cp313-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cytoscnpy-1.2.0-cp312-cp312-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.2.0-cp312-cp312-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

cytoscnpy-1.2.0-cp312-cp312-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cytoscnpy-1.2.0-cp311-cp311-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cytoscnpy-1.2.0-cp310-cp310-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.2.0-cp39-cp39-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.0-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 f4abf9b21e32312d0c7e0dbcd1957e91607e810d113c1da43721e8201decf4bd
MD5 53a0b81f49087a831da3620e25ef3b23
BLAKE2b-256 1f01b4272fa22fc431dbf27c5e3730ace2163b7684138a6bd62e999d3346e294

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9f213da801f79986d09680bd9ba246e273e09fbb876ea41e87871aa5debee84
MD5 aac5447672f1fbad2952ca568a9a452e
BLAKE2b-256 6e32f0073f940ea78ea1fbea5c0975e63d8717485d77ea1b8c4315aa68f57439

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.0 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.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cef6dbc29319572c3cc1defa5c9e5498526f4ce2d7650792b56af6e4d3ac7834
MD5 f8eec19a3b4476abd2f16b12463ec4d7
BLAKE2b-256 a6632f25add9bf0b6559864bcf77fa9f0006d15ebe41616fd6051b88f6249531

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4082ecf54b5418022757b36036529318bad8ffc4c65790cec6182062c6a9c26b
MD5 670243955c6dc18ec821e9ecce8fe9a3
BLAKE2b-256 ee17921935a0e197ea78e9c4a761cb83b1a09ae0b4203b2f5413fed3905e041d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.0 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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 54f1b7698a89fa58e94b7d5de569d1e658bd1346a79b58d3af76920d1807a3f2
MD5 a8a9f027eba6d781510db31bbc00a6fb
BLAKE2b-256 6f0ca81aba2d980fefadbef119fa554505ce6cda3195a8741b582128103bd62a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ce087bf104c8891bc734af49b9cfd9a861936efe41f9e0e9c2db35acb43f7131
MD5 301518a0b5a25a87d6f4e5e65f8ec381
BLAKE2b-256 59e32028f4851c8dddc0e6df062cda348905c5c97e9f3dbc5948e177275efdf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe778551bba842d47be70820d9e97000aae59066f83c2333e3658c3f54eb341b
MD5 55188c6b8c0a1543e054d1bfc18adbd8
BLAKE2b-256 c505fa49a46f405ead77d520e808b59b0ba2486660ceb4d4ac1d7da0b1fc2412

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.0 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.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7dbf731a663046bb05b8109c3ffe5306d3113854f9164cdf22827b8703e09643
MD5 43fa90ca20bc2c10216ad440ba085b1e
BLAKE2b-256 d9abab686091ef572119e28306f54c511dfbb063bf59bffe265710367746157b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 058107be4d8a87aa7448f25043d3a1ddd39761976fbbf9d4f72d99f9bbae7590
MD5 ee51bb94f19f8eb0b0fd8f56d8db76fa
BLAKE2b-256 4d01a3858803b01cb96672389e9692f195fae21267455cccf4589a44ae4dfc9e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.0 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.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d95c518736acd08000ebb64d62c074195cad611a2d6ae5b5237bd4b0f0a22b6c
MD5 01b8e11778b27c2942c59c84cd7c583f
BLAKE2b-256 729da87b3f2af3118e0d77cc0e62f8437ad1c6fcbf0aa98cd7f2175066a02f45

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.0 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.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6d2b98622c9e569a5ddb743fd7ec352199f29acf50e1ff2c7b7533c637d5ce81
MD5 a89f527431610618008ef04967218121
BLAKE2b-256 97018aeeb480d29f832dcf72c9cb72393b5ce6a53fdfd7cad9ae19ddc3fe138b

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