Skip to main content

Static analysis tool for tracing Python API calls to their origin library

Project description

PCResolve — Python API Call Chain Tracing

Static analysis tool that traces every API call in a Python project back to its origin library (e.g. requests, numpy, flask) or identifies it as local / python builtin.

PyPI License: MIT

Installation

pip install pcresolve

For development:

pip install -e .

No third-party dependencies — pcresolve uses only the Python standard library (ast, os, sys, builtins, copy, typing).

Requires Python 3.9+.

Quick Start

CLI

# Human-readable output
pcresolve /path/to/project

# JSON output
pcresolve --json /path/to/project

# Or as a module
python -m pcresolve /path/to/project

Library API

from pcresolve import analyze_project, analyze_source

# Analyze an entire project
result = analyze_project("/path/to/project")
for call in result.all_api_calls:
    print(f"{call.expression} -> {call.top_library}")

# Analyze a single source string
code = '''
import requests
resp = requests.get("https://example.com")
'''
result = analyze_source(code, file_path="example.py")
for sym, top in result.symbols.items():
    print(f"{sym} -> {top}")

Public API

Name Description
analyze_project(root) Full project analysis, returns ProjectAnalysis
analyze_source(code) Single-file analysis, returns FileAnalysis
scan_directory(root) Discover .py/.pyi files, returns list[str]
ProjectAnalyzer(root) Orchestrator class (step-by-step control)
SingleFileAnalyzer() AST visitor class for one file
ModuleMapper(root) File-path to module-name bidirectional mapping
SymbolTable() Per-symbol chain tracking
FileScanner() File system scanner

Output Types

@dataclass
class ApiCall:
    expression: str       # "requests.get('url')"
    top_library: str      # "requests", "python", "local"
    base_symbol: str      # Root symbol name
    chain: list           # Resolution chain

@dataclass
class FileAnalysis:
    file_path: str
    module_name: str
    symbols: dict         # symbol -> top-level source
    chains: dict          # symbol -> resolution chain
    api_calls: list[ApiCall]

@dataclass
class ProjectAnalysis:
    project_root: str
    files: list[FileAnalysis]
    all_api_calls: list[ApiCall]

Supported Patterns

  • Direct import + direct call
  • from/as import + alias call
  • Variable binding / container storage (dict, list, tuple, set)
  • partial / lambda wrappers
  • Class encapsulation & inheritance
  • Cross-file shared third-party instances
  • Decorator pattern
  • Context managers / protocols (with, async with)
  • Chained calls / fluent API
  • getattr / importlib.import_module dynamic calls

Running Tests

python -m pytest tests/ -v

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

pcresolve-1.0.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

pcresolve-1.0.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file pcresolve-1.0.1.tar.gz.

File metadata

  • Download URL: pcresolve-1.0.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pcresolve-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7067dc51f056cc1c27af819f938861aede2c1261cf6adc232d07c56bd6c93152
MD5 a5b413136deaea51d51acbe8063afea2
BLAKE2b-256 424c391ab37710e51fe7039274bcd90dd81a65c6a0a62f984daf35ff685e27d5

See more details on using hashes here.

File details

Details for the file pcresolve-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pcresolve-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pcresolve-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c15e90c5c4ee9f26824f9eec45e8b84338627c51483aa8d1e54e02b31dc3443
MD5 e881d4e35e1958783f1b38e12ef5066a
BLAKE2b-256 20d95c0027dd8849cac7b2d468e79bedff110136360be0fd2192d1c52e183dae

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