Package Builder is a modular build system for Python projects and hybrid Python + Rust extensions. It reads pypackage.toml, prepares an isolated virtual environment, installs declared dependencies, and assembles results under site-packages.
- Pure-Python backend for copying your module and dependencies
- Rust-Python backend via Cargo and
pyo3 - Isolated virtual environment for reliable
python/pip - Hooks and plugins to customize pre/post steps
- Optional dependency cleanup
No separate installation is required in this repository.
- Run with Python:
python -m package_builder <command> - Run with the embedded runner (Windows):
embedded_python.exe module package_builder <command>
embedded_python.exeis produced from the embedded-Python runner template:
https://github.com/krita-frag/embedded-python-template- Build steps (Windows):
- Install
cookiecutter, Zig 0.15+, and Visual Studio 2022 C++ build tools (MSBuild). - Run:
cookiecutter https://github.com/krita-frag/embedded-python-template.git - Enter the generated project folder and run:
zig build(or build only the app:zig build -Dbuild_step=app) - Find
embedded_python.exeinside the generated project'sdist\folder - Place the executable next to this project (or add it to PATH) and invoke it as:
embedded_python.exe module package_builder <command>
- Install
Prerequisites (when using the Rust backend):
- Python 3.11 (tested) or newer
- Rust toolchain and Cargo
General syntax:
python -m package_builder <command> [options]embedded_python.exe module package_builder <command> [options]
Available commands:
init– Create a minimalpypackage.tomlinstall/uninstall– Manage dependencies in the venvinfo/list– Show environment and installed packagescheck– Validate configuration and environmentbuild– Assemble outputs underdist/site-packagesbuild_sdist– Build a source distributionupdate– Self-update Package Builder from GitHub releases
Examples:
- Initialize config:
python -m package_builder init - Build (pure Python):
python -m package_builder build - Build with embedded runner:
embedded_python.exe module package_builder build - Self-update to latest:
python -m package_builder update - Force update to a version:
python -m package_builder update --force 1.2.0
Minimal pypackage.toml:
[project]
name = "core"
version = "0.1.0"
description = "Core module (Rust+Python via pyo3)"
license = "MIT"
readme = "README.md"
authors = ["Example Dev <dev@example.com>"]
[dependencies]
PySide6 = "==6.10.0"
[dev-dependencies]
[build]
backend = "rust-python"
[build.pip]
index-url = "https://pypi.tuna.tsinghua.edu.cn/simple"
[build.rust-python]
source = "python"
cargo-toml = "Cargo.toml"
binding = "pyo3"
profile = "release"
module = "core._core"
artifact = ""
include = []
exclude = ["**/__pycache__/**", "**/*.pyc", "target/**", "tests/**", ".venv/**"]
features = []
[tool]
plugins = ["hooks"]
[tool.hooks]
script = "scripts/hook.py"Notes:
excludepatterns affect your project files; dependencies are copied as installed.- Outputs are placed under
dist/site-packagesfor inspection and packaging.
-
Pure-Python project:
- Write
pypackage.tomlwith[project],[dependencies], and[build].python - Run:
python -m package_builder build
- Write
-
Rust-Python project:
- Ensure Cargo and
pyo3are configured in your crate - Set
[build].rust-pythonand run:python -m package_builder build
- Ensure Cargo and
-
Self-update:
- Latest release:
python -m package_builder update - Dry run:
python -m package_builder update --dry-run - Specific version:
python -m package_builder update --force 1.2.0
- Latest release:
- Tested with Python 3.11.5
- For Python 3.13, use
pyo3 >= 0.21or setPYO3_USE_ABI3_FORWARD_COMPATIBILITY=1when building Rust extensions - Windows and Linux are supported; macOS support depends on your Rust/Python toolchains
- Embedded runner not found: ensure
embedded_python.exeexists and usemodule package_builder - Venv creation fails: confirm Python and write permissions in the project directory
- Cargo/pyo3 errors: update toolchain and verify
Cargo.tomlmatches your Python version - Dependency conflicts: run
python -m package_builder checkand adjust versions - SSL/TLS issues with
pip: upgradepipinside the venv (pip install -U pip) - Build outputs missing: verify
pypackage.tomlmodulepaths and rerunbuild
- microvenv – Lightweight virtual environment implementation used internally for fast, isolated Python runs.
- Embedded Python Template – Template for generating
embedded_python.exe(Zig build, embedded CPython).