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

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.2.26-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.2.26-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.2.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.2.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cytoscnpy-1.2.26-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.26-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.2.26-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.12

File hashes

Hashes for cytoscnpy-1.2.26-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7b08af0d024f3b444130da5b0916774e437e777855bc4faa112d1f8cd669642e
MD5 17153d976fb07fa6452dafc6cbffbe58
BLAKE2b-256 8de522a4eb7477e791db16a613ff9bff330622e06320f5b23bef057bbb389fb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e9d48375cb3cf5721872fce3923345f6e496a65e7f1627c50b573e852755058
MD5 162f3f4b6675f33ce1bc1d3f013fd720
BLAKE2b-256 ff03768d3ef046ba96d8cbede4162a5b31bf17730a8b17734b6f6459204bf795

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2af902fd42e934be3b5a841d8f2416f2f0943997f21e6f21f8f59ac6b4858478
MD5 f769fc8388c68362630497f6320de5af
BLAKE2b-256 f1ae3b433af45e7a01f5f9ecfc5331ba98c14db8e2ef1cf2331660bf13999290

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.26-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.12

File hashes

Hashes for cytoscnpy-1.2.26-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fd812441f5489e335718ba99afbbdd20d5c179f54b973b9b23ffcb0ef3c039b3
MD5 3ef62e080d9fe36d402944dcdf8a798d
BLAKE2b-256 eeda2d990b1460575b4d6356bf648d874d2c04d07ca8a295b074f26067b25f98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2114fde022abb37f401edc1ee039046d98b4061bc61158c3b675bf71ae929c16
MD5 a40a026a4ddca5ff8bf3e32f519bb4d5
BLAKE2b-256 e5133f17608f67c0b87cf8b2b7039ca81efe30bb528eda1051604f0535331311

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9c41ed9dc6eaef8d8c0f6abf47eb8e3da504b75288873be675e178a97f3aedd
MD5 0d55cda859f72de23ee41b79d5e5c022
BLAKE2b-256 ad8256e708df3108b33705cfea2e13043a2208e8ca5a13a47fd11c54f05de7bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.26-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.12

File hashes

Hashes for cytoscnpy-1.2.26-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c241a572a2d519802ffa60f28c52cb64dd415d9ec77eb30c913bcaf3b06359fa
MD5 2a738b92a61e5871fe0dc0c456109979
BLAKE2b-256 53c886da4404147196ddb1c519be071487935017dbcdc831b7ecd6b3e9c3939d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 04c88956545b13483b9fc8b0f13a69925e97fa12572debfe610d9d904653bc48
MD5 a9b667fc9b8c3ab86498d43a0ccb8b7b
BLAKE2b-256 430ac65878650d1d565c26973fd8ae5bddb2522143c0e457c71938451824c7a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 99648455f79f3de06b67b73a40f56c01fa47e4458734c7f8f29d63e397a71cb2
MD5 a1fdd74625a7d0f0b5787021628a11fd
BLAKE2b-256 4cb9ad36485c7333ccdc03d1d83376969abb0fe45a49684b0b1ff62b1b97fdbd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.26-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.12

File hashes

Hashes for cytoscnpy-1.2.26-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 febccdcf2e0025a12483ec56cc482e80f16d98810e49fabf9eef7636cea78039
MD5 c125128250e9706c7badc09f52902c6a
BLAKE2b-256 053824d6497d7fb712d0bc4a12331069aa95084021d5bf975a9c033f719bf2be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 337444c8f9a0f6b4139969a40a62c2cb4766861e63413ffebf7072e922c6922b
MD5 01ec43909497ea70a428b81caef14cbf
BLAKE2b-256 65603a5a342d792f0a76580d030a45ae5b8b4b891dc551261f94f3adb5caf937

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.26-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 752bd77ace898b8df4228813e2ef05f18100864affd1c41449129e0893442a5e
MD5 e0bdae9c1adfb62b1a427ed9953da2b3
BLAKE2b-256 6e71a995c335f995b51bdb7768ddd0ade15177dff860a056b221236c4f60d08b

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