Skip to main content

PyFlow: Static Analysis for Python

PyFlow is a program analysis framework for Python. It combines program analysis infrastructure, experimental optimization passes, and security checking in a single research-oriented toolkit.

Current status: alpha. The project already contains substantial analysis and testing infrastructure, but APIs, pass behavior, and CLI details are still evolving.

If you use pyflow in your research or work, please cite the following:

@misc{pyflow2025,
  title = {pyflow: A Program Analysis Framework for Python},
  author = {ZJU Programming Languages and Automated Reasoning Group},
  year = {2025},
  url = {https://github.com/ZJU-PL/pyflow},
  note = {Program analysis, compiler}
}

What PyFlow includes

  • Intermediate representations: CFG, CDG, DDG, PDG, CPG, lowered data flow IR, and a shared store graph model
  • Program analysis: call graph, IFDS, alias, IPA, CPA, shape, lifetime, and type-analysis infrastructure
  • Optimization pipeline: modular passes such as simplify, method-call optimization, cloning, argument normalization, and load/store elimination
  • Security checking: ast pattern, ast-dataflow, cpg, and ifds security analysis
  • Supply-chain analysis: local SBOM generation, distribution integrity auditing, and dependency metadata extraction
  • CLI tooling: commands for optimization, call graph generation, IR dumps, security, supply-chain, and alias analysis

Evaluation results

Security analysis engines evaluated on the PySASTBench microbenchmark (ICSE 26):

python3 evaluation/pysastbench/bench_micro.py --timeout 45 --workers 16
Engine Precision Recall F1 Accuracy Mean(s)
ast-scanner 0.623 0.400 0.487 0.579 0.49
ast-dataflow 0.849 0.842 0.845 0.846 0.58
cpg 0.792 0.792 0.792 0.792 1.56
ifds 0.852 0.767 0.807 0.817 3.57

Installation and Usage

Prerequisites

  • Python 3.10 or newer
  • Graphviz (for visualization features)

Install from source

git clone https://github.com/ZJU-PL/pyflow.git
cd pyflow
pip install -e .

For development, install the dev extras:

pip install -e ".[dev]"

If you want the optional PyCG-backed call-graph algorithm, install:

pip install -e ".[dev,callgraph]"

Usage

# Dump IR for a specific function
pyflow ir input.py --dump-ast function_name

# Generate a call graph
pyflow callgraph input.py

# Generate a PyCG-backed call graph
pyflow callgraph input.py --algorithm pycg

# Run security analysis (fast AST scan)
pyflow security input.py

# Run AST-based interprocedural taint dataflow
pyflow security input.py --engine ast-dataflow

# Run IFDS-backed interprocedural security analysis
pyflow security input.py --engine ifds --sources input --sinks eval

# Run CPG-based security analysis
pyflow security input.py --engine cpg --framework flask

# Run alias analysis (flow-sensitive heap or k-CFA pointer)
pyflow alias input.py --verbose

# Start the LSP server (Content-Length framed JSON-RPC)
pyflow lsp --root . --mode full

# Start the MCP server (newline-delimited JSON-RPC over stdio)
pyflow mcp --root . --mode full

# Run a one-shot semantic query
pyflow query . --get-callers package.module.function --pretty

# Generate a CycloneDX SBOM from local package metadata
pyflow supply-chain sbom package/

The scanner is offline by design. Production CI is responsible for refreshing and authenticating OSV snapshots; --osv-trusted-digest binds data to trusted configuration while --osv-max-age-days enforces freshness. Install the optional supply-chain dependency group for JSON Schema and Sigstore tooling.

See CLI.md for the command reference, docs/source/lsp.rst for LSP, MCP, and semantic-query integration, docs/type-inference.md for the standalone static type-inference engine, and docs/ for broader project documentation.

Running Tests

# Run the default unit-focused test suite
pytest

# Run integration tests explicitly
pytest -m integration tests/integration

# Run focused areas
pytest tests/ir
pytest tests/frontend
pytest tests/api
pytest tests/checker

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyflow_analysis-0.1.1.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyflow_analysis-0.1.1-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

File details

Details for the file pyflow_analysis-0.1.1.tar.gz.

File metadata

  • Download URL: pyflow_analysis-0.1.1.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pyflow_analysis-0.1.1.tar.gz
Algorithm Hash digest
SHA256 52e29f6c8332654a1daa04a177b8a7d846b2db68b604b9ccbda5a6f11d1be2c6
MD5 1e18838da49c76b475787a04da987ee5
BLAKE2b-256 6dfd4f882bbe8c8cb6d5e77bbad1b0d5c22cb1a0cd574efef94971fe8a50b01a

See more details on using hashes here.

File details

Details for the file pyflow_analysis-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyflow_analysis-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 938efd2dad81a0653ffef4a744b1c7297c8d5b4fb2aa0cfbb02b89736eb52cc8
MD5 bbbc48aeb3cbb1c273728c4c0092bc5b
BLAKE2b-256 35c0075bef9531ddb9539f626efb5cf492a0d361f0cf799e5da66b87a764ebc2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page