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

# 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 patterns
--quality Scan for code quality issues
--taint Enable taint analysis
--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.1-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.1-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.0.1-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.1-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.1-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 006f89dfa6aa681dab80996b34a505362122e5bcbc95f22890ae4c6f37b48c9a
MD5 77e49678384cf062d6dddd283285dc50
BLAKE2b-256 bddb2af9a1264f01e7270612e2f4a66d2821826dca9a746806e3c6da58828779

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ab0c0c5d9a9b6691d4fa97de1810d70265f48eedafa5c0a7710faaec8df0378f
MD5 6f2e2809fe44c6625f5394e43c5edeaf
BLAKE2b-256 5c5219a12b7bedaeb89da17c89f11fdf55bae29a93ceac1bec861db6bd6fd2a0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fd3c2bb46886abf99234c58c1f06d9f224cc767a26772f22b6636055320fde08
MD5 bc3b46599e3e3070a6c5f85f5f43e204
BLAKE2b-256 c2747fe5a21227cba44d63906e5913a02de62e7f648458740278bce40ae48bf8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be5b4f3e2a8162f4ecca3328cab9fe682e1666d08d4a85bb3f61c609313627f9
MD5 9e6f8fae302d7ed677f7b579356db5d8
BLAKE2b-256 ca898c9a5202d0cbc86a3078332033e5e7b767a9ed7d0306272ca6b4a0352ffb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 106f0d8df728ecb96d1d7c3760646424d1896455ed4ca94ebfb31f066e8b903c
MD5 7d5d480baee2427e07fa13d3ba8363d0
BLAKE2b-256 0da098296abd045577bdc5c3b814f7e1fc28cd36fed8f3d967ba3bbf8096da43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 d8bb00e74f288fea4c24f5978f6b1da1b9c633ccdcd623daf3c48cc367991b86
MD5 9e23440467b098e645ef046d1f71a78a
BLAKE2b-256 ec013843b4ed4e69e516cf2cec82cad9ca8e81f3887e7662f6fc4ebe964ccd90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f16c15cdedc65e22a54d8cc38b80a88286e75654044b5668c390578b2be9f488
MD5 eb69091a6e3f73eae152c3368435e7b5
BLAKE2b-256 7868923272496ddf26d9b55d290f87923e9c8cbf76afed942084781cf8947747

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bbeae65cc7326bc492343acf325f1da96ec97b20cdbe0b9cbe10127c837a41c0
MD5 61ebb8db5ef359cef7341ef8fb434229
BLAKE2b-256 a1c5f8201bb2a85cdd3fdbe87ad77041890f62b1c93296031437b656cf716bc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce5a222a674128d83e6c9f05e8081d5e6314416781914a802ad0912d32d6a67c
MD5 7544caa06e074882196b878c0bd73405
BLAKE2b-256 392e4dbbd43d8db4b4a5623161f02e94b572ff381647147ae5b84e7810025ca3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8e575879242c336c4270122e035691ea4dc9b55b7a106f5212b066b30b93a731
MD5 326756cc1be8f8446c7f5a53cc041a2f
BLAKE2b-256 269f6c945539af3b5d73877ae357c5e823924c735f79ab22dbc38aecaacb8490

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.0.1-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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f4c89b26f4d81e20598ec42b41c1a6b87b5b959609a703b72293b9e25884427f
MD5 9ba0378a9c4cfe00ec51ed8f80c9051c
BLAKE2b-256 7de79af60fed910058c6349c989e92a308e643b8e0dfbc0f0c11204ee3f9840a

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