Just (Python Wrapper)
rust-just is a Python wrapper for the `just` command runner, a powerful and simpler alternative to Make for project-specific task automation. It allows Python applications to programmatically invoke `just` recipes defined in a `Justfile`. The current version, 1.49.0, aligns with the version of the underlying `just` command-line tool, which maintains an active development cycle with frequent updates.
Warnings
- gotcha The `rust-just` Python package acts as a wrapper for the `just` command-line executable. Installing `rust-just` via pip DOES NOT install the `just` binary itself. You must install the `just` command-line tool separately on your system for the wrapper to function.
- gotcha The version of the `rust-just` Python package typically mirrors the version of the underlying `just` command-line tool it is designed to wrap. While the Python wrapper's API is generally stable, functionality changes, new features, or breaking changes in the `just` tool's CLI (e.g., recipe syntax, new flags) will only be reflected if a compatible `just` binary is installed and the wrapper is updated.
- gotcha If the `just` executable is not found in the system's PATH when `just_runner.run()` is called, it will raise a `subprocess.CalledProcessError` or `FileNotFoundError` (depending on the Python version and specific error scenario).
Install
-
pip install rust-just -
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -
choco install just
Imports
- Just
from just import Just
Quickstart
import os
import subprocess
# Create a dummy Justfile for demonstration
justfile_content = """
hello:
echo 'Hello from Just!'
greet NAME=\"World\":
echo "Hello, {{NAME}}!"
fail:
exit 1
"""
with open('Justfile', 'w') as f:
f.write(justfile_content)
try:
from just import Just
just_runner = Just()
print("Running 'hello' recipe:")
result_hello = just_runner.run(recipe='hello')
print(f"Output: {result_hello.stdout.strip()}\n")
print("Running 'greet' recipe with argument:")
result_greet = just_runner.run(recipe='greet', args=['NAME=Pythonista'])
print(f"Output: {result_greet.stdout.strip()}\n")
print("Attempting to run a non-existent recipe (expected error):")
try:
just_runner.run(recipe='non_existent')
except subprocess.CalledProcessError as e:
print(f"Caught expected error: {e.stderr.strip().splitlines()[0]} [...]")
print("Attempting to run 'fail' recipe (expected error):")
try:
just_runner.run(recipe='fail')
except subprocess.CalledProcessError as e:
print(f"Caught expected error with return code {e.returncode}\n")
finally:
# Clean up the dummy Justfile
if os.path.exists('Justfile'):
os.remove('Justfile')