Keywords: lib

# 19.1 The basic interface

The top-level of the package defines four functions. If you import `compiler`, you will get these functions and a collection of modules contained in the package.

`parse`(buf)
  Returns an abstract syntax tree for the Python source code in buf. The function raises SyntaxError if there is an error in the source code. The return value is a `compiler.ast.Module` instance that contains the tree.

`parseFile`(path)
  Return an abstract syntax tree for the Python source code in the file specified by path. It is equivalent to `parse(open(path).read())`.

`walk`(ast, visitor[, verbose])
  Do a pre-order walk over the abstract syntax tree ast. Call the appropriate method on the visitor instance for each node encountered.

`compile`(source, filename, mode, flags=None, dont_inherit=None)
  Compile the string source, a Python module, statement or expression, into a code object that can be executed by the exec statement or `eval()`. This function is a replacement for the built-in `compile()` function.

  The filename will be used for run-time error messages.

  The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression.

  The flags and dont_inherit arguments affect future-related statements, but are not supported yet.

`compileFile`(source)
  Compiles the file source and generates a .pyc file.

The `compiler` package contains the following modules: `ast`, `consts`, `future`, `misc`, `pyassem`, `pycodegen`, `symbols`, `transformer`, and `visitor`.