A pure functional subset of Python for scientific computing

A versioned standard with a formal grammar, formal semantics, and a reference implementation for a mutation-free subset of Python.

Overview

PurePy defines a pure, mutation-free subset of Python. PurePy is aimed initially at researchers in programming languages and computer science education, and is intended to grow into a common language for scientific computing, supporting portable applications in modelling, data processing, analysis, and visualisation.

The standard defines a versioned formal grammar, a formal semantics, and a reference implementation. Every compliant implementation accepts any valid PurePy program and behaves according to the formal semantics.

from dataclasses import dataclass

@dataclass
class Point:
    x: int
    y: int

def describe(p: Point) -> str:
    kind: str
    match p:
        case Point(0, 0):
            kind = "origin"
        case Point(x, y):
            kind = "point"
    return kind

print(describe(Point(3, 4)))
The declaration kind: str is mandatory. As with blank final variables in Java, later assignments to kind are treated as deferred initialisation. Reassignment on a given branch is therefore not permitted.

Why PurePy

Pure & functional

Mutation-free; functions are referentially transparent. All variable resolution is static.

Statically typed

Mandatory type annotations and a type system which accepts only programs well-typed under mypy.

Pythonic

A strict subset of Python: every valid PurePy program is valid Python, and runs with exactly the same runtime behaviour.

Formally specified

Well-formedness rules and operational semantics mechanised in Isabelle/HOL, with proof of soundness.

Portable

Python dialects are compliant by definition, checked on CPython, GraalPy and Pyodide. Research languages like Fluid and Fortl are too.

For science and education

Reproducible, deterministic, and easy to reason about, for researchers developing new Python-based languages or students learning to program.