Skip to main content

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 its BEND footer signature, decompresses the single Zstd block, and passes the payload to the embedded Python runtime.
  • Before Py_Initialize(), VFS .pyc entries are extracted to a temp directory so importlib can find them during stdlib bootstrapping.
  • A BendMemoryFinder is injected into sys.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 via dlopen/LoadLibrary with RTLD_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) in dist/.pybend_cache/, so rebuilds recompile only changed files.
  • Debug stripping: co_linetable/co_lnotab is 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, .exe output with .pyd/.dll support)

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.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pybend 1.0.2
File Interpreter ABI Platform
pybend-1.0.2-py3-none-any.whl Python 3 none any Details

Release files / pybend-1.0.2-py3-none-any.whl

Download URL pybend-1.0.2-py3-none-any.whl
Size 53.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
39512309a820de62a2f248cd35841822ca153b7fa1813ff2ad632bb415412173
BLAKE2b-256 checksum
How to use checksums
156f28eb08b9411cc31cdd9ce06ddafa079e8bb15cb85673e5bb84b88d8d546f
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 Aug 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page