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.
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.
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.
One class statement spans the whole range — and every rung is opt-in, so you pay only for what you use.
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 object | pygx | pygx topo=True | @dataclass | pydantic v2 |
|---|---|---|---|---|
| construct (kwargs) | 292 | 283 | 192 | 522 |
| attr get | 45 | 45 | 40 | 45 |
| clone (deep) | 915 | 882 | 2,270 | 1,620 |
| to dict/json | 389 | 388 | 631 | 532 |
| from dict/json | 977 | 982 | 196 | 656 |
Apple Silicon · read ratios, not absolutes · the full report covers ~50 operations across scales.
Same paradigm, enhanced object model — opt-in topology, richer hooks — with hot paths up to 100× faster on the native Rust core.
Built by Daiyi Peng to power automated machine learning research, under the name PyGlove.
The machinery behind Vertex AI NAS, Pax, and Vizier — searching over real programs in production.
The original PyGlove paper introduced symbolic programming for AutoML.
@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}
}
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.
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.