Python API¶
airflow.providers.pixi.operators.pixi
¶
Run a Python callable inside a Pixi environment, and the base classes of every Pixi operator.
WORKER_PYTHON_VARIABLES
module-attribute
¶
Variables of the worker's Python left out of a pixi run, so the environment's Python never imports the
worker's packages; env_vars or env can set them for a run.
PixiOperator
¶
PixiOperator(
*,
env_vars: dict[str, str] | None = None,
skip_on_exit_code: int | Container[int] | None = None,
**kwargs: Any,
)
Bases: PixiSubprocessMixin, BasePixiPythonOperator
Run a Python callable inside a Pixi environment on the worker.
Accepts every BasePixiPythonOperator and BasePixiOperator
argument, plus those of PixiSubprocessMixin and PixiRunEnvMixin:
env_vars, env_from_variables, env_from_connections, pixi_conn_id, the cache directory Variables and
skip_on_exit_code. The return value is the task's XCom. The output of the run is streamed to the task log;
execution_timeout and killing the task stop pixi and everything it started.
Subclasses and mixins can change what runs, the same way as for @task.virtualenv: override
get_python_source, and set op_args, op_kwargs or env_vars,
or call add_pypi_dependencies, in execute before calling
super().execute.
Source code in src/airflow/providers/pixi/operators/pixi.py
PixiBranchOperator
¶
PixiBranchOperator(
*,
env_vars: dict[str, str] | None = None,
skip_on_exit_code: int | Container[int] | None = None,
**kwargs: Any,
)
Bases: PixiOperator, BranchMixIn
Choose the tasks to follow with a Python callable run inside a Pixi environment on the worker.
The Pixi counterpart of BranchPythonVirtualenvOperator. The callable returns a task id or task group id
directly downstream of this task, a list of them, or None. The tasks directly downstream that it does not
name are skipped, and the skips spread to the tasks after them as their trigger rules decide; None skips
them all. A task group id stands for the group's root tasks. As for BranchPythonOperator, the return value
becomes the task's XCom only when nothing is skipped: otherwise Airflow's task runner handles the skips instead.
Accepts every PixiOperator argument; context parameters such as params reach the callable as
for PixiOperator. A task id that is not in the DAG fails the task, and so does a return value that
is neither a string, a list of strings nor None.
Source code in src/airflow/providers/pixi/operators/pixi.py
PixiShortCircuitOperator
¶
Bases: PixiOperator, SkipMixin
Continue the pipeline only if a Python callable run inside a Pixi environment returns a truthy value.
The Pixi counterpart of ShortCircuitOperator. When the callable returns a falsy value, the tasks
downstream of this one are skipped, except teardown tasks. As for ShortCircuitOperator, the return value
becomes the task's XCom only when nothing is skipped: a truthy one, or a falsy one without downstream tasks.
Accepts every PixiOperator argument; context parameters such as params reach the callable as
for PixiOperator. Plus:
Parameters:
-
ignore_downstream_trigger_rules(bool, default:True) –if
True(default), skip every task downstream of this one, whatever its trigger rule. IfFalse, skip only the tasks directly downstream, and let the trigger rules of the tasks after them decide whether they run.
Source code in src/airflow/providers/pixi/operators/pixi.py
BasePixiPythonOperator
¶
BasePixiPythonOperator(
*,
python_callable: Callable[..., Any] | str,
op_args: Sequence[Any] | None = None,
op_kwargs: dict[str, Any] | None = None,
serializer: Literal["json", "pickle"] = "json",
**kwargs: Any,
)
Bases: BasePixiOperator
Base class of the Pixi operators that call a Python function inside the environment.
Accepts every BasePixiOperator argument, plus:
Parameters:
-
python_callable(Callable[..., Any] | str) –a function, whose source is shipped to the environment and run there, so it must be self-contained (imports inside it, no variables from enclosing functions); or a
"module.path:callable_name"string imported in the environment. The manifest's directory is the working directory, so modules next to it are importable. -
op_args(Sequence[Any] | None, default:None) –positional arguments for the callable (templated).
-
op_kwargs(dict[str, Any] | None, default:None) –keyword arguments for the callable (templated).
-
serializer(Literal['json', 'pickle'], default:'json') –how arguments and the return value travel:
"json"(default), or"pickle"for values JSON cannot hold, whose types must then be importable on both sides.Parameters of the callable named after a key of
CONTEXT_KEYS, such asds,paramsorrun_id, get the task's value whenop_argsandop_kwargsleave them unset, and a**kwargsparameter gets all of them, as for@task.virtualenv. Dates and datetimes arrive as ISO 8601 strings.Subclasses and mixins can change what runs, the same way as for
@task.virtualenv: overrideget_python_source, and setop_argsorop_kwargs, or calladd_pypi_dependencies, inexecutebefore callingsuper().execute.
Source code in src/airflow/providers/pixi/operators/pixi.py
get_python_source
¶
get_python_source() -> str
Return the source shipped to the environment when python_callable is a function.
The runner executes it and calls the name of python_callable in the resulting namespace. Task
decorators are removed, including the one named by custom_operator_name (@task.<name> of a
decorator built on @task.pixi) and this provider's decorator functions used under their own names
(@pixi_task(...)), and line numbers kept, so tracebacks point at the DAG file. Override it to wrap
the function, for example by appending code that rebinds the name to a wrapper, as for
@task.virtualenv.
Source code in src/airflow/providers/pixi/operators/pixi.py
callable_input
¶
Return the runner's input: the callable, its arguments and the task context, in the serializer's format.
Parameters:
-
context(Mapping[str, Any] | None, default:None) –the task context, of which the runner passes the JSON-safe part (
serializable_context) to parameters named after its keys.
Source code in src/airflow/providers/pixi/operators/pixi.py
BasePixiOperator
¶
BasePixiOperator(
*,
pixi_project_path: str | None = None,
pixi_toml_path: str | None = None,
environment: str | None = None,
lock_mode: Literal["locked", "frozen"] | None = None,
dependencies: dict[str, Any] | Sequence[str] | None = None,
pypi_dependencies: dict[str, Any] | Sequence[str] | str | None = None,
channels: Sequence[str] | None = None,
platforms: Sequence[str] | None = None,
env_cache_path: str | None = None,
cleanup_temp_manifest: bool = True,
pixi_binary: str = "pixi",
**kwargs: Any,
)
Bases: BaseOperator
Base class of the Pixi operators: chooses the Pixi environment and prepares it.
The environment comes from exactly one of pixi_project_path (a project directory),
pixi_toml_path (a pixi.toml or pyproject.toml) or an inline manifest: a list of packages in
dependencies / pypi_dependencies, with channels and platforms. Anything
else, such as PyPI indexes, features or several environments, belongs in a pixi.toml.
Parameters:
-
pixi_project_path(str | None, default:None) –a Pixi project directory, with a
pixi.tomlorpyproject.toml(templated). -
pixi_toml_path(str | None, default:None) –a
pixi.tomlorpyproject.toml; pixi uses exactly that file (templated). -
environment(str | None, default:None) –the environment of a project or manifest file to run in, if it defines several (templated). Not for inline manifests, which have only the default environment.
-
lock_mode(Literal['locked', 'frozen'] | None, default:None) –how pixi treats the
pixi.lockof a project or manifest file (templated).None(default) runs plainpixi run, which solves again and rewrites the lock file when it no longer matches the manifest."locked"passes--locked: the run fails if the lock file is out of date."frozen"passes--frozen: the environment is installed from the lock file as it is, without checking it against the manifest. Not for inline manifests, which have no lock file. -
dependencies(dict[str, Any] | Sequence[str] | None, default:None) –conda dependencies of an inline manifest, a dict or a list of MatchSpecs.
-
pypi_dependencies(dict[str, Any] | Sequence[str] | str | None, default:None) –PyPI dependencies of an inline manifest (templated): a dict as under
[pypi-dependencies]in apixi.toml, or pip requirement strings as@task.virtualenvtakes them, a list or one string that may hold several lines, such as a rendered requirements file. An inline manifest with PyPI packages but nopythondependency gets the worker's Python version. -
channels(Sequence[str] | None, default:None) –channels of an inline manifest; default
["conda-forge"]. -
platforms(Sequence[str] | None, default:None) –platforms of an inline manifest; default
default_platforms, the platform of the machine that runs pixi. -
env_cache_path(str | None, default:None) –keep inline environments in
<env_cache_path>/pixi-<hash>and reuse them across runs, likevenv_cache_pathofPythonVirtualenvOperator. Otherwise an inline environment is built in a temporary directory, removed after the run unlesscleanup_temp_manifest=False. -
cleanup_temp_manifest(bool, default:True) –remove the temporary directory of an inline environment after the run.
-
pixi_binary(str, default:'pixi') –the pixi executable, a name on
PATHor a path. It must be installed on the workers, in versionMIN_PIXI_VERSIONor newer; the provider never installs it.Where pixi runs on the worker (
local_manifest), a relativepixi_project_path,pixi_toml_pathorenv_cache_pathis relative to the directory of the DAG file there, or to the working directory for a task without a DAG.
Source code in src/airflow/providers/pixi/operators/pixi.py
inline_manifest
property
¶
inline_manifest: bool
Whether the environment comes from an inline manifest.
Only an inline manifest can be extended with add_pypi_dependencies.
add_pypi_dependencies
¶
add_pypi_dependencies(*requirements: str) -> None
Add pip requirement strings, such as "mytracker>=1", to the PyPI dependencies of the inline manifest.
For subclasses and mixins that need a package in the environment, whichever form the DAG gave
pypi_dependencies in: a dict gets the [pypi-dependencies] entries of requirements, pip
strings become a list with requirements at the end. pypi_dependencies is assigned a new value,
so a value saved before stays as it was and can be restored afterwards.
Raises:
-
AirflowException–if the environment comes from
pixi_project_pathorpixi_toml_path, whose manifest has to list the packages itself. -
ValueError–for a requirement
pypi_dependenciesdoes not accept, or a package listed twice.
Source code in src/airflow/providers/pixi/operators/pixi.py
inline_manifest_toml
¶
inline_manifest_toml() -> str
Return the pixi.toml of an inline manifest, from the rendered arguments.
Source code in src/airflow/providers/pixi/operators/pixi.py
default_platforms
¶
Return the platforms of an inline manifest without platforms: the one of the machine running pixi.
Called when the task runs. Pixi solves the environment for every platform of the manifest, and a package missing on one of them fails the solve, so only the platform that runs it is listed.
Source code in src/airflow/providers/pixi/operators/pixi.py
pixi_run_options
¶
Return the options of pixi run that follow --manifest-path: the environment and the lock mode.
Called when the task runs, as templated fields are then rendered.
Source code in src/airflow/providers/pixi/operators/pixi.py
pixi_run_command
¶
Return pixi run with the manifest and pixi_run_options.
The command to run in the environment goes after it.
Source code in src/airflow/providers/pixi/operators/pixi.py
local_manifest
¶
Yield the manifest to pass to pixi on the worker and the directory to run in.
An inline manifest is written to env_cache_path or to a temporary directory, removed afterwards
unless cleanup_temp_manifest=False. Runs at execution time, so templated paths are rendered. Relative
paths are resolved against the directory of the DAG file.
Source code in src/airflow/providers/pixi/operators/pixi.py
holding_manifest
¶
holding_manifest() -> Iterator[None]
Keep one local_manifest for every use inside, such as the pokes of one sensor run.
Source code in src/airflow/providers/pixi/operators/pixi.py
PixiSubprocessMixin
¶
PixiSubprocessMixin(
*,
env_vars: dict[str, str] | None = None,
skip_on_exit_code: int | Container[int] | None = None,
**kwargs: Any,
)
Bases: PixiRunEnvMixin
Run the runner with pixi on the worker, streaming its output to the task log.
Accepts every PixiRunEnvMixin argument, plus:
Parameters:
-
env_vars(dict[str, str] | None, default:None) –environment variables for the run, on top of all others. Not templated, so secrets set here are never rendered into the UI.
-
skip_on_exit_code(int | Container[int] | None, default:None) –exit codes of
pixi runthat skip the task instead of failing it, as forPythonVirtualenvOperator. The callable chooses one withsys.exit(code); an exception it raises exits with 1, and so does pixi when it cannot prepare the environment.An exception raised by the callable fails the task with
PixiCallableError, which names the callable and the exception; other failures of the run fail it with pixi's exit code and the last lines of output.execution_timeoutand killing the task stop pixi and everything it started.
Source code in src/airflow/providers/pixi/operators/pixi.py
run_callable
¶
Call python_callable in the environment and return its result.
Parameters:
-
context(Mapping[str, Any] | None, default:None) –the task context, for the callable's parameters named after its keys.
Source code in src/airflow/providers/pixi/operators/pixi.py
PixiRunEnvMixin
¶
PixiRunEnvMixin(
*,
env_from_variables: dict[str, str] | None = None,
env_from_connections: dict[str, str] | None = None,
pixi_conn_id: str | Sequence[str] | None = None,
pixi_cache_dir_variable: str | None = None,
uv_cache_dir_variable: str | None = None,
pip_cache_dir_variable: str | None = None,
**kwargs: Any,
)
Bases: BaseOperator
The environment variables of a pixi run on the worker, from Airflow Variables and Connections.
Everything is read when the task runs, never rendered as a template.
Parameters:
-
env_from_variables(dict[str, str] | None, default:None) –environment variable name to the key of an Airflow Variable, such as
{"API_URL": "api_url"}. A missing Variable fails the task. -
env_from_connections(dict[str, str] | None, default:None) –environment variable name to
"conn_id"(the connection's URI),"conn_id.<field>"(host,login,password,schema,port, orextraas a JSON string) or"conn_id.extra.<key>"(one key of the extra), such as{"DB_PASSWORD": "warehouse.password"}. A missing connection or field fails the task. Passwords, URIs and extras are masked in the task log. -
pixi_conn_id(str | Sequence[str] | None, default:None) –one or several connections of type
pixi(PixiHook) with credentials for private conda channels or PyPI indexes. Written to temporary files for the run, whichRATTLER_AUTH_FILEandNETRCpoint at. -
pixi_cache_dir_variable(str | None, default:None) –key of an Airflow Variable holding
PIXI_CACHE_DIRfor the run (templated); likewiseuv_cache_dir_variable(UV_CACHE_DIR) andpip_cache_dir_variable(PIP_CACHE_DIR). A missing Variable leaves the environment variable unset.pixi_run_envbuilds the run's environment from them.
Source code in src/airflow/providers/pixi/operators/pixi.py
pixi_run_env
¶
pixi_run_env(
base: Mapping[str, str], overrides: Mapping[str, str] | None = None
) -> Iterator[dict[str, str]]
Yield the environment of a pixi run, valid until the block exits.
In increasing precedence: base (usually the worker's environment) without the worker's Python settings
(WORKER_PYTHON_VARIABLES) and with PYTHONNOUSERSITE=1, so the environment's
Python imports only what the Pixi environment has; the cache directory Variables; env_from_variables and
env_from_connections; then overrides (such as env_vars), which can set those Python variables again.
With pixi_conn_id, RATTLER_AUTH_FILE and NETRC point at temporary files with the credentials, merged
with the files these variables named before (see
pixi_auth_env), and removed when the block exits.
Source code in src/airflow/providers/pixi/operators/pixi.py
airflow.providers.pixi.operators.bash
¶
Run a Bash command inside a Pixi environment.
PixiBashOperator
¶
Bases: PixiRunEnvMixin, BasePixiOperator, BashOperator
Run a Bash command inside a Pixi environment, like BashOperator.
The command runs as pixi run --manifest-path <manifest> [--environment <env>] [--locked | --frozen] bash -c
<command>, so every part of it, pipes and && included, sees the activated environment. Accepts every
BashOperator argument (bash_command, env, append_env, cwd, skip_on_exit_code,
output_processor, ...), every BasePixiOperator
argument for the environment, and the PixiRunEnvMixin
arguments env_from_variables, env_from_connections, pixi_conn_id and the cache directory Variables, as
PixiOperator does. cwd defaults to the manifest's directory. The last line of output is the task's XCom, as
for BashOperator.
Parameters:
-
env_vars(dict[str, str] | None, default:None) –environment variables for the run, on top of all others, as for
PixiOperator. Not templated, so secrets set here are never rendered into the UI.The environment of the run, in increasing precedence: the worker's environment, unless
envis set withoutappend_env=True; the cache directory Variables;env_from_variablesandenv_from_connections;env;env_vars.envreplaces the worker's environment unlessappend_env=True, as forBashOperator; pixi needs at leastHOMEandPATH, so passappend_env=Truewithenv.
Source code in src/airflow/providers/pixi/operators/bash.py
pixi_command
¶
Return the command that runs in place of bash_command: pixi run ... bash -c <bash_command>.
Called when the task runs, as templated fields are then rendered. Override it to run something else
through pixi, as PixiTaskOperator does.
Source code in src/airflow/providers/pixi/operators/bash.py
get_env
¶
Return the environment of the run: BashOperator's, with the variables of this operator merged in.
Called by execute; see the class docstring for the precedence. Files written for pixi_conn_id
exist until execute returns.
Source code in src/airflow/providers/pixi/operators/bash.py
airflow.providers.pixi.operators.task
¶
Run a task defined in a Pixi manifest.
PixiTaskOperator
¶
Bases: PixiBashOperator
Run a task from the [tasks] of a Pixi manifest, as pixi run <task> [task_args...] does.
The command is pixi run --manifest-path <manifest> [--environment <env>] [--locked | --frozen] <task>
<task_args...>, run through BashOperator's bash -c with each argument shell-quoted, so each one
reaches pixi unchanged, without word splitting or $ expansion by bash. Pixi appends them to the task's
command when it declares no args. A task that declares args gets their values substituted into its
cmd without quoting, which pixi's task shell then interprets, so don't pass it values someone else
controls, such as dag_run.conf. A name that is not a task is run as a command of the environment, as
pixi run does.
Accepts every PixiBashOperator argument except
bash_command: env, append_env, env_vars, env_from_variables, env_from_connections,
pixi_conn_id, the cache directory Variables, skip_on_exit_code (default 99), output_processor
and cwd, which defaults to the manifest's directory. The last line of output is the task's XCom. The
environment comes from pixi_project_path or pixi_toml_path: an inline manifest has no tasks.
Parameters:
-
task(str) –the name of the task (templated).
-
task_args(Sequence[str] | None, default:None) –arguments for the task, a list of strings (templated), or anything that resolves to one when the task runs, such as the output of another task.
Source code in src/airflow/providers/pixi/operators/task.py
pixi_command
¶
Return pixi run ... <task> <task_args...>, from the rendered task and task_args.
Source code in src/airflow/providers/pixi/operators/task.py
airflow.providers.pixi.operators.kubernetes
¶
Run a Python callable inside a Pixi environment in a Kubernetes pod.
Requires pip install "apache-airflow-providers-pixi[cncf.kubernetes]".
DEFAULT_IMAGE
module-attribute
¶
DEFAULT_IMAGE = f'ghcr.io/prefix-dev/pixi:{MIN_PIXI_VERSION}'
The official pixi image in the minimum supported version.
DEFAULT_POD_PLATFORMS
module-attribute
¶
The platforms of an inline manifest without platforms: those of the Linux nodes a pod can land on.
MAX_ENV_VALUE_BYTES
module-attribute
¶
The largest value one of the pod's environment variables may have.
Linux refuses to start a process with an environment string longer than MAX_ARG_STRLEN (128 KiB), so the
pod would fail to start; the margin leaves room for the variable's name.
PixiKubernetesPodOperator
¶
PixiKubernetesPodOperator(
*, image: str | None = DEFAULT_IMAGE, do_xcom_push: bool = True, **kwargs: Any
)
Bases: BasePixiPythonOperator, KubernetesPodOperator
Run a Python callable inside a Pixi environment in a Kubernetes pod.
Accepts every BasePixiPythonOperator argument and
every KubernetesPodOperator argument except cmds and arguments, which run the callable. Paths
(pixi_project_path, pixi_toml_path, env_cache_path) are paths in the pod, a relative one relative to the
image's working directory, and pixi_binary is the pixi executable of the image.
Parameters:
-
image(str | None, default:DEFAULT_IMAGE) –an image with pixi
MIN_PIXI_VERSIONor newer, GNUsortandbase64, and the project forpixi_project_path. DefaultDEFAULT_IMAGE.The function's source, its arguments, the task context and an inline manifest reach the pod in environment variables, so they are visible in the pod's spec, and each must stay under
MAX_ENV_VALUE_BYTES. The return value comes back through the XCom sidecar (do_xcom_pushdefaults toTruehere), also withdeferrable=True. An inline manifest withoutplatformsis solved forDEFAULT_POD_PLATFORMS, in the pod on each run; mount a volume atenv_cache_pathto reuse it. An exception raised by the callable fails the task withPixiCallableError.
Source code in src/airflow/providers/pixi/operators/kubernetes.py
xcom_dir
class-attribute
instance-attribute
¶
Where the KubernetesPodOperator sidecar reads return.json: the path it mounts its volume at.
termination_message_path
class-attribute
instance-attribute
¶
Where Kubernetes reads the container's termination message, its default terminationMessagePath.
default_platforms
¶
Return DEFAULT_POD_PLATFORMS: pods run on Linux nodes, not on the worker.
pod_script
¶
pod_script() -> str
Return the shell script the pod runs: check pixi, write the inputs, run the callable.
Source code in src/airflow/providers/pixi/operators/kubernetes.py
pod_env_vars
¶
Return the environment variables that carry the callable, its arguments and an inline manifest.
Parameters:
-
context(Mapping[str, Any] | None, default:None) –the task context, of which the JSON-safe part reaches the callable.
Raises:
-
AirflowException–if the input or the manifest is longer than
MAX_ENV_VALUE_BYTES, so the task fails before the pod is created.
Source code in src/airflow/providers/pixi/operators/kubernetes.py
airflow.providers.pixi.sensors.pixi
¶
Wait for a Python callable running inside a Pixi environment to report success.
PixiSensor
¶
PixiSensor(
*,
env_vars: dict[str, str] | None = None,
skip_on_exit_code: int | Container[int] | None = None,
**kwargs: Any,
)
Bases: PixiSubprocessMixin, BasePixiPythonOperator, BaseSensorOperator
Wait for a Python callable, run inside a Pixi environment on each poke, to return a truthy value.
Like PythonSensor, but the callable runs in the Pixi environment, as for
PixiOperator, whose arguments it accepts, together with
every BaseSensorOperator argument (poke_interval, timeout, mode, soft_fail, ...).
To finish with an XCom value, return {"is_done": True, "xcom_value": value}, the fields of
PokeReturnValue, which Airflow cannot pass into the environment itself.
In mode="poke" the environment is prepared once for all pokes of a run. In mode="reschedule"
each poke is a new run, so pass env_cache_path to keep an inline environment between them.
Source code in src/airflow/providers/pixi/operators/pixi.py
airflow.providers.pixi.decorators.pixi
¶
@task.pixi: run the function inside a Pixi environment.
PixiDecoratedOperator
¶
PixiDecoratedOperator(
*,
python_callable: Callable[..., Any],
op_args: Sequence[Any] | None = None,
op_kwargs: Mapping[str, Any] | None = None,
**kwargs: Any,
)
Bases: DecoratedOperator, PixiOperator
@task.pixi: run the function inside a Pixi environment.
Source code in src/airflow/providers/pixi/decorators/pixi.py
pixi_task
¶
pixi_task(
python_callable: Callable[..., Any] | None = None,
multiple_outputs: bool | None = None,
**kwargs: Any,
)
@task.pixi: run the function inside a Pixi environment.
Accepts every PixiOperator argument. Like @task.virtualenv, the function's source is
shipped to the environment, so it must be self-contained: imports go inside the function.
Source code in src/airflow/providers/pixi/decorators/pixi.py
airflow.providers.pixi.decorators.bash
¶
@task.pixi_bash: run the Bash command a function returns inside a Pixi environment.
pixi_bash_task
¶
@task.pixi_bash: run the Bash command the function returns inside a Pixi environment.
Like @task.bash: the function runs on the worker and returns the command, which is rendered as a
template and then run with pixi run ... bash -c. Accepts every PixiBashOperator argument.
Source code in src/airflow/providers/pixi/decorators/bash.py
airflow.providers.pixi.decorators.kubernetes
¶
@task.pixi_kubernetes: run the function inside a Pixi environment in a Kubernetes pod.
pixi_kubernetes_task
¶
pixi_kubernetes_task(
python_callable: Callable[..., Any] | None = None,
multiple_outputs: bool | None = None,
**kwargs: Any,
)
@task.pixi_kubernetes: run the function inside a Pixi environment in a Kubernetes pod.
Accepts every PixiKubernetesPodOperator argument. As for @task.pixi, the function's source is
shipped, so it must be self-contained. Requires
pip install "apache-airflow-providers-pixi[cncf.kubernetes]".
Source code in src/airflow/providers/pixi/decorators/kubernetes.py
airflow.providers.pixi.decorators.sensor
¶
@task.pixi_sensor: a sensor whose function runs inside a Pixi environment on each poke.
pixi_sensor_task
¶
@task.pixi_sensor: a sensor whose function runs inside a Pixi environment on each poke.
Like @task.sensor. The function returns a truthy value when the condition is met, or
{"is_done": ..., "xcom_value": ...} to also push an XCom. Accepts every PixiSensor argument.
Source code in src/airflow/providers/pixi/decorators/sensor.py
airflow.providers.pixi.decorators.branch
¶
@task.pixi_branch: choose the tasks to follow with a function run inside a Pixi environment.
pixi_branch_task
¶
pixi_branch_task(
python_callable: Callable[..., Any] | None = None,
multiple_outputs: bool | None = None,
**kwargs: Any,
)
@task.pixi_branch: choose the tasks to follow with a function run inside a Pixi environment.
Like @task.branch_virtualenv. The function returns a task id or task group id directly downstream, a
list of them, or None to skip them all. Accepts every PixiBranchOperator argument; as for
@task.pixi, the function's source is shipped, so it must be self-contained.
Source code in src/airflow/providers/pixi/decorators/branch.py
airflow.providers.pixi.decorators.short_circuit
¶
@task.pixi_short_circuit: continue only if a function run inside a Pixi environment returns a truthy value.
pixi_short_circuit_task
¶
pixi_short_circuit_task(
python_callable: Callable[..., Any] | None = None,
multiple_outputs: bool | None = None,
**kwargs: Any,
)
@task.pixi_short_circuit: continue only if a function run inside a Pixi environment returns a truthy value.
Like @task.short_circuit. A falsy return value skips the tasks downstream. Accepts every
PixiShortCircuitOperator argument, such as ignore_downstream_trigger_rules; as for @task.pixi, the
function's source is shipped, so it must be self-contained.
Source code in src/airflow/providers/pixi/decorators/short_circuit.py
airflow.providers.pixi.hooks.pixi
¶
Credentials of private conda channels and PyPI indexes for pixi, from Airflow connections of type pixi.
Pixi reads conda channel credentials from the JSON file named by RATTLER_AUTH_FILE and PyPI index credentials
from the netrc file named by NETRC (https://pixi.sh/latest/deployment/authentication/). For a run,
pixi_auth_env writes both to temporary files and removes them afterwards.
AUTH_TYPES
module-attribute
¶
Values of the auth_type extra of a pixi connection.
PixiHook
¶
Bases: BaseHook
Credentials of a private conda channel or PyPI index, from an Airflow connection of type pixi.
The connection's host is the host of the channel or index, such as repo.prefix.dev (a URL is reduced
to its host name; *.prefix.dev matches every subdomain of a channel). password is the token or the
password, and login the username for basic_http and netrc. auth_type in the extra chooses how
pixi sends them:
"auto"(default):basic_httpif the connection has a login, otherwisebearer_token."bearer_token": anAuthorization: Bearerheader, as prefix.dev uses."conda_token": a token in the channel URL, as anaconda.org and quetz use."basic_http": HTTP basic authentication, as Artifactory and Nexus use."netrc": a netrc entry, for a PyPI index named in[pypi-options]of a project'spixi.toml.
Parameters:
-
pixi_conn_id(str, default:default_conn_name) –the connection id.
Source code in src/airflow/providers/pixi/hooks/pixi.py
get_ui_field_behaviour
classmethod
¶
get_credentials
¶
get_credentials() -> PixiCredentials
Return the connection's credentials; the token or password is masked in the task log.
Source code in src/airflow/providers/pixi/hooks/pixi.py
PixiCredentials
dataclass
¶
Credentials for one host, from a pixi connection.
Parameters:
-
conn_id(str) –the connection they come from.
-
auth_type(str) –one of
AUTH_TYPESexcept"auto". -
host(str) –the host name pixi looks them up by, such as
repo.prefix.devor*.prefix.dev. -
login(str | None) –the username of
basic_httpandnetrc. -
secret(str) –the token or password.
rattler_entry
¶
Return the value for host in pixi's credentials file, for a conda channel.
Source code in src/airflow/providers/pixi/hooks/pixi.py
pixi_auth_env
¶
pixi_auth_env(
conn_ids: str | Sequence[str] | None, env: Mapping[str, str]
) -> Iterator[dict[str, str]]
Yield RATTLER_AUTH_FILE and NETRC for the credentials of the pixi connections conn_ids.
Each points at a temporary file, readable only by the worker's user and removed when the block exits; only
the variables the connections need are set, and none without connections. While RATTLER_AUTH_FILE is
set, pixi reads no other credentials, so the file also holds those of the file pixi would read otherwise:
the one env names in RATTLER_AUTH_FILE, or ~/.rattler/credentials.json. Likewise the netrc file
starts with the connections' entries, followed by the one env names in NETRC, or ~/.netrc.
Credentials in the system keychain are not copied. In the credentials file, a connection's entry replaces
one for the same host; netrc readers differ in which entry of a host they use, so keep a host in one place.
Parameters:
-
conn_ids(str | Sequence[str] | None) –a connection id, or several, each for another host.
-
env(Mapping[str, str]) –the environment pixi will run with, for
HOMEand the files it names.
Source code in src/airflow/providers/pixi/hooks/pixi.py
airflow.providers.pixi.exceptions
¶
Exceptions raised by the Pixi operators.
PixiCallableError
¶
Bases: AirflowException
The Python callable raised an exception inside the Pixi environment.
The message names the callable and the exception, such as train raised ValueError: no rows; the
traceback is in the task log, where the run printed it, and in traceback.
Parameters:
-
callable_name(str) –the function's name, or the
"module.path:callable_name"string. -
error_type(str) –the exception's class, with its module unless it is a built-in, such as
ValueErrororrequests.exceptions.HTTPError. -
error_message(str) –str()of the exception. -
traceback(str) –the traceback, formatted inside the environment.
Source code in src/airflow/providers/pixi/exceptions.py
airflow.providers.pixi.utils.pixi
¶
The pixi binary on the worker: where it is, whether it is new enough, and the platform it installs for.
Pixi is never installed here.
MIN_PIXI_VERSION
module-attribute
¶
Oldest pixi this provider supports. The integration and system tests run against it.
local_platform
¶
local_platform() -> str
Return the pixi platform of this machine, such as linux-64 or osx-arm64.
Source code in src/airflow/providers/pixi/utils/pixi.py
airflow.providers.pixi.utils.context
¶
The part of the Airflow context a callable in a Pixi environment receives, as JSON values.
The environment may not have Airflow or pendulum, so the context travels as plain JSON: dates and datetimes as
ISO 8601 strings, params and the DAG run's conf as dicts.
CONTEXT_KEYS
module-attribute
¶
CONTEXT_KEYS: tuple[str, ...] = (
*dict.fromkeys((*_PLAIN_KEYS, *_TASK_INSTANCE_KEYS, "params", "conf")),
)
The keys a callable can receive, when the task's context has them.
serializable_context
¶
Return the context values of CONTEXT_KEYS that context has, as JSON values.
Dates and datetimes become ISO 8601 strings, params a plain dict and the DAG run's conf conf.
dag_id, task_id, map_index and try_number come from the task instance. A value JSON cannot
hold is left out, as is a key the context does not have.
Source code in src/airflow/providers/pixi/utils/context.py
airflow.providers.pixi.utils.env
¶
Environment variables of a pixi run from Airflow Variables and Connections, read on the worker when it runs.
Values never pass through templates. Passwords, connection URIs and extras are masked in the task log.
CONNECTION_FIELDS
module-attribute
¶
The fields env_from_connections can name after the connection id, as "<conn_id>.<field>".
resolve_env
¶
resolve_env(
*,
env_from_variables: Mapping[str, str] | None = None,
env_from_connections: Mapping[str, str] | None = None,
optional_variables: Mapping[str, str | None] | None = None,
) -> dict[str, str]
Return the environment variables read from Airflow Variables and Connections, for the worker's run.
Parameters:
-
env_from_variables(Mapping[str, str] | None, default:None) –environment variable name to the key of a Variable, which must exist.
-
env_from_connections(Mapping[str, str] | None, default:None) –environment variable name to
"conn_id"(the connection's URI),"conn_id.<field>"(host,login,password,schema,port, orextraas a JSON string) or"conn_id.extra.<key>"(one key of the extra; a value that is not a string as JSON). The connection and the field must exist. -
optional_variables(Mapping[str, str | None] | None, default:None) –environment variable name to the key of a Variable whose value, stripped of surrounding whitespace, is used if the Variable exists;
Noneor a missing Variable leaves it out. For the cache directory Variables.env_from_variablesandenv_from_connectionswin overoptional_variables. Passwords, URIs and extras of connections are masked in the task log; Variables are masked as Airflow masks them, by their key.
Source code in src/airflow/providers/pixi/utils/env.py
parse_connection_reference
¶
Split an env_from_connections value into the connection id, the field and the key of extra.
"conn_id" is the connection's URI (field None), "conn_id.password" one field, and
"conn_id.extra.key" one key of the extra. The first .<field> names the field, so a connection id
cannot itself contain .host, .login, .password, .schema, .port or .extra. Only
extra takes a key: "conn_id.port.internal" is rejected rather than read as the whole port.
Source code in src/airflow/providers/pixi/utils/env.py
airflow.providers.pixi.utils.manifest
¶
Inline Pixi manifests: pixi.toml written from operator arguments.
pypi_dependencies_table
¶
pypi_dependencies_table(
pypi_dependencies: dict[str, Any] | Sequence[str] | str | None,
) -> dict[str, Any]
[pypi-dependencies] from a dict as in pixi.toml, or from pip requirement strings.
The strings are a list, or one string, as @task.virtualenv takes them. A string may hold several lines,
such as a rendered requirements file; blank lines and comments are skipped. Versions, extras, git and URL
requirements are supported.
Raises:
-
ValueError–for a pip option, such as
--index-url, or an environment marker, which have no equivalent in an inline manifest and belong in apixi.toml; for an invalid requirement; and for a package listed twice.
Source code in src/airflow/providers/pixi/utils/manifest.py
conda_dependencies
¶
[dependencies] from a dict, or from a list of MatchSpecs such as "numpy>=2".
A MatchSpec is [channel::]name [version [build]], such as "conda-forge::pytorch 2.* cuda*".
Raises:
-
TypeError–for a string, which would otherwise be read one character at a time.
-
ValueError–for a MatchSpec of another form, or a package listed twice.
Source code in src/airflow/providers/pixi/utils/manifest.py
airflow.providers.pixi.runtime.runner
¶
Call a function inside the Pixi environment and hand its result back to the worker.
The operators run this module's source as python -c <source> <serializer> <input> <output> [json].
The input file holds the callable, either "module" and "name" or a function's "source", "filename"
and "name", with its "args", "kwargs" and an optional JSON-safe "context", in the serializer's
format. The return value goes to the output file, which keeps stdout and stderr free for the task log. With
json as the fourth argument, a pickled result is written as a base64 JSON string, for a pod's XCom file.
An exception from the callable, or an environment Python older than MIN_PYTHON, is described in
<output> + ERROR_SUFFIX and, when the environment variable
TERMINATION_LOG_ENV names a file, there too, shortened to fit a Kubernetes termination message.
Either exits with 1.
ERROR_SUFFIX
module-attribute
¶
Appended to the output path for the file describing an exception from the callable.
TERMINATION_LOG_ENV
module-attribute
¶
Environment variable naming the file Kubernetes reads as the container's termination message.
TERMINATION_KEY
module-attribute
¶
Key of the exception's description in the termination message.
TERMINATION_MESSAGE_BYTES
module-attribute
¶
The longest termination message written; Kubernetes keeps up to 4 KiB of it.
PICKLE_PROTOCOL
module-attribute
¶
Pickle protocol of the input and the result, readable by every Python the runner supports.
MIN_PYTHON
module-attribute
¶
The oldest Python the runner supports in the Pixi environment.
SHIPPED_MODULE
module-attribute
¶
__name__ of the namespace a shipped function's source runs in.
unsupported_python
¶
Return why the environment's Python cannot run the callable, or None if it is new enough.
Source code in src/airflow/providers/pixi/runtime/runner.py
load_spec
¶
Return the callable's description and arguments from the input file.
Source code in src/airflow/providers/pixi/runtime/runner.py
load_callable
¶
Return the callable: the shipped function, compiled under the DAG file's name, or module:name.
Source code in src/airflow/providers/pixi/runtime/runner.py
with_context
¶
with_context(
fn: Callable[..., Any],
args: Sequence[Any],
kwargs: dict[str, Any],
context: Mapping[str, Any],
) -> dict[str, Any]
Return kwargs with the context values for the parameters args and kwargs leave open.
A function with **kwargs gets every context value, as Airflow's determine_kwargs passes them.
Source code in src/airflow/providers/pixi/runtime/runner.py
await_result
¶
Return result, awaited first if it is awaitable, as the result of a coroutine function.
Source code in src/airflow/providers/pixi/runtime/runner.py
encode_result
¶
Return the content of the output file for result.
Source code in src/airflow/providers/pixi/runtime/runner.py
describe_error
¶
describe_error(error: BaseException) -> dict[str, str]
Return the exception's type (with its module unless built in), message and traceback.
Source code in src/airflow/providers/pixi/runtime/runner.py
termination_message
¶
Return error as a termination message of at most limit bytes, keeping the end of the traceback.
Source code in src/airflow/providers/pixi/runtime/runner.py
report_error
¶
Print the traceback and write the error file, and the termination message when one is asked for.
Source code in src/airflow/providers/pixi/runtime/runner.py
main
¶
Run the callable described by argv (-c, serializer, input, output, optionally json).