Meta-program
Python objects

Ordinary objects are built and then sealed — the call that produced them is gone. A pg.Object behaves like any Python object and keeps the structure it was built from — so your code can generate, inspect, diff, patch and tune it as easily as it runs it.

$pip install pygx
Read the docs
Python 3.12–3.14 · GIL-free 3.14t Native Rust core Apache 2.0
trainer.py
Battle-tested lineage
Born at Google Brain / DeepMind Drives Vertex AI NAS Powers Vizier & PAX NeurIPS 2020 paper Fast with Rust Core
01 · Representational computing

Compute on the program itself

A pg.Object is a representation your code can hold — and the representation comes with a full algebra: compare it, rewrite it, leave holes in it, generate it, optimize it.

Turn any field into a space

Say it where the value lives: replace a value with pg.oneof and the class is the space — no separate schema to keep in sync. Enumerate it, sample it, or hand it to a search.

02 · A versatile object model

From dataclass to bi-directional topological container

One class statement spans the whole range — and every rung is opt-in, so you pay only for what you use.

High performance

All the power of PyGlove, at dataclass speed

Hot paths run in a native Rust core (pygx-core, installed automatically); the pure-Python implementation remains the executable specification, and the full suite runs against both cores on every PR. Wheels ship for Linux, macOS, and Windows on CPython 3.12–3.14 — plus a genuinely free-threaded 3.14t wheel.

Validated construction beats pydantic v2 with the whole symbolic model attached; attribute reads are at parity. Deserialization is slower — PyGX emits a _type tag so JSON round-trips back to the real class.

median ns/op · 3-field objectpygxpygx topo=True@dataclasspydantic v2
construct (kwargs)292283192522
attr get45454045
clone (deep)9158822,2701,620
to dict/json389388631532
from dict/json977982196656

Apple Silicon · read ratios, not absolutes · the full report covers ~50 operations across scales.

03 · Battle-proof method & implementation

Proven at Google scale,
rebuilt better and faster

Elevated PyGlove

Same paradigm, enhanced object model — opt-in topology, richer hooks — with hot paths up to 100× faster on the native Rust core.

Originated at Google Brain / DeepMind

Built by Daiyi Peng to power automated machine learning research, under the name PyGlove.

Powers AutoML at Google

The machinery behind Vertex AI NAS, Pax, and Vizier — searching over real programs in production.

NeurIPS 2020

The original PyGlove paper introduced symbolic programming for AutoML.

citation.bib
@inproceedings{peng2020pyglove,
  title  = {PyGlove: Symbolic programming
            for automated machine learning},
  author = {Peng, Daiyi and Dong, Xuanyi and Real,
            Esteban and Tan, Mingxing and others},
  booktitle = {NeurIPS}, volume = {33},
  pages = {96--108}, year = {2020}
}
When to reach for it

Where these properties cash out

And when not to: if your objects are only ever built and read, a dataclass or pydantic model is the better tool. PyGX earns its keep the moment a program becomes something you operate on.

Ask your program a question.

A search space is a program with holes. A patch is a rule from program to program. A diff is the difference between two of them. One object model — and they all speak about the same tree.

$pip install pygx
See examples