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.2-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.2-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.0.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.0.2-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.2-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.2-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 24d510a04b283bc632e6e3d50dcd20bf7ca0fa5321f63d7b55f82b45803ea97a
MD5 0e64d97ca06ee783e89779aea105b22e
BLAKE2b-256 0e9d1859d97edaf5e1b9a18e11eb3692996ae5226c9a4fb1a12e9b31deba71ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20f414138216e288aacff58523262ac728fcb8dfb649765eab358a03ddcd9e6a
MD5 48a548a725c0725d6e5f6691d6aaa794
BLAKE2b-256 ba536ebae1f300716857c5c50f218a5cc749db8f0c59e1e0ec31d0827d214cc7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2e0fd6a01ffccb14a5f437f6611e3f8f4f08397c99e5974df9fe64c9171b94b8
MD5 bff7e3aa27b44eb6bac652320fd17786
BLAKE2b-256 119901f69190ed5e76c269d2f54d314eb06aea19f445bac214b7aa7943a45abd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c0f7ee43209bcbe31f8b5728c5452ef9dced09d98a613f7a7c6bc40890744f2
MD5 40aed6e870a9b9dcde479083943351f9
BLAKE2b-256 cf8fbfa5199e459889f657e08aeaaf25c2331b13e4aff39f60570a2f0962340b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dcea58e0d6cb1625ca4b9bfc02bb78426df0650560b9cac18e3544d5a62b72a5
MD5 abd6faf44b48b386fca32b83fd7fd12b
BLAKE2b-256 a7ff625e173c1be87abe0d10932d00369cab11e8333ac2f35a2d22bd63aa5b1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1a5a5379bba926aac2a0dc7cb0d1bc4d8b6f26fed2e013dac6a77d44b174c027
MD5 c17678de52e2d98c5d38446300351f4d
BLAKE2b-256 84174453c7cf45619e32357d365d97a800fd822227f9498d6d2a7e3e4ed6e0f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bfdbf1edab9823d0760bd1d49777051ccebf6a7bd47dab5556858f742d777fb5
MD5 5e1bc6d121426329e2492354538b9fc2
BLAKE2b-256 6c8c0e457ac1c463542edd0a011122b53fe2cc746d1b343b6810aeafd0d8d88a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b537f07847aac4232c0c5894520400f10eb183802b31c09b0edae435bddc78de
MD5 48df6e867012ef312bb9c0a2c7b348a2
BLAKE2b-256 2da94f71f1c2ce6245b3394eb7017d3e420bf222ffdcfaaf90acf345cf81155a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ac89e6576760785c82bd71d58eee90fc3402ec84272ffd66c77e51f21a81058d
MD5 0a27e5c51d6c0c02c1aa3a3b016072bd
BLAKE2b-256 7532838a30ef14e702bd02cab36c65cad1659d652d0500b68d6468f2ae4c970b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.2-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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 015ffc190bc7c9423a8db811b1483173bc116cfb32fe449fb2a6d5e3fcd55111
MD5 8e14b6b16ad928239af095c10e30d04b
BLAKE2b-256 0dcfa41568541d12ddeb00293745cc55a0116e339cfb9c8d521082de7d5395f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.2-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.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 61e58236adc433662df275bd464e88b57595422ceb9e4269780610495187fdc8
MD5 37cc89f77e2142c8a21c9ab845734e53
BLAKE2b-256 c941e589d3a763d4bb969e35dd8ed92b6125bb5a7609ca840ae2ac67963c6bf2

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