Skip to main content

CytoScnPy - High-Performance Python Static Analysis

CI Coverage codecov Security Audit Docs License Version AI Assisted

A fast, lightweight static analyzer for Python codebase. It’s built in Rust with Python integration and detection of dead code, security issues, and code quality issue, along with useful quality metrics.

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, Pydantic, Azure Functions
  • Benchmarked: Continuous benchmarking with 135-item ground truth suite

Installation

Linux / macOS:

# Install
curl -fsSLO https://raw.githubusercontent.com/djinn-soul/CytoScnPy/main/install.sh
bash install.sh

Windows (PowerShell):

# Install
Invoke-WebRequest https://raw.githubusercontent.com/djinn-soul/CytoScnPy/main/install.ps1 -OutFile install.ps1
Unblock-File .\install.ps1
powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -File .\install.ps1

This applies RemoteSigned only to the installer child process and does not override organization-enforced execution policy.

Via Pip:

pip install cytoscnpy

From Source:

git clone https://github.com/djinn-soul/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 via the standalone CLI binary (install script or cytoscnpy-cli build). The Python package does not run mcp-server.

# Start MCP server (standalone CLI)
cytoscnpy mcp-server

For Claude Desktop, Cursor, or GitHub Copilot configuration, see the MCP Server Documentation.

GitHub Action

Integrate CytoScnPy directly into your GitHub Actions workflow:

- name: Run CytoScnPy Analysis
  uses: djinn-soul/CytoScnPy@v1
  with:
    args: "--secrets --danger --quality"

Action Inputs:

Input Description Default
path Path(s) to analyze .
args Additional arguments (e.g., --secrets)
version Version of cytoscnpy to install latest
python-version Version of Python to set up 3.x

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                       # Include tests in all scans/metrics/clones

# 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 (quality auto-enabled; add --secrets --danger for security)
cytoscnpy . --html --secrets --danger

# Pre-commit integration
# See https://djinn-soul.github.io/CytoScnPy/pre-commit/ for setup

Common Options:

Flag Description
-s, --secrets Scan for API keys and hardcoded credentials
-d, --danger Scan for dangerous code + taint analysis
-q, --quality Scan for code quality issues (complexity, etc.)
--clones Activate duplicate code detection
--fix Preview/dry-run dead code removal
-a, --apply Apply fixes to files (use with --fix)
--json Output results in machine-readable JSON

[!TIP] View the Full CLI Reference for detailed usage, advanced configuration, and quality gate options.

CI/CD Gate Options:

Flag Description
--fail-on-any Exit code 1 if any supported gate finds issues
--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
--fail-on-secrets Exit code 1 if any secret findings found
--fail-on-danger Exit code 1 if danger or taint findings found
--fail-on-missing-deps Exit code 1 if missing dependencies found
--fail-on-unused-deps Exit code 1 if unused dependencies 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

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
cytoscnpy deps .                   # Dependency analysis
cytoscnpy init                     # Scaffold config in the current project

Dependency analysis reports CytoScnPy-style hygiene categories for missing (CSP-R001), unused production (CSP-R002), transitive (CSP-R003), dev dependency used in production (CSP-R004), and standard-library (CSP-R005) dependencies. Development dependencies are not reported as unused by default; pass cytoscnpy deps --include-dev-unused for stricter checks.

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
include_ipynb = 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
# CLI shortcut: --fail-on-any uses zero tolerance unless fail_threshold is set

# Code Quality Thresholds
max_lines = 100       # Max lines per function
max_args = 5          # Max arguments per function
max_complexity = 10   # Max cyclomatic complexity
max_nesting = 4       # Max indentation depth
min_mi = 65.0         # Minimum Maintainability Index
ignore = ["CSP-P003"] # 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"

# Danger + Taint Configuration
[cytoscnpy.danger_config]
enable_taint = true
severity_threshold = "LOW" # LOW, MEDIUM, HIGH, CRITICAL
excluded_rules = ["CSP-D101"]
custom_sources = ["mylib.get_input"]
custom_sinks = ["mylib.exec"]

Note: ipynb_cells is currently CLI-only. include_ipynb is supported in config files.

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/README.md for detailed comparison against Vulture, Flake8, Pylint, Ruff, and others.

Contributing

See CONTRIBUTING.md for development setup, testing instructions, and guidelines.

License

Apache-2.0 License - see License file for details.

Links

References

CytoScnPy's design and implementation are inspired by:

⭐ Star this repo if you find it helpful!

Developed from scratch with assistance from Gemini AI.

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.27-cp314-cp314-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.14Windows x86-64

cytoscnpy-1.2.27-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

cytoscnpy-1.2.27-cp313-cp313-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.2.27-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

cytoscnpy-1.2.27-cp312-cp312-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.2.27-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

cytoscnpy-1.2.27-cp311-cp311-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.2.27-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

cytoscnpy-1.2.27-cp310-cp310-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.2.27-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cytoscnpy-1.2.27-cp310-cp310-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file cytoscnpy-1.2.27-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.2.27-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for cytoscnpy-1.2.27-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 fd4ce243abaed89a0af05814d954bc4bec47f36cd0f0f34dc53a54b5e8264183
MD5 7251fe482066e4f9640f4f20668d1f6e
BLAKE2b-256 4882f4e2cc2d84fa2d3f98c590d5a782b041ced649597ec3943e932532dca908

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.27-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e595f950a58aa910f7a9949f5336380f972b3de33271df1e64f2a306a33022f0
MD5 60bd129be3a2b0feddd9193a63efeadc
BLAKE2b-256 28892c1debd1fede34cae1b4153bdc0b2bbeb8cfadfa5600242fa0eaf3240158

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 81dd9ae93bd270ff45d690df51279e8a20a1797f2ee512283c524b46c5e37fe0
MD5 4e8690175f0f7a2d8596c9afa87ca851
BLAKE2b-256 a8f116bd226b641d87204c3e0a814b772b9e1119321d8de62b9aa95496ad4699

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.27-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for cytoscnpy-1.2.27-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b45bb7bfa0b9b7777740478872a0957cecf0623390faeee7e60fd059595cafad
MD5 20fbb77990e23e2217806ee01c300f39
BLAKE2b-256 0c26a01dc0290afcc1a43c83a3b20495a05b5ce007961b580580e1d1ffa6500d

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.27-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aa68a3654a2b84b39cd628143331b5d58ad247d73d1f7f24c3b6c8085d0f7241
MD5 e38c97d8483530572d4b954f7070b1e6
BLAKE2b-256 43cb621b7ea5f99693c82c658d3b3a8bf495ebe3ee0ae5b022ca40eaa5abcdec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 180991caafc8c3535e1043fabee501e7b2daf83f94aa5ee8cb8cec22b3c3990c
MD5 37fa0d7897a523e93d8e7b00e6a98291
BLAKE2b-256 e20cf7e6004618faf3a864ce6b11b81b0600d13b9ec637b466eef54e921e3791

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.27-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for cytoscnpy-1.2.27-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9167bb5481940f02781103422e25025df27e2c3c23133c8d327ecf48f9cc270d
MD5 ffd1b6644f460c24b401b5704846f53b
BLAKE2b-256 1bf034a672e09539ea6f9df145b0428906c934a3b0967f94ebd5538f4f8aa500

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.27-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9dfb90a732f3b88ad1a0b30b42ca0e98c80ec0100e59e269ad1127f3568f90b3
MD5 04911028f83325611e2edbc5364b2044
BLAKE2b-256 6d987e6750d51ccc98aeadb03c29883be3c04819b1e932f85c39fa2f03e75818

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2bc9ebdf51b86bd5edf1653237dcc582d9fd25977d703981fabf1c4744d0dc89
MD5 0059e967f823a20272523054e7684e10
BLAKE2b-256 8c5464d6b8e5ebd3541b273a223330afb1e27c44e92d3de3476131018b9f1500

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.27-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for cytoscnpy-1.2.27-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7eedd4a4917362b7a8099a528abfe3d0c685019649c1387405d9d0ee2b812dca
MD5 eadb80b78422f169064f5cf97a160200
BLAKE2b-256 235f720e752b857da62792cfa528aceebb98a1271269e9d60d111e7a07cdb319

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.27-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af88dff0c1d6254ff7067cf0f22cdf2b38ddb601980242f01f8d76734f9fa53c
MD5 570aac09463ebf98d01435a2ebf3373c
BLAKE2b-256 aba377d6736a4480275da7284fcd763a8f20f0fff127c321c244ed6cb7f48e03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e52f60e69cc2f28268eed51cbcb8017fc4abdba85ac43ac92a00bc7603e41421
MD5 6df6c054d052d33e0297085aee4bb78e
BLAKE2b-256 f5701e43807dae653e030e159c4cfdc58d7dc61046963efc47bac264bc830c32

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.27-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for cytoscnpy-1.2.27-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1c8571f02dd9125a0b8dad83bbcb21bc8cf53ce65e83dabeae42e00510a6c267
MD5 d37839cc95192e211bfaf8a6c75df410
BLAKE2b-256 75e5d54c7efa216d10130f83defb1a7056644799c466b388e79edd12b0c8f5e3

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.27-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b43a894f73187b780bddcd29f3007f054e8a3e0e1ca6f585e4f638e8f4dcc9c4
MD5 f55c7889a091bc55802ba7dd8df6ef71
BLAKE2b-256 e532d7f6d54cdcdfc613f20128db7f17ff5f939694d9719aeabbb4dc86cfee16

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.27-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.27-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25492cdfc27957acce1e528f0cc255a5a8044ee43db7e3524fb99252fe5ce7e8
MD5 f6127856c94f3cb00a332de54e5cd844
BLAKE2b-256 057e3800c3e6914d2a71929f546d85382acabbd9ba32bd0f8bb5d173df001c0c

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