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: 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.
  • 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 (--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
-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

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

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

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"

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: 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.1-cp314-cp314-manylinux_2_39_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

cytoscnpy-1.1.1-cp314-cp314-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cytoscnpy-1.1.1-cp313-cp313-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.1.1-cp313-cp313-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cytoscnpy-1.1.1-cp312-cp312-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.1.1-cp312-cp312-manylinux_2_39_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

cytoscnpy-1.1.1-cp312-cp312-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cytoscnpy-1.1.1-cp311-cp311-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.1.1-cp311-cp311-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cytoscnpy-1.1.1-cp310-cp310-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.1.1-cp39-cp39-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.1.1-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 fda6213e648100dad7c14957edebf5a81adc04dbb362759fbd9e749c314c8cc6
MD5 5c86126e069fb85a093b4697f6c7cdf0
BLAKE2b-256 648602647ef7f4b4acb13d7681f939c25a639a5eb04da9df0baed2972a3d84ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.1.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ac0f883c82447812a2c190352a19a564ed9ee8ab5eded3cd1c5ae3034b6cdf4b
MD5 5249b0159e746acf2d179afcc3c23872
BLAKE2b-256 c9382b69cdec4010b8788dca5601143c5fe7e471e577026d6c66be0cb553d1e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.6 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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 46d21b43a31c9dc5aac78fe843591d8716613f5d0e547a2d125ef08983155189
MD5 67a0ed0031f5ebf76ffdf251602548e1
BLAKE2b-256 12914a4e69ad1f9ab848a7c485e8bc9ab2d16505e77c018519fea0e13a1288a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df6a951d87cc9d56cf9b32ddd22e9517050a76c1256723c5ca94a24fe0e9d6de
MD5 4796590347343b774104f77300f85a77
BLAKE2b-256 276258855f13a4bc5098c6ca188d58f0b95274d6eb42de2274c921ef72dee5bd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.6 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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ee6a815c9f1528950759faccfe3dd456cb16aeb2fae53aba9a570087957ded83
MD5 6bc5e90e34507934c827dcb06ea88c6c
BLAKE2b-256 f646a18c10a307dda6c046488d55ddffade1e6c9e6ef75d70b589df700fe56e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.1.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 c28fcfb75d2b67bd898f859da5b580db5ecbd8bbb6f15489bb815003ad7c3660
MD5 0618d68b09bebdbabac03113beabc9eb
BLAKE2b-256 3e4f694549b926f360f5678d22ea7a9e793e822e5b9c586c2e6b63bda99d83e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42077039df73434fb3a2595b5722cdad5f13b057f385de73c02b93c394733529
MD5 586c71757b8edfaa9f6ce91f603823ab
BLAKE2b-256 46826d7db23f8cdd0e0143ec7998bf1ea74dcf361f27c66fb2eb0e01e97535a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.6 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f48d65222a5cc4e6d934624c3184cd41aa097547027f00daaa7d4b9084e07b8d
MD5 2a581a3bbf1cb44d51855e9bb9628ba4
BLAKE2b-256 bc3a5060337bb1638c4e4009ff490b56dbcc6a4606220052a4208a1166dbfc79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d7669ce2c6ccd95adf8409c9daeff36210d705371d9536d3d28426c20aec52c
MD5 27132a484b1081b4b9dbd2a3fef898b3
BLAKE2b-256 3128510ec5383a7f491fec4d37056121e4466567b6bc415380aea1121d1cb058

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.1.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.6 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cf9e4741eb1a8cd292a7fe2a3e5a5850f1c67bbeaea13c10bd70e19a2176e2eb
MD5 e01b00cfe3f35450d4d3831c0581c382
BLAKE2b-256 7558f58e9e19530cefdfd983764679679a48718e27401aeebedc9543fb8dd5b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.1.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.6 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3511b8a9dec95efe3e229868f2dc8b48be77bd60ed5eda1a4f8fcc1c5997bc1b
MD5 872f2233528decd6e10a4d9b217fe46a
BLAKE2b-256 eb7d128fee1ff3abc7e6c884509c0608c5469a737e8a30e1f50d2558dfe7a61b

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