Compile Python applications into standalone native binaries
Project description
PyBend ๐ชถ
Compile Python applications into standalone native binaries that run entirely in volatile memory.
PyBend is a zero-configuration, high-performance Python-to-Native-Binary compiler toolchain. It compiles your Python applications, third-party packages, and native C-extensions into a single, standalone executable โ with zero physical disk I/O at runtime.
Unlike traditional freezers (PyInstaller, cx_Freeze, Nuitka) that extract dependencies to /tmp or %TEMP%, PyBend keeps everything in RAM via a custom PEP 451 meta-path importer backed by an embedded Virtual File System.
๐ Performance Snapshot
| Metric | PyBend | PyInstaller |
|---|---|---|
| Cold-Start Latency | ~143 ms | ~300โ500 ms |
| Disk I/O at Runtime | 0 physical writes | Writes to /tmp |
| Binary Size (hello world) | ~2.7 MB | ~30 MB+ |
| Tree-Shaken Stdlib | Modulefinder trace (300-400 modules) | Bundles full stdlib (~3,400 modules) |
| Code on Disk | Never | Extracted to temp |
๐ ๏ธ How It Works
1. AST Tracing & Tree-Shaking
Scans your import graph using Python's modulefinder. Only the modules your app actually imports are included โ no bloat.
2. Optimization Pass (-OO)
All source is compiled to bytecode with assertions and docstrings stripped, yielding 8โ15% smaller payloads.
3. Dual-Table VFS v2 Layout
Bytecode, native .so/.pyd extensions, and static assets are packed into a structured binary blob. All entry payloads are compressed as a single Zstd block for maximum ratio:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ BENDVFS BLOB โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ [4B: "BEND" Magic] [4B: Code Entry Count] โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Code Module Table โ โ
โ โ name โ (offset, compressed_size, โ โ
โ โ uncompressed_size, is_c_ext) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ [4B: Asset Entry Count] โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Asset Table โ โ
โ โ path โ (offset, compressed_size, โ โ
โ โ uncompressed_size) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Single Zstd Block (all entries batched) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
4. RAM-Mapped Execution
- The Rust bootloader memory-maps itself via
memmap2, locates the VFS by itsBENDfooter signature, decompresses the single Zstd block, and passes the payload to the embedded Python runtime. - Before
Py_Initialize(), VFS.pycentries are extracted to a temp directory soimportlibcan find them during stdlib bootstrapping. - A
BendMemoryFinderis injected intosys.meta_path[0]per PEP 451 โ all subsequent imports resolve from RAM. - C-extensions are written to anonymous
memfd_create(Linux) or temp files (Windows) and loaded viadlopen/LoadLibrarywithRTLD_GLOBAL.
5. Tree-Shaking, Incremental Cache & Debug Stripping
- Tree-shaken stdlib: Modulefinder traces only the modules your app actually imports โ ~300โ400 modules instead of the full stdlib (~3,400).
- Incremental cache: Bytecode is cached by
(path, mtime, opt_level)indist/.pybend_cache/, so rebuilds recompile only changed files. - Debug stripping:
co_linetable/co_lnotabis stripped from all code objects, saving ~10% binary size. - Compression: All entry payloads batched into a single Zstd block (level 7 default, configurable 1โ19).
๐ฆ Quick Start
1. Install
pip install pybend
2. Zero-Config Build
If your project directory contains main.py, app.py, or manage.py (Django):
pybend build
That's it. The output lands at ./dist/<name>.bin (Linux) or ./dist/<name>.exe (Windows).
Django projects are auto-detected: --noreload is appended to runserver, project packages are force-included, and certifi.where() is patched for the VFS CA bundle. FastAPI projects detected via uvicorn.run() get the same treatment.
3. Explicit Build
pybend build --entry src/server.py --output deploy/server -O 2
4. Config-Driven Build (pybend.toml)
[build]
entry_point = "src/main.py"
output_exe = "dist/app" # auto-appends .exe on Windows
optimization_level = 2
compress_level = 7 # Zstd compression level (1โ19)
strip_debug = true # Strip co_linetable from bytecode
include_modules = ["hidden_dep"]
exclude_modules = ["test", "unittest"] # or ["*"] to skip site-packages
include_data = ["config.json", "assets/"]
pybend build
5. Inspect a Compiled Binary
pybend inspect dist/app
Prints a table of all code and asset entries in the VFS โ names, compressed/uncompressed sizes, compression ratios, and module types.
6. Build Bootloader from Source
If the pre-built bootloader doesn't match your Python version:
pybend bootstrap
Requires Rust/Cargo. The built template is automatically staged for future use.
7. Fetching Embedded Assets at Runtime
Any file listed in include_data can be streamed from memory:
import pybend
config = pybend.get_asset("config.json")
template = pybend.get_asset("templates/email.html")
No disk access. No extraction. Directly from the VFS.
๐๏ธ Project Structure
pybend/
โโโ pyproject.toml # Hatchling build config
โโโ bootloader/ # Rust runtime engine
โ โโโ Cargo.toml
โ โโโ src/
โ โโโ main.rs
โ โโโ extractor.rs
โ โโโ bootstrapper.rs
โโโ pybend/ # Python build orchestration
โ โโโ __init__.py
โ โโโ cli.py # Click CLI
โ โโโ compiler.py # Pipeline orchestrator
โ โโโ config.py # TOML + CLI config resolution
โ โโโ detector.py # Django/FastAPI auto-detection
โ โโโ inspector.py # Binary VFS table parser
โ โโโ dependency_resolver.py # Import tracing + filtering
โ โโโ importer.py # Runtime VFS finder & loaders
โ โโโ splicer.py # Binary tail-splicing
โ โโโ vfs_builder.py # Zstd batch VFS builder + cache
โ โโโ templates/ # Pre-built bootloader binaries
โโโ docs/ # MkDocs documentation
โโโ tests/ # Test suite
โโโ .github/workflows/ # CI/CD pipelines
โ๏ธ Configuration Reference
CLI Commands
| Command | Description |
|---|---|
build |
Compile a Python app into a standalone binary |
bootstrap |
Build the bootloader template from Rust source |
inspect |
Inspect the VFS table inside a compiled binary |
CLI Flags (build)
| Flag | Shorthand | Description |
|---|---|---|
--entry |
-e |
Entry point script path |
--output |
-o |
Output executable path |
--optimize |
-O |
Optimization level (0, 1, 2) |
--include |
-i |
Force-include a module |
--exclude |
-x |
Exclude a module |
--template |
-t |
Custom bootloader binary |
--config |
-c |
Custom pybend.toml path |
--target |
-p |
Target platform (os/arch, e.g. linux/x86_64) |
--verbose |
-v |
Show detailed build output |
--quiet |
-q |
Suppress all non-error output |
--no-strip |
Do not strip debug symbols from output | |
--compress-level |
Zstd compression level (1โ19, default 7) | |
--no-strip-debug |
Keep co_linetable in bytecode (larger binary) |
pybend.toml Fields
| Field | Type | Default | Description |
|---|---|---|---|
entry_point |
string | auto-discover | Entry script path |
output_exe |
string | dist/<name>.bin/.exe |
Output binary path |
optimization_level |
int | 2 |
Bytecode optimization (0/1/2) |
compress_level |
int | 7 |
Zstd compression level (1โ19) |
strip_debug |
bool | true |
Strip co_linetable from bytecode |
include_modules |
string[] | [] |
Force-include modules |
exclude_modules |
string[] | [] |
Exclude modules (["*"] skips all site-packages) |
include_data |
string[] | [] |
Static file paths to embed |
๐งช Testing
# Python test suite
python -m unittest discover -s tests -v
# Rust tests
cd bootloader && cargo test
Current test coverage: 49 Python tests + 2 Rust tests โ all passing.
Includes end-to-end compilation + execution tests, C-extension loading (memfd_create on Linux, .pyd+.dll on Windows), VFS structural validation, latency benchmarks, and disk-isolation verification.
๐ฏ Target Platforms
- Linux x86_64 (primary, production-tested)
- Windows x86_64 (Python 3.10โ3.14, CI-tested,
.exeoutput with.pyd/.dllsupport)
Future targets: aarch64-unknown-linux-musl, aarch64-apple-darwin.
๐ License
MIT โ see LICENSE.
Copyright (c) 2026 Jude Nii Klemesu Commey
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybend-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pybend-1.0.1-py3-none-any.whl
- Upload date:
- Size: 53.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c34082872d7bcc1bd3d26a828d150f7e9be8098adf173a9bd351c1341986d854
|
|
| MD5 |
3cb76f069f71684a5a511f97493efbb4
|
|
| BLAKE2b-256 |
e2023c48c5ca95bdc622c96c3d11c980ef6389f50f4dd5a9abe3d6841504a269
|
Provenance
The following attestation bundles were made for pybend-1.0.1-py3-none-any.whl:
Publisher:
release.yml on niicommey01/pybend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybend-1.0.1-py3-none-any.whl -
Subject digest:
c34082872d7bcc1bd3d26a828d150f7e9be8098adf173a9bd351c1341986d854 - Sigstore transparency entry: 2170918820
- Sigstore integration time:
-
Permalink:
niicommey01/pybend@dc3c10097bfeb5974bdef0036238657dad718444 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/niicommey01
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dc3c10097bfeb5974bdef0036238657dad718444 -
Trigger Event:
push
-
Statement type: