imre · sharifhsn.dev

Imre: progress from Astral

Imre is Astral's experimental ahead-of-time compiler for typed Python, written in Rust. It turns a closed, statically typed program into a native executable that runs without a Python installation. Upstream is astral-experiments/imre; everything on this page is read from main at c5e6864ec (2026-11-25).

7,843commits since 2026-10-17
#9,206highest merged PR
505,474lines of Rust in crates/
86.2%13,081 / 15,183 stdlib passes paired

Compiling Imre to WebAssembly →

Imre's generated LLVM IR already compiles for wasm32-wasip1; the runtime is the work. Runtime build errors for WASI: 556 → 10. Milestones: 5 / 9.

/wasm/

An experimental .NET target →

imre build --target dotnet emits a .NET assembly through cilly. On .NET 11 it beats CPython 3.14.5 on 7 of 10 workloads, up to 7.32× (luhn_4x (scaled)).

/dotnet/

Activity

3 authors; Charlie Marsh wrote 7,839 of 7,843 commits

Commits per day (UTC author date)

05001k10-17: 110-1710-21: 7410-22: 1710-23: 4810-2310-24: 13410-25: 65910-26: 29310-2610-27: 41510-28: 9910-29: 12710-2910-30: 311-01: 13211-02: 1,37511-0211-03: 48711-04: 31611-05: 21011-0511-06: 17511-07: 35211-08: 11811-0811-09: 7911-10: 37011-11: 28411-1111-12: 32611-13: 47011-14: 44411-1411-15: 40111-16: 20511-17: 17311-1711-18: 4311-19: 811-23: 211-2311-25: 3

Per ISO week: 2026-W42: 1 · 2026-W43: 932 · 2026-W44: 1,069 · 2026-W45: 3,033 · 2026-W46: 2,374 · 2026-W47: 429 · 2026-W48: 5

Merged PR number over time

05kOct 26Nov 2Nov 9Nov 16Nov 23PR number

7,727 first-parent commits end in “(#NNNN)”, from #1 to #9206.

Lines of Rust per crate

imre-runtimeimre-compilerimre-astimre-regeximre-runtime-jemallocrelar-compilerrelar-runtime
0200k400krelar-compiler 10-21: 2,071 linesrelar-runtime 10-21: 526 lines2.6k10-21imre-runtime 10-26: 70,826 linesimre-compiler 10-26: 106,238 linesimre-regex 10-26: 575 linesimre-runtime-jemalloc 10-26: 7 lines178k10-26imre-runtime 11-01: 124,475 linesimre-compiler 11-01: 120,344 linesimre-ast 11-01: 241 linesimre-regex 11-01: 662 linesimre-runtime-jemalloc 11-01: 7 lines246k11-01imre-runtime 11-02: 134,542 linesimre-compiler 11-02: 123,946 linesimre-ast 11-02: 332 linesimre-regex 11-02: 727 linesimre-runtime-jemalloc 11-02: 7 lines260k11-02imre-runtime 11-09: 251,511 linesimre-compiler 11-09: 153,055 linesimre-ast 11-09: 4,989 linesimre-regex 11-09: 3,430 linesimre-runtime-jemalloc 11-09: 7 lines413k11-09imre-runtime 11-16: 256,060 linesimre-compiler 11-16: 213,041 linesimre-ast 11-16: 6,555 linesimre-regex 11-16: 3,566 linesimre-runtime-jemalloc 11-16: 7 lines479k11-16imre-runtime 11-23: 265,748 linesimre-compiler 11-23: 228,662 linesimre-ast 11-23: 6,533 linesimre-regex 11-23: 3,566 linesimre-runtime-jemalloc 11-23: 7 lines505k11-23imre-runtime 11-25*: 265,861 linesimre-compiler 11-25*: 229,507 linesimre-ast 11-25*: 6,533 linesimre-regex 11-25*: 3,566 linesimre-runtime-jemalloc 11-25*: 7 lines505k11-25*

Newline counts of every *.rs file under crates/, at the first commit of each week and month (* = HEAD). The first code import used the crate names relar-compiler and relar-runtime.

How Imre compiles

docs/design.md, docs/subset.md

Imre compiles every executable Python body ahead of time. Within one compiled function, operations on values whose types are proved (exact ints, floats, fixed classes, concrete containers) become native LLVM instructions, while operations on Python objects call the Rust runtime ('boxed native code that calls the runtime'). There is no interpreter fallback: the earlier Python source evaluator was retired.

  1. Parse with Ruff's parser (docs/design.md:7).
  2. Check: Imre resolves imports, signatures and class layouts across the whole program and asks ty for semantic queries (docs/design.md:7).
  3. Lower to a typed, representation-checked IR; range analysis proves machine-word arithmetic and borrow analysis removes retains (docs/design.md:9).
  4. Emit LLVM IR as text, split per source module so unchanged modules are reused (docs/design.md:11).
  5. Compile with Clang (-O<n> -c -x ir -) and link against libimre_runtime.a, a Rust static library (crates/imre-compiler/src/build_cache.rs:386-387).

Native-only admission. Since #9204 (2026-11-25, one commit before HEAD), `imre check`/`imre build` accept only fixed native lowering; programs that need registered Python frames, a runtime module launcher or the general Python object runtime are rejected, with no override. (docs/native-only.md:3-8)

The value word

An int is one machine word, struct Int(usize). Small values are stored inline as (v << 1) | 1; anything else is a pointer to a reference-counted BigInt (crates/imre-runtime/src/lib.rs:76-99, docs/subset.md:1476). The compiler's IR passes these words as i64.

x86-64 / aarch64 (usize = 8 bytes)x = 5 # Int(usize)0B00000000000000byte 0bytes 1–7(5 << 1) | 1 = 0x0B bit 0 = 1 → small int, range [−2**62, 2**62)byte 0, bits 7…000001011bits 7…1 = 5 (value), bit 0 = 1 (tag)y = 2**70 # Int(usize)A014209C3A7F0000example address 0x7f3a9c2014a0, little-endianbit 0 = 0 → pointer; HeapInt is align(16), so the low bits are freeheapHeapInt(BigInt)#[repr(C, align(16))]num-bigint digits, refcounted

CPython stdlib test scorecard

CPython 3.14.5 · Linux x86-64 · 45 families

A test is paired when stock CPython passes it and Imre passes it at both -O0 and -O3. 13,081 of 15,183 stock Linux passes are paired (86.2%; 584 short of 90%). Against all 16,225 original tests it is 13,179 (81.23%). (README.md:263, README.md:247)

Headline percentage, every README revision

paired / stock passespaired / all originals
60%70%80%Nov 5Nov 8Nov 11Nov 14paired / stock passespaired / all originals

Denominators grow as families are added (13,328 → 16,225 originals). The sentence last changed on 2026-11-16 (7b11a4e8a).

Per family

familyoriginalsstock passpaired%
argparse1,8931,8931,88799.7%
importlib1,3451,32843232.5%
unittest1,0901,0881,05496.9%
datetime1,0981,0661,02996.5%
io1,0381,01095494.5%
pathlib1,36996394798.3%
typing71271271099.7%
collections65965563897.4%
socket74661410416.9%
os57948646996.5%
inspect36236226472.9%
zipfile38334333698.0%
configparser344339339100.0%
functools32932531697.2%
subprocess35330929796.1%
dataclasses27627627398.9%
logging27226822082.1%
zoneinfo26123322998.3%
threading2282239743.5%
json21621320596.2%
warnings18718117797.8%
weakref18317916893.9%
ssl1951786637.1%
shutil22317317198.8%
urllib178173173100.0%
re16516114590.1%
contextlib149149149100.0%
types14113913496.4%
itertools13813211083.3%
tokenize13013012797.7%
csv12812412298.4%
tempfile11811211098.2%
math89868396.5%
copy818181100.0%
gzip75757498.7%
hashlib82696797.1%
textwrap686868100.0%
fractions505050100.0%
uuid120484797.9%
struct43433479.1%
base6441414097.6%
fnmatch242424100.0%
glob242222100.0%
netrc232222100.0%
tomllib171717100.0%

From benchmarks/cpython_stdlib/full/frozen-stock-intersection-8818.tsv.

Caveats. The 86.2% figure is a historical mixed-revision ledger. The README's own pinned scorecard at revision 95908fb0 (README.md:111-181) credits only 666 verified pairs of 16,225 originals, because only configparser, dataclasses, fnmatch and part of json were re-run at that pin. Per-family stock skips and errors are not in the TSV or README: only the totals (1,024 skips, 7 errors, 11 unregistered) are published. stockNotPass = originals - stockPass lumps skips, errors and unregistered tests together. 'paired' = CPython 3.14.5 passed the original test and Imre passed it at both -O0 and -O3 (README.md:249-250).

Feature matrix

docs/subset.md, docs/stdlib.md, README.md
native Lowered to typed native codeboxed Compiled, but goes through Python objects / the runtime (registered frames, dynamic dispatch, boxed matcher)unsupported Rejected at compile time or documented as outside the subsetunknown Import accepted but no API example or evidence recorded

Language

areafeaturestatussource
Numbersint (arbitrary precision; tagged word in [-2**62, 2**62), num-bigint outside)
Checked arithmetic promotes/demotes
nativedocs/subset.md:40, docs/subset.md:1476
float (IEEE binary64)nativedocs/subset.md:41, docs/subset.md:605
bool as its own exact typenativedocs/subset.md:56
Textstr (immutable UTF-8): slicing, split, join, replace, find, formatnativedocs/subset.md:47
f-strings, str.format, % formatting
Bounded format specs
nativedocs/subset.md:47, docs/subset.md:742
bytesnativedocs/subset.md:49
Containerslist[T] with one exact element type
No slice assignment/deletion
nativedocs/subset.md:42
dict[K, V] with exact key types
Keys: int, str, StrEnum, bytes, Path, immutable tuples
nativedocs/subset.md:43
set[T]nativedocs/subset.md:44
Fixed tuples (one type per position)nativedocs/subset.md:46
collections.deque[T]
Native ring buffer
nativedocs/subset.md:1304
TypesT | None and str | bytes
Bounded unions only
nativedocs/subset.md:36
Any, unrestricted unions, untyped objects in native storage
ty checks first; Imre then enforces exact types
unsupporteddocs/subset.md:56
enum.StrEnum and typing.Literal strings
Members stored as integer tags
nativedocs/subset.md:1147
FunctionsExact signatures: positional/keyword, positional-only, keyword-only, scalar defaultsnativedocs/subset.md:35
Unannotated parameters inferred from defaults and concrete callsnativedocs/subset.md:66
Direct and mutual recursion
Needs resolved signatures
nativedocs/subset.md:35, README.md:99
Callable values, bound methods, noncapturing lambdasnativedocs/subset.md:35, docs/subset.md:191
functools.cache / lru_cache / partialnativedocs/subset.md:9-19, docs/subset.md:21-28
Closures that need Python cells
Compiler can request a registered frame; see native-only admission
boxeddocs/design.md:36-40
Calling a runtime-selected callable (e.g. handlers[key](value))
Looked up and invoked through the Python runtime inside compiled code
boxeddocs/design.md:23, docs/design.md:55
Arbitrary decorators
Excluded from fixed layouts
unsupporteddocs/subset.md:62
General generator functions
Excluded from fixed layouts; generator expressions consumed immediately are lowered
unsupporteddocs/subset.md:62, docs/subset.md:238
Open-ended argument expansion, untyped *argsunsupporteddocs/subset.md:62
ClassesFixed-layout classes, dataclasses (incl. frozen), properties, class/static methodsnativedocs/subset.md:37
Single concrete base class inheritancenativedocs/subset.md:1246
@imre.struct immutable value structs stored inline in listsnativedocs/subset.md:1250-1252, README.md:429-433
Reflection and dynamic attributes
getattr over a known set of field names compiles
unsupporteddocs/subset.md:62, README.md:90-91
Control flowif/while/for/else, break/continue, assertnativedocs/subset.md:38
Structural pattern matching (match/case)nativedocs/subset.md:1116
Assignment expressions (:=)nativedocs/subset.md:570
Exceptions: try/except/else/finally, raise
Sealed builtin Exception family
nativedocs/subset.md:38, docs/subset.md:1498
with (builtin file / workspace context managers)nativedocs/subset.md:38
ComprehensionsList/dict/set comprehensionsnativedocs/subset.md:45
Lazy pipelines: map/filter/zip/enumerate/reversed/generator expressions
Lowered into native control flow at the consumer
nativedocs/subset.md:238
AsyncTyped coroutines, await, asyncio.TaskGroup / gather / Semaphore
Subprocess-backed work
nativedocs/subset.md:1747
Async generator feeding an async comprehensionnativeREADME.md:100, docs/subset.md:62
ConcurrencyThreads sharing Python objects
Compiles but raises NotImplementedError at Thread.start()
unsupporteddocs/subset.md:1730-1734
ModulesClosed first-party import graph (absolute, from, relative imports)
No import cycles
nativedocs/subset.md:32-33
Modules selected by name at runtime (--include-module)
Links source for a runtime module loader; a fully typed entry rejects it
boxeddocs/subset.md:641
exec / eval / runpy on source chosen at runtime
Reported before linking
unsupporteddocs/design.md:63
ValuesInferred results in Python object storageboxeddocs/subset.md:510
Regexre.compile / re.search on fixed literal patternsnativedocs/subset.md:48, docs/subset.md:441
Literal lookaheads and fixed-width lookbehinds
Uses the boxed matcher
boxeddocs/subset.md:485
ExtensionsC extensions rebuilt against Imre's Python.h
Wheels carry a static archive plus typed signatures
nativedocs/design.md:73, README.md:414-416

Standard library modules (194)

native 84 · boxed 3 · unknown 43 · unsupported 64. Hover a module for its API note.

abcannotationlibargparsearrayasynciobase64binasciibuiltinscmdcodecscollectionsconfigparsercontextlibcontextvarscopycsvdataclassesdatetimedifflibdoctestemailenumerrnofnmatchfunctoolsgcgenericpathgettextgziphashlibhtmlhttpimportlibinspectioitertoolsjsonkeywordlinecachelogginglzmamarshalmathmimetypesnumbersoperatorospathlibpickleplatformposixposixpathrandomresecretsselectselectorsshlexshutilsignalsitesocketserverstatstringstructsubprocesssyssysconfigtempfiletextwraptimetomllibtypestypingunicodedataunittesturllibuuidwarningswaveweakrefzipfilezipimportzlibdecimalheapqsocketastatexitbisectcalendarcodecodeopcolorsyscompressioncopyregdisencodingsfaulthandlerfcntlfractionsftplibgetoptglobgrphmacipaddresslocalentpathopcodeoptparsepkgutilpprintpwdpy_compilepyexpatqueuequopriresourcerunpysslstatisticstermiosthreadingtokentokenizetracebacktracemallocxmlzoneinfoantigravitybdbbz2cProfilecmathcompileallconcurrentctypescursesdbmensurepipfilecmpfileinputgetpassgraphlibidlelibimaplibmailboxmmapmodulefindermsvcrtmultiprocessingnetrcntnturl2pathpdbpickletoolsplistlibpoplibprofilepstatsptypyclbrpydocpydoc_datareadlinereprlibrlcompleterschedshelvesmtplibsqlite3sre_compilesre_constantssre_parsestringprepsymtablesyslogtabnannytarfilethistimeittkintertracettyturtleturtledemovenvwebbrowserwinregwinsoundwsgirefxmlrpczipapp

Statuses are partly inferred: docs/stdlib.md calls this import inventory historical and does not say native vs boxed per module, so modules are classified by the wording of their API note. Some modules listed as rejected imports have passing suites in the README scorecard.

CLI

commanddoessource
imre build (SOURCE.py | -m MODULE) [-o OUTPUT]Compile to a native executable named after the source filecrates/imre-compiler/src/main.rs:39, crates/imre-compiler/src/main.rs:56
imre run SOURCE.py [-- ARGS]Compile (cached) and run; arguments after -- go to the programcrates/imre-compiler/src/main.rs:40, README.md:506
imre check SOURCE.py [--watch]Type-check and validate without linking; --watch reports each revisioncrates/imre-compiler/src/main.rs:33, README.md:510
imre [-c CODE | -m MODULE | SCRIPT]Python-compatible launcher: compiles and runs as native code; sys.implementation.name == 'imre'; discoverable by uvcrates/imre-compiler/src/main.rs:34, README.md:53-64
imre wheel PROJECT [--out-dir DIR] [--overlay DIR] [--python PYTHON]Build a native-extension wheelcrates/imre-compiler/src/main.rs:38, crates/imre-compiler/src/main.rs:114-115
imre extension-headerPrint Imre's Python.h (C API header for extensions)crates/imre-compiler/src/main.rs:36, crates/imre-compiler/src/main.rs:117-122
imre build-target [--output-dir DIR]Report the target description (target.json) used by extension buildscrates/imre-compiler/src/main.rs:37, .github/workflows/build-release-binaries.yml:89-90

Release targets

triplebuiltarchive
x86_64-unknown-linux-gnuevery releaseClang 18 + LLD 18 toolchain, libimre_runtime.a, libimre_runtime_jemalloc.a, bundled stdlib zip and O0/O3 provider archives
aarch64-unknown-linux-gnuevery releaseSame as x86-64 Linux; jemalloc built for up to 64 KiB pages
aarch64-apple-darwinonly with include_macosimre + libimre_runtime.a only (uses Apple Clang); included only when include_macos is set

Optimization levels -O0, -O1, -O2, -O3 (default -O3). --whole-program optimizes all modules together; default splits LLVM per source module for incremental reuse. Allocators: system (default), jemalloc (Linux).

Published benchmarks

benchmarks/
ImreRustCPython

Application CLIs: median elapsed ms, one AMD EPYC Milan vCPU, warm caches, includes process startup

workloadmedian msvs CPythonImre / Rust
uv download catalog
153.9
103.5
2,884.0
18.7×1.49×
Source search
54.5
48.1
187.5
3.4×1.13×
Wheel verification
36.9
22.6
155.2
4.2×1.63×
Road graph load
61.2
60.9
531.1
8.7×1.0×
Road routing
102.7
92.6
1,926.9
18.8×1.11×
Conformance report
29.9
21.9
255.9
8.6×1.37×

benchmarks/applications/README.md:15-34. Speedups derived from the published medians.

HTTP throughput, 8 concurrent clients, median of rounds (requests/s)

Frozen Flask on Imre 0.1.5
9,521
Rust/Hyper (single-threaded)
9,558
Stock Flask on CPython (Werkzeug)
1,028

benchmarks/applications/README.md:38-40; README.md:24-32

Original runtime suite (2026-10-28)

workloadmedian msvs CPython
Inventory (repeated)
41.81
27.36
90.37
2.2×
Inventory (distinct)
72.64
48.90
121.16
1.7×
Base45 decode
16.88
9.73
206.27
12.2×
Luhn checksum
13.73
5.71
157.62
11.5×
Telemetry report
16.49
10.31
128.03
7.8×
Conformance report
48.51
29.67
290.33
6.0×

benchmarks/runtime-suite.md:9-32