Skip to main content

Python wrapper for the PyCrucible CLI tool

Project description

Poster image of PyCrucible

Overview

This tool runs a Python application using the UV binary. It extracts your application, optionally reads configuration from pycrucible.toml or pyproject.toml, and uses uv to execute it in an ephemeral environment.

What does this mean?

You get a single self-contained binary that can be distributed across machines running the same platform. No Python installation is required - just an internet connection. Run the executable, and it takes care of the rest.

Community

You can visit our community group on Telegram PyCrucible Telegram Community

Changelog

You can see latest changes at CHANGELOG FILE.

Github Action

PyCrucible has associated GitHub Action workflow which you can use to embed your python applications directly in CI. GitHub Action marketplace. GitHub Repository

Documentation

Documentation can be found at PyCrucible docs.

How to get PyCrucible

There are a couple of ways to get PyCrucible.

Using PyPI

PyCrucible is published to PyPI for every release. All you need to do is:

pip install pycrucible

Using Github Releases

You can download pre-made binaries for your system from Github Releases page

Downloading and building from source code

  1. Ensure you have Rust installed.

  2. Clone the repository git clone https://github.com/razorblade23/PyCrucible

  3. Change directory to be inside of a project cd PyCrucible

  4. Build Runner cargo build -p pycrucible_runner --release

  5. Build Pycrucible cargo build -p pycrucible --release

[!NOTE] The resulting binary will be in target/release/pycrucible.

How to use PyCrucible

All you need for starting is a single main.py file with some code.

If you installed it using pip you can just run it with:

pycrucible -e .

This will embed your project and produce a new binary which is by default called launcher (or launcher.exe on Windows).

[!TIP] To configure the output path and name of your binary, use -o or --output flag.

Example: pycrucible -e . -o ./myapp (or pycrucible -e . -o ./myapp.exe)

This is now all you need to distribute your python project to other people.

No python required on their end. Just this single binary.

Running pycrucible --help reveals more options:

$ pycrucible --help
Tool to generate python executable by melding UV and python source code in crucible of one binary

Usage: pycrucible [OPTIONS]

Options:
  -e, --embed <EMBED>
          Directory containing Python project to embed. When specified, creates a new binary with the embedded project
  -o, --output <OUTPUT>
          Output path for the new binary when using --embed
      --uv-path <UV_PATH>
          Path to `uv` executable. If not found, it will be downloaded automatically [default: `.`]
      --debug
          Enable debug output
  -h, --help
          Print help
  -V, --version
          Print version

How to configure PyCrucible

Configuration can be set in two files:

  • pycrucible.toml
  • pyproject.toml

[!NOTE] When both pycrucible.toml and pyproject.toml are discovered, configuration from pycrucible.toml will take effect.

[!IMPORTANT] When using any configuration, only entrypoint is required. Other options are optional.

[!TIP] In both pycrucible.toml and pyproject.toml directive entrypoint can also be replaced by just entry.

Both of these files have exact same configuration options. You can find example file for pycrucible.toml here

In pycrucible.toml you would define configuration like this:

entrypoint = "src/main.py"
# or
entry = "src/main.py"

[options]
debug = false
extract_to_temp = false
delete_after_run = false

[patterns]
include = [
    "**/*.py",
]
exclude = [
    "**/__pycache__/**",
]

[env]
FOO = "foo"
BAR = "bar"

[hooks]
pre_run = "some_script.py"
post_run = "some_other_script.py"

In pyproject.toml you would define configuration like this:

[tool.pycrucible]
entrypoint = "src/main.py"
# or
entry = "src/main.py"

[tool.pycrucible.options]
debug = false
extract_to_temp = false
delete_after_run = false
offline_mode = false

[tool.pycrucible.patterns]
include = [
    "**/*.py",
]
exclude = [
    "**/__pycache__/**",
]

[tool.pycrucible.env]
FOO = "foo"
BAR = "bar"

[tool.pycrucible.hooks]
pre_run = "some_script.py"
post_run = "some_other_script.py"

[!TIP] You can use patterns to include or exclude any arbitrary files, like HTML templates, Kivy layout files or any other arbitrary files needed for your application.

[!IMPORTANT] There is no need for setting PYTHONPATH env variable as uv will take care of this. If this is really needed, uv will complain and you should also also set UV_LINK_MODE="copy" as env variable to mitigate the warning.

Update your project from GitHub

In configuration file its possible to set your GitHub repository, so the resulting binary will always check for update before running the application.

In pycrucible.toml it would look like this:

[source]
repository = "https://github.com/username/repo"
branch = "main"
update_strategy = "pull"

In pyproject.toml it would look like this-

[tool.pycrucible.source]
repository = "https://github.com/username/repo"
branch = "main"
update_strategy = "pull"

Default configuration

entrypoint = "main.py"

# Options
debug = false
extract_to_temp = false
delete_after_run = false

# Patterns
patterns.include = [
    "**/*.py",
]
patterns.exclude = [
    ".venv/**/*",
    "**/__pycache__/**",
    ".git/**/*",
    "**/*.pyc",
    "**/*.pyo",
    "**/*.pyd"
]

# Source repository (GitHub)
source = None

# Enviroment variables
env = None

# Pre and post run hooks
hooks = None

If any of these configuration options is not used, it will be replaced with default value.

NOTE - entrypoint directive is required when using any configuration options.

Security / Code signing

For users who want to verify the authenticity of the builder binary, we recommend code signing. This ensures that the binary you download has not been tampered with. Code signing will be automatic in next release of PyCrucible.

The builder is the only distributed artifact; the Python projects themselves are provided by users at runtime.

Signing the builder ensures the binary is authentic.

Generated self-contained binaries (created by the builder) are not pre-signed — users may optionally sign them for their own distribution.

[!IMPORTANT] Make sure you run code signing after embedding your project. This makes sure that embedded project also be part of the signiture.

Features

  • Cross-Platform:
    • Windows support
    • macOS support (testing)
    • Linux support
  • Small overhead:
    • Runner binary that embeds your project is just 2 MB. This ofcourse grows with embedding uv and your project.
  • Configurable:
    • Use pycrucible.toml or pyproject.toml to customize embedding details
      • entrypoint
      • include/exlude files
      • arguments to uv
      • env variables
      • update source code from github
      • pre and post run hooks (python scripts)
      • offline mode
      • extract to temporary directory (removes temporary directory after running automaticly)
      • remove extracted files after running
    • Support for multiple ways of defining requirements
      • uv initialized pyproject.toml (This is preffered !)
      • requirements.txt
      • pylock.toml
      • setup.py
      • setup.cfg
    • Load the project as a directory
  • Tests:
    • Unit tests covering as much as i can make it

Thanks to

The idea is inspired by Packaged.

Thanks to all the briliant developers at Astral. They did awesome job with uv.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycrucible-0.3.1-py3-none-win_amd64.whl (2.6 MB view details)

Uploaded Python 3Windows x86-64

pycrucible-0.3.1-py3-none-manylinux_2_39_x86_64.whl (2.7 MB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

pycrucible-0.3.1-py3-none-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

pycrucible-0.3.1-py3-none-macosx_10_12_x86_64.whl (2.4 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file pycrucible-0.3.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: pycrucible-0.3.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycrucible-0.3.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1ad33a8c613c0040d0c900b75b3928a1ecb8a2437fce83a19bda6e76c64fba10
MD5 5df20991dbecb263cb35b9c764c63f25
BLAKE2b-256 f01b3bbe53d0aae7a253e0fc9a2489db37115f926908720edd1c4600a4caef61

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycrucible-0.3.1-py3-none-win_amd64.whl:

Publisher: v0.3-pipeline.yml on razorblade23/PyCrucible

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycrucible-0.3.1-py3-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for pycrucible-0.3.1-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 637d9d6427c012bc62fab76d9037aa0ca528c75f1eb06a41e2d87de303e50bd7
MD5 49413268cf0390ba20c18b270a09d99a
BLAKE2b-256 c63886320ab417f6de6b326f552b0384518487fb34d84a7c11a7730238ae7f1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycrucible-0.3.1-py3-none-manylinux_2_39_x86_64.whl:

Publisher: v0.3-pipeline.yml on razorblade23/PyCrucible

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycrucible-0.3.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycrucible-0.3.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e5580902fa74363148a19f7453654237c7fc5ebc46c052a5e070469157e65ba6
MD5 80b0372ce628c227cacb58a0aa2db38d
BLAKE2b-256 2314021fb2a1d789c62d1ee7a94630c83bf6d6c696f4913a3bc3b7e637524204

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycrucible-0.3.1-py3-none-macosx_11_0_arm64.whl:

Publisher: v0.3-pipeline.yml on razorblade23/PyCrucible

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycrucible-0.3.1-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pycrucible-0.3.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ed66efb01f436066614522be7fc44c8485f57aafc1cc9704becd961099552522
MD5 2295acdaceb1bce35e2597b2dc1bd03a
BLAKE2b-256 e88faf95fa95f16bc2cbfa07f0c6f0249638c499e6571cb6f04d1b709bd64c4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycrucible-0.3.1-py3-none-macosx_10_12_x86_64.whl:

Publisher: v0.3-pipeline.yml on razorblade23/PyCrucible

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page