{"slug": "serc-cpython-bytecode-compiler-written-in-rust-codex-built-2-4x-speedup", "title": "Serc: CPython bytecode compiler written in Rust (Codex built, 2-4x speedup)", "summary": "Astral Experiments released Serc, an experimental CPython bytecode compiler written in Rust, which produces byte-for-byte identical output to CPython on Django, Airflow, and Transformers across CPython 3.12, 3.13, 3.14, and 3.15 at optimization levels 0, 1, and 2, while compiling 3-4x faster than CPython's compileall. The project's README states that all code changes, PR summaries, and additional documentation were authored entirely by GPT in Codex, and warns that Serc is experimental and may emit incorrect bytecode in some cases. Serc installs from crates.io as serc-cli with Rust 1.96 or later, emits Python 3.14-compatible bytecode by default, and supports --python-version targeting for 3.12 through 3.15.", "body_md": "An experimental CPython bytecode compiler, written in Rust.\n\nSerc produces byte-for-byte identical output (as compared to CPython) on an\nextensive corpus of real-world Python code, including\n[Django](https://github.com/django/django),\n[Airflow](https://github.com/apache/airflow), and\n[Transformers](https://github.com/huggingface/transformers), across CPython\n3.12, 3.13, 3.14, and 3.15, and optimization levels 0, 1, and 2, all while\ncompiling [3-4x faster](https://github.com/astral-experiments/serc/blob/main/BENCHMARKS.md#project-compilation) than CPython’s\n`compileall`.\n\nBut Serc is also experimental! And so may emit incorrect bytecode in some cases.\n\nWarning\n\nSerc is experimental. This README is human-edited, but all code changes, PR summaries, and additional documentation were authored entirely by GPT in Codex.\n\nInstall from [crates.io](https://crates.io/crates/serc-cli) with Rust 1.96 or\nlater:\n\n```\ncargo install serc-cli --locked\n```\n\nGiven `hello.py`:\n\n``` python\ndef greet(name):\n    return f\"Hello, {name}!\"\n```\n\nCompile to bytecode, emitted at `__pycache__/hello.cpython-314.pyc`:\n\n```\nserc compile hello.py\n```\n\nPass a directory to compile its Python files recursively, or use `--check` to\ncompile without writing cache files:\n\n```\nserc compile path/to/package\nserc compile --check path/to/package\n```\n\nCompilation uses the available CPUs by default. Use `--jobs` (or `-j`) on the\ncommand line or the `RAYON_NUM_THREADS` environment variable to set a limit,\nincluding `--jobs 1` for serial compilation.\n\n```\nserc compile --jobs 4 path/to/package\n```\n\nBy default, Serc skips files whose `.pyc` is up to date by checking the bytecode\nformat and invalidation mode, then comparing the source file's timestamp and\nsize (for timestamp-based caches) or its content hash (for hash-based caches).\n\nPass `--force` (or `-f`) to recompile every file, for example after switching\ncompilers or native build profiles. (Even with `--force`, Serc refuses to\noverwrite symlinks or special files.)\n\nSerc emits Python 3.14-compatible bytecode by default, but supports target\nselection with `--python-version`. For example, to emit Python 3.15 bytecode:\n\n```\nserc compile --python-version 3.15 path/to/package\n```\n\nSerc supports the following CPython minor versions:\n\n| Target | Pinned CPython release | \n|---|---|\n| `3.12` | 3.12.14 | \n| `3.13` | 3.13.15 | \n| `3.14` | 3.14.5 | \n| `3.15` | 3.15.0rc2 | \n\nEach target writes its own cache tag and bytecode magic number, so the four\nversions can coexist under `__pycache__`.\n\nUse `-O` to remove assertions and set `__debug__` to false, matching Python's\n`-O` mode. Use `-OO` to additionally remove module, class, and function\ndocstrings:\n\n```\nserc compile -O hello.py\nserc compile -OO hello.py\n```\n\nYou can also select the level explicitly with `--optimize 0`, `--optimize 1`, or\n`--optimize 2`. Level 0 is the default. Optimized caches use Python's naming\nconvention, such as `__pycache__/hello.cpython-314.opt-1.pyc` and\n`__pycache__/hello.cpython-314.opt-2.pyc`, so all three levels can coexist.\n\nAdd Serc to your `Cargo.toml`:\n\n```\n[dependencies]\nserc = \"0.1.0\"\n```\n\nCompile Python source and serialize the resulting code object in CPython's marshal format:\n\n``` js\nlet module = serc::compile(\"print('Hello, world!')\\n\", \"hello.py\").unwrap();\nlet marshaled = module.marshal();\n```\n\nSerc is licensed under either of\n\n- Apache License, Version 2.0, ([LICENSE-APACHE](https://github.com/astral-experiments/serc/blob/main/LICENSE-APACHE) or[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0) )\n- MIT license ([LICENSE-MIT](https://github.com/astral-experiments/serc/blob/main/LICENSE-MIT) or[https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT) )\n\nat your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serc by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.", "url": "https://wpnews.pro/news/serc-cpython-bytecode-compiler-written-in-rust-codex-built-2-4x-speedup", "canonical_source": "https://github.com/astral-experiments/serc", "published_at": "2026-11-10 02:53:14+00:00", "updated_at": "2026-11-10 03:22:26.963372+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "artificial-intelligence"], "entities": ["Serc", "Astral Experiments", "CPython", "Rust", "GPT", "Codex", "Django", "Airflow"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/serc-cpython-bytecode-compiler-written-in-rust-codex-built-2-4x-speedup", "markdown": "https://wpnews.pro/news/serc-cpython-bytecode-compiler-written-in-rust-codex-built-2-4x-speedup.md", "text": "https://wpnews.pro/news/serc-cpython-bytecode-compiler-written-in-rust-codex-built-2-4x-speedup.txt", "jsonld": "https://wpnews.pro/news/serc-cpython-bytecode-compiler-written-in-rust-codex-built-2-4x-speedup.jsonld"}}