Documentation

The pyFlow reference.

pyFlow runs a large, growing subset of Python. Everything on this page runs today and is covered by the engine's test suite. Nothing here is aspirational.

The model is simple: your source is parsed, lowered to one typed dataflow graph, and executed on the substrate. Every operation carries a cost in picojoules.

What it runs

Functions
  • def with positional, default (y=10), and keyword (f(y=5)) arguments
  • Recursion and mutual recursion
  • Return values of any type; multiple returns via tuples
Functional
  • lambda and closures that capture their enclosing variables
  • First-class functions: pass, return, and call them (currying)
  • map, filter, reduce, and sorted / min / max with key=
  • Nested def, hoisted with free-variable capture
Classes
  • class with __init__, instance attributes, and methods
  • obj.attr read and write; obj.method(args) dispatch
  • Constructor defaults and keyword arguments
Control flow
  • if / elif / else, including inside loops
  • while and for (ascending, descending, nested)
  • break, continue, and return inside loops; for / while else
  • with blocks, running __enter__ and __exit__
Data structures
  • Lists: index (negative too), slice, xs[i]=v, nested writes (g[0][1]=v), concat, repeat, and methods (append, extend, insert, sort, pop, reverse)
  • Dicts: literal, access, set, membership, iteration over keys
  • Sets and real tuples, including (1,) and (a, b) == (a, b)
  • Comprehensions: list, dict, set, and several for clauses
  • Generator expressions as arguments: sum(x * x for x in xs)
Generators and errors
  • Generators: yield and yield from
  • Lazy and infinite generators run one step at a time (the resume-model)
  • try / except / finally, raise, return inside try, and exceptions from called functions
Text and numbers
  • f-strings with format specs (f"{x:.2f}", f"{n:05d}")
  • String iteration, indexing, and methods (upper, split, join, ...)
  • int / float parsing, Python floored % and //, ** power, bitwise & | ^ << >>
Assignment
  • Augmented (x += 1, xs[i] += 1)
  • Parallel / tuple (a, b = b, a) and chained (a = b = 0)
  • Module-level globals and top-level control flow

Builtins

Around thirty builtins and methods are wired directly into the runtime, including the list, dict, string, and set operations most programs reach for:

print · len · str · int · float · bool · abs · round · sum · min · max · sorted · reversed · range · list · enumerate · zip · any · all · map · filter · reduce · in / not in · dict.get / keys / values / items · list.append / extend / insert / sort / reverse · str.upper / lower / strip / replace / split / join / count / startswith / endswith · set / union / intersection / difference · format

The energy model

Each operation is priced from an analytical prior in picojoules. A multiply is not the same cost as an add, and division is far more. The receipt is the sum over the graph.

# the analytical op prior, in picojoules
Add, Sub, comparison, and/or, not   1 pJ
Mul                                 14 pJ
Div, Rem (modulo)                   72 pJ
literal load                        45 pJ
# run it and read the bill
py     : def poly(a, b): return (a + b) * (a - b)
call   : poly(5, 3)
result : 16
energy : 16 pJ

   Add                   1 pJ
   Sub                   1 pJ
   Mul                  14 pJ

Today the receipt is an analytical estimate. The flowg backend compiles the same graph to native code with an exact per-instruction picojoule count, which turns the estimate into a measurement. See the roadmap.

Current limits

Correctness is measured, not asserted. A corpus of ordinary Python programs runs through both CPython and pyFlow with the output compared byte for byte; 71 of 72 match exactly, and none of the rest returns a different answer. What is left is refused outright: