Skip to main content

PCResolve

PyPI License: MIT

Project-level Python static analysis for API ownership and library usage provenance.

Status

PCResolve 1.0.8 provides stable ownership and symbol-provenance output plus an opt-in experimental value-flow API for parameters, receivers, returns, and supported mutation effects. It also supports single-file ownership analysis. The implementation is reorganized into frontend, shared-fact, ownership and value-flow packages while keeping the public Python API, legacy flat module paths, and ownership schema_version="1.0" compatible.

This release adds optional analysis resource limits and repeated-analysis fact reuse, and improves value-flow precision and analysis performance.

Existing Python callers can keep their package-level imports and earlier flat module paths such as pcresolve.cross_file. See the Python API contract.

The experimental flow-0.2 API includes bounded source constructor/lookup, incoming-call context, generated-dispatch, scalar-truth and entry-alias facts. These additions retain explicit source assumptions and unsupported-operation boundaries; the stable ownership schema remains 1.0.

What is PCResolve?

PCResolve is a project-level Python static analyzer for API ownership and library usage provenance. It classifies Python API call expressions and traces the symbols that feed them to their owner: an import-backed library, Python-provided API, project-local definition, or unknown.

It answers questions such as:

  • Which import-backed libraries and Python APIs does this project call?
  • Which call expression belongs to numpy, requests, json, pathlib, flask, or another top-level library owner?
  • Which calls are library-owned, Python-provided, local, or unknown?
  • How did a local symbol, return value, attribute, parameter, or container element acquire library provenance?
  • Where is the analysis certain, and where are there multiple possible origins?

PCResolve is designed for CI pipelines, audit workflows, IDE integration, and large-scale codebase scanning. It has zero runtime dependencies and supports Python 3.9+.

Quick Start

pip install pcresolve
pcresolve /path/to/project

For machine-readable output:

pcresolve /path/to/project --json

To analyze just one Python source file:

pcresolve a.py
pcresolve a.py --json

Ownership analysis accepts relative or absolute .py and .pyi paths. File mode analyzes only the selected file. Use a project directory when provenance needs to be traced across local imports. Both inputs use the same ownership rules; with the same source set and module mapping root, call classifications are the same.

To analyze explicit parameter and return dependencies from one entry function:

pcresolve /path/to/project --value-flow --entry package.module:function --depth 2 --json
pcresolve /path/to/module.py --value-flow --entry module:function --depth 2 --json

The value-flow positional input accepts a project directory or one .py/.pyi file. A file selects only that source and uses its basename as the module name unless --import-root supplies a package root. Use repeated --source-file options when selecting multiple explicit files.

Usage

CLI

pcresolve /path/to/project                         # human-readable summary
pcresolve /path/to/project --json                  # full provenance JSON
pcresolve /path/to/project --json-summary          # compact JSON summary
pcresolve /path/to/a.py --json                     # one file, full provenance JSON
pcresolve /path/to/project --explain-library numpy
pcresolve /path/to/project --explain-call "np.array"
pcresolve /path/to/project --explain-symbol df

--explain-call NAME matches a callable's name or resolved path, using exact names or dotted path suffixes. For example, Series selects Series(...), pd.Series(...), and aliases whose resolved path ends in .Series. Arguments, string contents, partial names such as ABCSeries, and methods such as Series.to_numpy(...) do not match that query. Matching is case-sensitive.

Choose one output mode: --json, --json-summary, --debug-dump, or one --explain-* option. Conflicting modes and empty explain queries are CLI errors. JSON output rejects the text controls --verbose, --quiet, and --usage-summary. Explain output accepts --verbose to include diagnostics; --quiet and --usage-summary are summary controls. --debug-dump also rejects --quiet. Long options require their complete spelling; abbreviations such as --js and --json-f are rejected.

--top N requires a non-negative integer; 0 means unlimited. It limits libraries in text and usage summaries, calls and symbols in explain output, and per-library file details in summary JSON. Counts always cover the complete analysis. Full JSON and the debug dump retain all facts, so --top is rejected with those modes unless it applies to a usage summary appended to the debug dump. Diagnostics appear once; --quiet --verbose shows only error diagnostics and the skipped-file count when diagnostics are present. --strict makes the causing error diagnostics visible in every text mode.

Use either a positional input path or --stdin; providing both is an error. In value-flow mode, --stdin also conflicts with --source-file. Missing and unsupported inputs are argument errors and exit with status 2.

Python API

from pcresolve import analyze_project

result = analyze_project("/path/to/project")
# Or select one source file: result = analyze_project("a.py")

for call in result.all_api_calls:
    print(call.expression, "->", call.top_library)
    print("reason:", call.reason)
    print("confidence:", call.confidence)

Experimental value flow uses a separate result contract:

from pcresolve import FlowAnalyzer, FunctionRef

analyzer = FlowAnalyzer(project_root="/path/to/project")
flow = analyzer.analyze(
    FunctionRef(module="package.module", qualname="ClassName.method"),
    max_depth=2,
)

Performance controls

Optional resource controls apply to ownership and value-flow analysis:

pcresolve ./my_project --max-seconds 60 --max-work 1000000 --max-memory-mb 1024

Limits are cooperative checks during analysis; defaults are unrestricted. Exceeded limits produce an error without presenting a partial result as complete. Python callers can pass AnalysisLimits to either analyzer and catch AnalysisLimitExceeded. These controls do not cover output serialization or later queries on a returned result.

For repeated ownership analysis, ProjectAnalyzer(root, reuse_source_facts=True) can reuse pristine facts from unchanged files. This optional mode copies mutable state for each run and still recomputes cross-file semantics. It trades additional memory and first-run copying for reduced visitor work; it is disabled by default. Flow automatically reuses unchanged file-index facts while resetting query state.

Run python scripts/perf_scalability.py --sizes 10 100 500 --repeats 5 --independent-samples 5 --output reports/performance.json to measure cold, cached, unchanged and single-file-edit analysis. Each sample runs in an isolated process and records peak RSS alongside raw timing and output fingerprints.

Output

In ownership mode, --json returns the stable provenance schema. With --value-flow, it returns the separate experimental flow-0.2 schema.

The main output sections are:

Section Description
all_api_calls Every call expression with source location, resolved owner, reason, confidence, alternatives, and decorator evidence.
all_symbol_provenance Provenance records for imports, variables, parameters, return values, attributes, container items, and decorators.
library_usage Per-library aggregation of calls, symbols, files, reason counts, and confidence ranges.
diagnostics Non-fatal parse, encoding, and tracing diagnostics.

For the complete JSON contract, see docs/output-contract.md.

Analysis Capabilities

PCResolve reports two connected views: API call ownership and symbol provenance. API calls are the primary classification target. Symbol provenance explains the imports, aliases, assignments, parameters, returns, attributes, containers, and decorators that support each classification.

Supported patterns include:

  • direct imports, aliases, wildcard imports, and re-exports;
  • cross-file symbol tracing through local modules;
  • function return propagation and parameter binding;
  • class construction, instance attributes, and method call provenance;
  • dict/list/tuple/set container items and iteration;
  • decorator calls and decorated_by evidence;
  • ambiguous flows reported through alternatives instead of silent guessing.

top_library represents the primary owner of the callable or receiver object for a call expression. Additional evidence is reported separately through fields such as alternatives, decorated_by, and symbol provenance records.

The experimental FlowAnalyzer answers a separate dependency question. It records actual-to-formal argument bindings, entry-parameter flows into calls, receiver flows, supported mutations and effects, and call-result flows into caller returns. Missing paths are reported as unknown when analysis boundaries remain; they are not proofs that no runtime flow exists.

Validation

The current analyzer is validated against locked call-site ground truth from 42 real-world projects:

ground-truth records:  5,788
primary hits:          5,548
primary misses:          240
primary recall:        0.959
false positives:       0

The regression gate checks complete AST call coverage, locked annotations, stable snapshots, clean library keys, and golden JSON output.

The separate value-flow development matrix covers 83 entry functions and 472 binding, call, parameter, receiver, return, and boundary checks. All currently match their reviewed expectations. This is a regression matrix used to guide implementation, not a held-out estimate of real-project accuracy.

Limitations

PCResolve is static by design. It does not execute project code and does not model arbitrary runtime reflection, monkey patching, dynamic imports, descriptors, or full library internals.

When a single origin cannot be determined confidently, PCResolve reports conservative results and preserves alternative evidence rather than choosing an unsupported library owner.

Value-flow expansion is bounded by the selected source files, call depth, summary budget, and call-site budget. Dynamic dispatch, general heap behavior, external implementations, and unsupported Python constructs remain explicit boundaries.

Documentation

Development

pip install -e ".[dev]"
python -m pytest tests/ -v
python scripts/evaluate_ground_truth.py --view all
python scripts/verify_ground_truth_calls.py --coverage-only
python scripts/refresh_ground_truth_snapshots.py --all --check

PCResolve uses only the Python standard library at runtime. Tests use pytest.

License

PCResolve is licensed under the MIT License. See LICENSE for details.

Metadata

Release files for pcresolve 1.0.8

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

Source distribution (sdist)

Source distribution for pcresolve 1.0.8
File Size Uploaded Provenance Actions
pcresolve-1.0.8.tar.gz 1.1 MB Without provenance Details for pcresolve-1.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pcresolve 1.0.8
File Interpreter ABI Platform Actions
pcresolve-1.0.8-py3-none-any.whl Python 3 none any Details for pcresolve-1.0.8-py3-none-any.whl

Total release size: 1.9 MB

Release files / pcresolve-1.0.8.tar.gz

Download URL pcresolve-1.0.8.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
214a7203138da2c8e61266c1fdf07b5831312068123459f04037c8670df63f7c
BLAKE2b-256 checksum
How to use checksums
e1b2aff022202e37df56cc991749346a83d0c6c2eebdd5e0a38952e08216fe30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / pcresolve-1.0.8-py3-none-any.whl

Download URL pcresolve-1.0.8-py3-none-any.whl
Size 843.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fa92c7356903f1af57f58f3add73d1b977b293d7531a6307d707eaae2c836f7
BLAKE2b-256 checksum
How to use checksums
8c0de6e38deaaadde5e36b9cc6af661500c9975c0cf4889444830fcf4846cdb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Security for pcresolve 1.0.8

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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