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{pyflow2026,
  title         = {PyFlow: An Inter-procedural Static Analysis Framework for Python},
  author        = {Gu, Zinan and Yan, Haoxiang and Yao, Peisen},
  year          = {2026},
  eprint        = {2608.07026},
  archivePrefix = {arXiv},
  doi           = {10.48550/arXiv.2608.07026},
  url           = {https://arxiv.org/abs/2608.07026}
}

What PyFlow includes

  • Intermediate representations: seven-instruction MIR, 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, alias analysis, and concolic test-input generation

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
ast-scanner 0.623 0.400 0.487 0.579
ast-dataflow 0.849 0.842 0.845 0.846
cpg 0.792 0.792 0.792 0.792
ifds 0.852 0.767 0.807 0.817

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]"

The native MIR-based PyCG algorithm is included in the standard installation. If you want the optional upstream 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

# Lower source to the seven-instruction MIR without executing the source
pyflow ir input.py --dump-mir --dump-format json --dump-output out/

# Generate a call graph
pyflow callgraph input.py

# Generate a native PyCG-style call graph from MIR
pyflow callgraph input.py --algorithm pycg-mir

# Generate a call graph with the optional upstream PyCG package
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

# Generate branch-covering integer inputs for a pure function named main
pyflow concolic input.py --inputs '[0]' --json

# 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/

See CLI.md for the command reference, docs/source/ir/mir.rst for MIR, the native PyCG API, and implementation limits, docs/source/lsp.rst for LSP, MCP, and semantic-query integration, 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

Metadata

Release files for pyflow-analysis 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyflow-analysis 0.1.2
File Size Uploaded Provenance
pyflow_analysis-0.1.2.tar.gz 2.1 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyflow-analysis 0.1.2
File Interpreter ABI Platform
pyflow_analysis-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 4.6 MB

Release files / pyflow_analysis-0.1.2.tar.gz

Download URL pyflow_analysis-0.1.2.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
2e0ee7e508a0a387dacc29ce90bc9e55b544e30ee07d5f88ba574ac38f99d1d9
BLAKE2b-256 checksum
How to use checksums
22525c6c137cd64b2244d8a88f6ba84a5ac8acbfecbd310550e8c34e8bc7e4d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / pyflow_analysis-0.1.2-py3-none-any.whl

Download URL pyflow_analysis-0.1.2-py3-none-any.whl
Size 2.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
59ff025078a896d2fd087a227dc10a1a44dbfacb844cca1e5be0c5fb8a3d7161
BLAKE2b-256 checksum
How to use checksums
29e47b15674aad8d58ed9ad9b8c6927e7815864c977e04c57e76dcbd453fa5f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for pyflow-analysis 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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