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 | ~77 ms (median, Linux/x86_64) | ~300–500 ms |
| Disk I/O at Runtime | stdlib bootstrap .pyc + C extensions extracted to temp; app bytecode from RAM |
Writes to /tmp |
| Binary Size (hello world) | ~2.2 MB | ~30 MB+ |
| Tree-Shaken Stdlib | Traced import graph (a few hundred modules, not the full stdlib) | Bundles full stdlib |
| Code on Disk | Never (only bootstrap/stdlib .pyc + native exts touch temp) |
Extracted to temp |
Benchmarks measured with the debug bootloader template on Linux x86_64, Python 3.14,
import math, jsonhello world; latency is the median of 20 runs. Numbers are machine-dependent; treat as indicative.
🛠️ 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
The PyPI wheel is code-only. Bootloader templates are fetched on first
use from GitHub Releases for your platform/Python; if you're offline, either
build one from source (pybend bootstrap, requires Rust) or pass a prebuilt
template with pybend build --template PATH.
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> (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>/.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 |
bundle_all |
bool | false |
Bundle every installed package (disable tree-shaking) |
🧪 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
Metadata
Release files for pybend 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pybend-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for pybend-1.1.3-py3-none-any.whl |
Release files / pybend-1.1.3-py3-none-any.whl
| Download URL | pybend-1.1.3-py3-none-any.whl |
|---|---|
| Size | 44.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84b484b9f92ae4f212c95f7ebf745dd5c14050fad095d8af299836942d0fe9ce
|
|
BLAKE2b-256 checksum How to use checksums |
e47ea9dafac5c79e98637e9dc2cd7baafc2599a3f41a50ce29c0106fda68a154
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logSecurity for pybend 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for pybend-1.1.3-py3-none-any.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.