Native Python source analysis with typed tokens, ASTs, diagnostics, and import sites. Requires Python 3.12 or newer and uses only the standard library.
from parse_py3 import absolute_module, parse
result = parse("from .helpers import run\n")
site, = result.imports
assert absolute_module(site, package="example.tools") == "example.tools.helpers"
The result retains decoded source text and the native AST. Tokens preserve the corresponding source slices, including original newline spellings. Spans are half-open, with one-based lines and zero-based byte columns and absolute offsets in the UTF-8 encoding of the decoded source. Byte input honors Python encoding declarations. Source without a valid syntax tree returns a diagnostic.
Import sites include aliases and relative levels from every static import statement, including nested and conditional statements. Resolution uses explicit package names. Filesystem lookup, dependency policy, compiler profiles, and runtime import tracing belong to callers. Use check_compile=True for scope checks that CPython performs after parsing. Neither mode executes source code.
The initial source contract is tracked in Wispsy Composition.