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

✨ 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.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

📚 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.0.3-cp314-cp314-manylinux_2_39_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

cytoscnpy-1.0.3-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cytoscnpy-1.0.3-cp313-cp313-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.0.3-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cytoscnpy-1.0.3-cp312-cp312-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.0.3-cp312-cp312-manylinux_2_39_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

cytoscnpy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cytoscnpy-1.0.3-cp311-cp311-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cytoscnpy-1.0.3-cp310-cp310-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.0.3-cp39-cp39-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.3-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 a0a673b911375e8b666a5fc5fd947f28f3f230372c5e790f146396d21ff6c66c
MD5 bd1b831196df3b0234c14712e575d11a
BLAKE2b-256 fc2220bb82a92d05a3a279562531964cfedb1336d58d5f2bae82bb3bb9e2f59d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 19f1f38816df6ea1284b25ba9b647e30a108882cee10edcf5c3788bc4c1fbfc8
MD5 931c75e9367a7cedf9322575e9b0e679
BLAKE2b-256 53a40438279ee278b7783b5c1760a079af44f66fdbb5ce03d95fe63ebc6378b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.3-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

Hashes for cytoscnpy-1.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 24e62c3a586f5f0c998963c642831216774bb6b7c349ea0f534f9c69b60f9b18
MD5 d4f54e6490792286a70f1f02ae114c2b
BLAKE2b-256 ccd3f93990de8a32c8303fdd0e61558d5f0cec2a9439ac1f64d992fee3d9ded3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cafe4083cf573cfc0f5ba07d0f5f189c4e384488240cf91fa7034fa8dd13ebf5
MD5 1608f8d593e9d34f716e38e047f75d4a
BLAKE2b-256 0b6359e18b88000647edde81e6cdafe325daabcdfdcc54ddffb37b652d0938f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.3-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

Hashes for cytoscnpy-1.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9682373a3ab73c3149781e1506d0af470f2c43abd480e37b0759835fdf81f100
MD5 57a538dbba31580e259679c93f11f353
BLAKE2b-256 ccbbda479d48ed6d8eccec88dd0aba478b6770946b32b76ef7e2edc37e163fdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.3-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 e40b60b1e99098dedf92ca7d395c48ec1bafc121a8a0a62e68a1edbef934ae85
MD5 9cb2b9ceb451bd197a6a47787b212040
BLAKE2b-256 123a5b0a3d89452b67bd0932ad543e514567acf2f9dd52af0ac37bed40387deb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b078e48f12f852e1b412d899f21790a15729a7142f3b351c6f06bd5561243e7b
MD5 ea37e9a9f0bc99f5bd2cf2c8f795ff99
BLAKE2b-256 2520ff997aa072d22e9c37a5920b2a48be187bec735b6a53c715c2c2892f9804

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.3-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

Hashes for cytoscnpy-1.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 04aff8b9983e02177b802c0783ba2ca061c2be6b3028b0f7a8049fa9cad499ae
MD5 02df0baf70d975d5e77d17c92b3af9b8
BLAKE2b-256 f8d68ad7a9a4dde30bc1288df00f2574e4df76d9dd23c7a75fece1515a06d014

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65b534427c92a39d7b0c0a595ac7667d5c794404c93ad66df812f3879568d697
MD5 fc0358b02511363d70651a2578460bd1
BLAKE2b-256 d4be3f8bc19d78751af4d6aaa637d174aed91b04dbfa9312acc79caa7e6979b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.3-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

Hashes for cytoscnpy-1.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2cf62ad2f0b09ea58cfa7f62bd5336bb9d8ca0a41f95702aa37b0edae8a659ec
MD5 6b7c49a62a4fe70d5bb53f4ffbe5834b
BLAKE2b-256 446807d72d5b45f5f93d85b9323f3cc57f12694e4e4af28c8f63933006bad6de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.3-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

Hashes for cytoscnpy-1.0.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b59e08b5292cc20606e9da3e686c81d4748e42241e5595b1e055e7297c69390c
MD5 3763b62fd78d360d08628aa4732c084c
BLAKE2b-256 dca4e8aa85c869f40f5216afb55b87454f82dad7cab07cee9682cfcf08fa3e10

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