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

    Function toSource

    • Convert an AST back to Python source code.

      Parameters

      • node: ASTNodeUnion

        The AST node to unparse

      • indent: string = " "

        The indentation string (default: 4 spaces)

      Returns string

      The generated Python source code

      import { parseModule, toSource } from "py-ast";

      const tree = parseModule("x=1");
      console.log(toSource(tree)); // "x = 1"