PyApp
repository·master·Indexed 24 days ago
https://github.com/ofek/pyappA runtime installer for Python applications that wraps them into standalone, platform-specific binaries. PyApp manages the Python environment and application execution, supporting features such as standalone binary builds, configurable runtime behavior, and optional management commands for self-updates. It allows for flexible Python distribution sourcing (CPython, PyPy, or custom), embedding of distributions and projects, and installation via pip or uv.
What's inside pyapp
- PyApp is a wrapper for Python applications that bootstraps them at runtime. It allows you to build standalone binaries for various platforms, providing a seamless experience where the user runs a single executable that manages the Python environment and application execution.
Detect if an application is running via PyApp
masterYou can detect if your application is being run through the PyApp bootstrap process by checking for the presence of thePYAPPenvironment variable. When running applications, PyApp injectsPYAPP=1by default.Configure runtime installation sources
masterPyApp supports three ways to configure how the project is installed at runtime. Note that the project identifier is required in all cases.
1. Package Index (PyPI)
By providing only
PYAPP_PROJECT_NAMEandPYAPP_PROJECT_VERSION, the package will be installed from a package index like PyPI.2. Dependency File
You can install your project using a local requirements file by setting
PYAPP_PROJECT_DEPENDENCY_FILEto the local path of the file. Supported extensions are.txtand.in(standard requirements file format). In this mode, the project identifier is used only as metadata and not for installation.3. Embedding
You can embed a specific package directly into the binary by setting
PYAPP_PROJECT_PATHto a path pointing to a.whl(wheel) or a.tar.gz(source distribution) file. When embedding, the project identifier is automatically derived from the metadata inside the file.Key features of PyApp
masterPyApp provides the following capabilities:
- Standalone Binaries: Easily build binaries for every platform.
- Management Commands: Optional commands for functionality like self-updates.
- Configurable Runtime: Extremely configurable runtime behavior to target different end-user requirements.
Install PyApp via Cargo
masterYou can install the
pyappbinary directly using Cargo. Use the--rootoption to specify the installation directory. You can also specify a version using the--versionflag.Note: Cross-compilation is currently unsupported via the
cargo installmethod.Output Locations:
- Windows:
<DIR>/bin/pyapp.exe - Other OS:
<DIR>/bin/pyapp
- Windows:
Build PyApp applications
masterOnce you have configured the necessary environment variables, use Cargo to build the release binary. The resulting executable will be located in the
target/release/directory.cargo build --releaseEmbed a Python distribution in the executable
masterTo avoid fetching a Python distribution at runtime, you can embed it directly into the executable at build time.
There are two ways to achieve this:
- Using
PYAPP_DISTRIBUTION_EMBED: Set this totrueor1. - Using
PYAPP_DISTRIBUTION_PATH: Set this to a local path pointing to a Python archive. This implicitly enables embedding.
The local archive should be structured similarly to the default distributions and contain a ready-to-use Python interpreter.
- Using
Build PyApp from a local repository
masterTo build PyApp from source, first ensure your project is configured according to the project configuration guide. Download the source archives from the releases page (e.g.,
source.tar.gz). After unpacking, run the build command from the repository root.Output Locations:
- Windows:
target/release/pyapp.exe - Other OS:
target/release/pyapp - Cross-compiled/Specific Target:
target/<TARGET>/release/pyapp(or.exeon Windows)
- Windows:
Cross-compiling PyApp
masterCross-compilation is supported using
cross.Important Requirement for Embedding: If you are embedding a project or distribution using a local path, you cannot use
cargo install. You must use the Local Repository build method. Additionally, ensure that:- The files to be embedded reside within the repository.
- The configuration options use relative paths.
Get PyApp source code
masterTo build applications with PyApp, you must download the source code. Follow these steps based on your operating system to download and extract the latest release.
Linux/macOS
- Download the source tarball using
curl. - Extract the archive.
- Rename the extracted directory to
pyapp-latest. - Enter the directory.
Windows
- Download the source zip using
Invoke-WebRequest. - Extract the archive using
7z. - Rename the extracted directory to
pyapp-latest. - Enter the directory.
# Linux/macOS curl https://github.com/ofek/pyapp/releases/latest/download/source.tar.gz -Lo pyapp-source.tar.gz tar -xzf pyapp-source.tar.gz mv pyapp-v* pyapp-latest cd pyapp-latest # Windows (PowerShell) Invoke-WebRequest https://github.com/ofek/pyapp/releases/latest/download/source.zip -OutFile pyapp-source.zip 7z x pyapp-source.zip mv pyapp-v* pyapp-latest cd pyapp-latest- Download the source tarball using
Distribute the built binary
masterAfter building, rename the
pyappbinary to your application's name. On non-Windows systems, you must also ensure the file has executable permissions.Linux/macOS
mv target/release/pyapp cowsay && chmod +x cowsayWindows
mv target\release\pyapp.exe cowsayUse a custom Python distribution source
masterTo use a Python distribution not included in the known list, set the
PYAPP_DISTRIBUTION_SOURCEoption to a URL pointing to an archived version of the desired distribution.Note: Manually setting the source may require defining additional metadata (such as paths) to ensure correct runtime behavior.