Skip to main content

Generated Python API Reference

This page is generated from the public Python API signatures and docstrings. Update the package source first, then regenerate with npm run docs:api from site/.

Public Surface

APIUse it for
runRun PyPlyne source once without managing a persistent session.
run_fileRun a .pyplyne file once without managing a persistent session.
PyPlyneSessionPersistent PyPlyne execution environment.
PyPlyneExecutionResultResult object returned by PyPlyneSession.run.
parse_sourceParse PyPlyne source text into a Lark parse tree.
compile_astCompile a PyPlyne parse tree into a Python AST module.

run

run(
source: 'str',
context: 'dict[str, Any] | None' = None,
filename: 'str' = '<pyplyne>',
*,
capture_output: 'bool' = True,
raise_on_error: 'bool' = True,
store_result: 'bool' = True,
) -> 'PyPlyneExecutionResult'

Run PyPlyne source once without managing a persistent session.

Parameters

NameDescription
sourcePyPlyne source code to execute.
contextOptional Python names and values available to the source.
filenameVirtual filename used in diagnostics.
capture_outputCapture stdout/stderr into the result object. When false, output goes to the process streams and the result stream fields are empty.
raise_on_errorRaise failures instead of returning a non-ok result.
store_resultCapture the final expression result.

Returns

TypeDescription
PyPlyneExecutionResultCaptured output, result value, shapes, and any non-raised error from the one-shot run.

run_file

run_file(
path: 'str | Path',
context: 'dict[str, Any] | None' = None,
*,
capture_output: 'bool' = True,
raise_on_error: 'bool' = True,
store_result: 'bool' = True,
) -> 'PyPlyneExecutionResult'

Run a .pyplyne file once without managing a persistent session.

Parameters

NameDescription
pathPath to the .pyplyne source file.
contextOptional Python names and values available to the file.
capture_outputCapture stdout/stderr into the result object. When false, output goes to the process streams and the result stream fields are empty.
raise_on_errorRaise failures instead of returning a non-ok result.
store_resultCapture the final expression result.

Returns

TypeDescription
PyPlyneExecutionResultCaptured output, result value, shapes, and any non-raised error from the one-shot file run.

PyPlyneSession

PyPlyneSession(globals_dict: 'dict[str, Any] | None' = None) -> 'None'

Persistent PyPlyne execution environment.

A session keeps Python globals, imports, runtime helpers, known df/seq shapes, and the most recent expression result across runs.

Parameters

NameDescription
globals_dictInitial names and values to add to the session environment.

PyPlyneSession.run

run(
self,
source: 'str',
filename: 'str | None' = None,
*,
capture_output: 'bool' = True,
raise_on_error: 'bool' = True,
store_result: 'bool' = True,
) -> 'PyPlyneExecutionResult'

Compile and execute PyPlyne source in this persistent session.

Parameters

NameDescription
sourcePyPlyne source code to execute.
filenameOptional virtual filename used in diagnostics.
capture_outputCapture stdout/stderr into the result object. When false, output goes to the process streams and the result stream fields are empty.
raise_on_errorRaise failures instead of returning a non-ok result.
store_resultCapture the final expression result and store it as _. Assignment-only snippets do not replace _.

Returns

TypeDescription
PyPlyneExecutionResultCaptured output, result value, shapes, and any non-raised error.

Raises

TypeDescription
ExceptionRe-raises parse, compile, or runtime failures when raise_on_error is true.

PyPlyneSession.load_file

load_file(self, path: 'str') -> 'PyPlyneExecutionResult'

Run a .pyplyne file inside this session.

load_file uses the default run behavior, including raising on errors. Read the file and call run(..., raise_on_error=False) when non-raising file execution is needed.

Parameters

NameDescription
pathPath to the .pyplyne source file.

Returns

TypeDescription
PyPlyneExecutionResultResult from running the file contents.

PyPlyneSession.get

get(self, name: 'str', default: 'Any' = MISSING) -> 'Any'

Return a named value from the session environment.

Parameters

NameDescription
nameName to read from the session.
defaultOptional fallback returned when the name is missing.

Returns

TypeDescription
AnyThe live Python object stored in the session.

Raises

TypeDescription
KeyErrorIf the name is missing and no default was supplied.

PyPlyneSession.get_df

get_df(self, name: 'str') -> 'pl.DataFrame'

Return a named value as a Polars DataFrame.

Parameters

NameDescription
nameName to read from the session.

Returns

TypeDescription
polars.DataFrameThe live DataFrame stored in the session.

Raises

TypeDescription
KeyErrorIf the name is missing.
TypeErrorIf the named value is not a Polars DataFrame.

PyPlyneSession.get_seq

get_seq(self, name: 'str') -> 'list[Any] | tuple[Any, ...]'

Return a named value as a sequence.

Parameters

NameDescription
nameName to read from the session.

Returns

TypeDescription
`listtuple`

Raises

TypeDescription
KeyErrorIf the name is missing.
TypeErrorIf the named value is not a list or tuple.

PyPlyneExecutionResult

PyPlyneExecutionResult(
filename: 'str',
stdout: 'str',
stderr: 'str',
result: 'Any' = None,
error: 'BaseException | None' = None,
phase: 'str | None' = None,
traceback: 'str' = '',
shapes: 'dict[str, str] | None' = None,
) -> None

Result object returned by PyPlyneSession.run.

ok is true when execution completed without an error. When ok is false, phase, error, traceback, and stderr describe what failed.

Fields

FieldTypeDefaultDescription
filenamestrrequiredVirtual filename used for diagnostics and tracebacks.
stdoutstrrequiredText written to standard output while the source ran.
stderrstrrequiredText written to standard error while the source ran.
resultAnyNoneFinal expression value when store_result is true and the snippet ends with an expression.
error`BaseExceptionNone`None
phase`strNone`None
tracebackstr''Python traceback text for captured errors.
shapes`dict[str, str]None`None

Properties

PropertyDescription
okWhether the run completed without a captured error.

parse_source

parse_source(source: 'str', filename: 'str' = '<pyplyne>') -> 'Tree'

Parse PyPlyne source text into a Lark parse tree.

Parameters

NameDescription
sourcePyPlyne source code to parse.
filenameVirtual filename used in diagnostics.

Returns

TypeDescription
TreeLark parse tree ready to pass to compile_ast.

Raises

TypeDescription
PyPlyneParseErrorSource text is not valid PyPlyne syntax.

compile_ast

compile_ast(
tree: 'Tree',
filename: 'str' = '<pyplyne>',
symbol_kinds: 'dict[str, str] | None' = None,
) -> 'ast.Module'

Compile a PyPlyne parse tree into a Python AST module.

Parameters

NameDescription
treeParse tree returned by parse_source.
filenameVirtual filename copied into generated AST nodes.
symbol_kindsOptional shape registry used to validate df and seq pipelines across session runs.

Returns

TypeDescription
ast.ModulePython AST module that can be compiled with compile.

Raises

TypeDescription
SyntaxErrorThe parse tree contains an invalid PyPlyne construct.