py-ast - v1.16.0
    Preparing search index...

    Function parsePython

    • Parse Python source code and return an AST (simplified API).

      Thin wrapper over parse that accepts a smaller, more convenient options shape.

      Parameters

      • source: string

        The Python source code to parse

      • Optionaloptions: { filename?: string; comments?: boolean }

        Optional parsing options

        • Optionalfilename?: string

          The filename to attribute in error messages (default: '<unknown>')

        • Optionalcomments?: boolean

          Whether to attach comment nodes to the tree

      Returns Module

      The parsed module's AST

      If source contains a syntax error

      import { parsePython } from "py-ast";

      const tree = parsePython("x = 1 + 2");