Skip to main content

A static compiler for Python

Project description

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

  • Program analysis: CFG, call graph, IFDS/dataflow, IPA, CPA, shape, and lifetime analysis infrastructure
  • Optimization pipeline: modular passes such as simplify, method-call optimization, cloning, argument normalization, and load/store elimination
  • Security checking: pattern-based and semantic 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

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

# Basic optimization pipeline
pyflow optimize input.py

# 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 security analysis with CPA-backed engine
pyflow security input.py --engine cpa

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

# Run CPG-based context-sensitive 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 a CycloneDX SBOM from local package metadata
pyflow supply-chain sbom package/

# Audit archives and distribution metadata for issues
pyflow supply-chain audit . --recursive

See CLI.md for the command reference 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/frontend
pytest tests/api
pytest tests/checker

Development

The repository is organized around a few major subsystems:

  • src/pyflow/analysis: core analysis engines such as call graph, CFG, DDG, IFDS, alias (flow-sensitive heap + k-CFA pointer), IPA, CPA, PDG, shape, and lifetime analysis.
  • src/pyflow/application: orchestration code including compiler context, pipeline execution, and the pass manager.
  • src/pyflow/api: query-facing interfaces and entrypoint construction.
  • src/pyflow/checker: pattern-based, semantic, and supply-chain analysis modules plus output formatters.
  • src/pyflow/cli: command-line entrypoints for optimization, call graph, IR, alias, security, and supply-chain analysis.
  • src/pyflow/frontend: source-driven extraction, dependency resolution, object loading, and stub handling.
  • src/pyflow/language: Python IR/AST support, module-handling utilities, and AST tooling (cyclomatic complexity, decorator/visitor utilities).
  • src/pyflow/optimization: optimization and simplification passes.
  • src/pyflow/stats: statistics collection and reporting for analysis results.
  • src/pyflow/stubs: builtin/runtime modeling used during analysis.
  • src/pyflow/util: foundational utility library (OrderedSet, canonical objects, TVL, type dispatch, graph algorithms).
  • tests: focused coverage for analysis, frontend, checker, integration, and API regressions.

Project maturity and expectations

PyFlow is best viewed today as an ambitious, actively developed framework for research, experimentation, and advanced static-analysis prototyping. The codebase has broad subsystem coverage and a large test suite, but documentation and some subsystems are still catching up with the implementation. If you are evaluating the project, expect strong technical depth with some rough edges.

Project details


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.0.tar.gz (1.6 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.0-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyflow_analysis-0.1.0.tar.gz
  • Upload date:
  • Size: 1.6 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.0.tar.gz
Algorithm Hash digest
SHA256 58fa206cb502e72306debbb5204cc48ae48844be837785670e49a459e1914fc5
MD5 692d9b201810629c58e6231f123979f5
BLAKE2b-256 349a4bcee411a67cef22b7c8e9918c67be263fc2a910da240a9f2cf2bb8b46da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyflow_analysis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ccc67c441d554847b83bd4da986779410c0785e45c950f3d7effa7abf2d1723
MD5 cabe4c8c38f8f9664f76566220a4ae53
BLAKE2b-256 9b1517e42769a99ba0ad4f355d856711762b5c736fb7642081f47a2675010d0b

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