Skip to main content

uairt (Python)

A ctypes binding for the Unified AI Runtime C API. Pure Python plus NumPy; no compiler is needed to install it, but it needs the shared library libuairt.

From a wheel on PyPI (see docs/releasing.md), which carries the native library and the ONNX Runtime plugin, so nothing else is built:

pip install "uairt[onnxruntime]"

From source, for development:

cmake -S ../.. -B ../../build-shared -DBUILD_SHARED_LIBS=ON && cmake --build ../../build-shared
export UAIRT_LIBRARY=$PWD/../../build-shared/libuairt.dylib      # .so on Linux
pip install -e .
import numpy as np
import uairt

uairt.load_backend_library("libuairt_backend_onnxruntime.so")   # a plugin per backend
with uairt.Engine("onnxruntime", intra_op_threads=1) as engine:
    with engine.load_model("model.onnx") as model:
        print(model.inputs, model.outputs)          # TensorInfo(name, dtype, shape, quant_scale, ...)
        x = np.zeros(model.inputs[0].shape, model.inputs[0].dtype)
        (y,) = model.run(x)

AutoModel and plugin discovery

AutoModel picks the backend from the model file and the device, so you do not need to know which plugin or which options a runtime takes. It is a thin layer over Engine and Model, which stay available.

import uairt

with uairt.AutoModel.from_file("yolov8n.onnx", device="gpu") as model:
    print(model.backend, model.options)        # onnxruntime {'execution_provider': 'cuda'}
    (y,) = model.run(x)

uairt.AutoModel.from_file("face_det.dlc", device="npu")                  # qnn
uairt.AutoModel.from_file("rtmdet.onnx", device="npu")                   # onnxruntime + onnxruntime-qnn
uairt.AutoModel.from_file("yolov8n_ncnn_model", device="gpu", input_shapes="3x640x640")   # ncnn on Vulkan
uairt.AutoModel.resolve("m.onnx", device="gpu")                           # the plan only, nothing loaded
  • Backend by file: .dlc and .bin go to qnn, .onnx to onnxruntime (then openvino), .xml to openvino, .param to ncnn, .engine and .plan to tensorrt, .tflite to tflite, .mlmodelc, .mlpackage and .mlmodel to coreml. A directory is judged by what it holds (an ultralytics _openvino_model or _ncnn_model export). Pass backend= to choose.
  • Device: cpu, gpu, npu, cuda, tensorrt or vulkan, with an optional index (gpu:1), or None for the backend's default. It is mapped to that backend's own options (device=npu for QNN, execution_provider=cuda for ONNX Runtime, device=GPU for OpenVINO, device=vulkan for NCNN, and so on). QNN's default is npu. For an .onnx file, device="npu" uses the onnxruntime-qnn package's QNN plugin and selects its NPU device automatically; install that package first. options={"ep_name": "MLXExecutionProvider"} (or QNNExecutionProvider, WebGpuExecutionProvider) finds the plugin library from its installed package and selects the matching device type.
  • Strict: the first candidate that is available (registered, or with a plugin that can be found) and supports the device is used. If it fails to load, that error is raised: there is no fallback to another runtime or to the CPU. A device a backend cannot serve raises Unsupported; no usable plugin raises NotFound. Both say why each candidate was passed over. model.plan.skipped lists the candidates passed over.
  • Options: keyword arguments and options={...} go to the backend and override the device mapping.

Backend plugins are found, and loaded when an engine asks for them, in this order: UAIRT_PLUGIN_PATH (directories separated like PATH), the package's own plugins/ directory, the directory of the loaded libuairt, and its uairt/ subdirectory. A plugin is a file named libuairt_backend_<name>.so, .dylib or .dll. uairt.load_backend_library(path) still loads one by path, and uairt.available_backends() and uairt.discover_plugins() show what is registered and what was found. A plugin still needs its vendor runtime installed; loading it reports that.

examples/python/auto_model.py loads any model this way and prints what was chosen.

  • Inputs must match the model's dtype and shape exactly; the binding never converts silently.
  • Errors are uairt.UairtError subclasses (NotFound, Unsupported, IncompatibleModel, IoFailure, ...) carrying .status and .message.
  • Engine.alloc_buffer(n, "host" | "dmabuf" | "pinned") and Model.run_buffers give zero-copy buffers; Buffer.array(dtype, shape) is a NumPy view.
  • Models and buffers keep their engine alive. Close models before buffers they used.
  • Threading follows the C API: do not run one model from several threads at once.

Tests: UAIRT_LIBRARY=... pytest bindings/python/tests. Set UAIRT_TEST_ORT_PLUGIN to the ONNX Runtime plugin to also run the two-input/two-output test. The session tests (test_sessions.py) need UAIRT_TEST_SESSION_PLUGIN (the fake-session plugin built by CMake, uairt_session_test_1) and, for the real-model tests, UAIRT_TEST_LLAMACPP_PLUGIN (the llamacpp plugin) and UAIRT_LLAMACPP_TEST_MODEL (a GGUF path); without them those tests are skipped. In a shared-library build (-DBUILD_SHARED_LIBS=ON) with pytest and NumPy importable, the python_sessions ctest sets these variables (except the model path, which it inherits from the environment) and runs the whole directory.

Windows ARM64: use an ARM64 Python (an x64 Python cannot load the ARM64 uairt.dll), build libuairt as a DLL and set UAIRT_LIBRARY to build-shared\Debug\uairt.dll. examples/python/run_qnn.py <plugin> <QAIRT root> <model.dlc> [npu|cpu|gpu] runs a model through the QNN plugin (0.8 ms on the Snapdragon X Elite NPU for face_det_lite). Set ADSP_LIBRARY_PATH to <QAIRT root>\lib\hexagon-v73\unsigned before starting Python for npu; see the Rust README for the caveat.

Language models (GGUF)

With the llamacpp plugin available, uairt.AutoModel.from_file("model.gguf", device="gpu") loads a GGUF model (device="gpu" is n_gpu_layers=99, "cpu" is 0; add options={"device": "CUDA0"} to pick one llama.cpp device, and pass n_ctx to the session: model.session({"n_ctx": "8192"}) with generate(..., session=)). It has no run; use model.generate(prompt, max_tokens=64, temperature=0.0, top_k=0, top_p=1.0, seed=None, stop_tokens=()), which yields text pieces and samples in NumPy, or your own loop over model.tokenize(text), model.session(n_ctx=...), session.append(tokens) and session.logits(). Close sessions before their model. generate() does not stop at an end-of-generation token by itself (the C API exposes no special-token ids); pass stop_tokens, or limit max_tokens. For a Llama 3 style model, stop = model.tokenize("<|eot_id|>", add_special=False) returns the one id to pass (other models use their own end token string). n_ctx is capped by the model's training context and cannot be read back; a generation that reaches the context size fails mid-stream with "context full" (InvalidArgument). Different sessions of one model may be used from different threads; one session must not be. tokenize and generate may parse special-token text such as <|eot_id|> into control tokens (llamacpp does), so do not pass untrusted text if that matters.

Text completion

model.complete(prompt, max_tokens=..., temperature=..., top_p=..., seed=..., system=..., on_text=None) returns the answer as a string, for the llamacpp and llmserver backends (others raise Unsupported). on_text(piece) is called with each piece as it arrives; return a true value to stop early, and an exception from it is raised from complete. Each call is independent (no history). It uses the model's chat template and, with no temperature, is greedy; see ../../docs/backends/llmserver.md and ../../docs/backends/llamacpp.md.

with uairt.Engine("llmserver", preset="ollama") as engine, engine.load_model("llama3.2:1b") as model:
    print(model.complete("Name three colors.", max_tokens=40, on_text=lambda piece: print(piece, end="", flush=True)))

AutoModel picks a backend from a file, so for a server use Engine as above. The tests are tests/test_complete.py; the llmserver ones need UAIRT_TEST_LLMSERVER_PLUGIN (the python_sessions ctest sets it) and run against the fake server of tests/test_llmserver.py.

Metadata

Release files for uairt 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uairt 0.2.1
File Size Uploaded Provenance Actions
uairt-0.2.1.tar.gz 332.0 kB With provenance Details for uairt-0.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for uairt 0.2.1
File Actions
uairt-0.2.1-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for uairt-0.2.1-py3-none-win_arm64.whl
uairt-0.2.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for uairt-0.2.1-py3-none-win_amd64.whl
uairt-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details for uairt-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
uairt-0.2.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64, Linux glibc 2.17+ ARM64 Details for uairt-0.2.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
uairt-0.2.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for uairt-0.2.1-py3-none-macosx_11_0_arm64.whl

Total release size: 563.7 kB

Release files / uairt-0.2.1.tar.gz

Download URL uairt-0.2.1.tar.gz
Size 332.0 kB
Tags Source
SHA-256 checksum
How to use checksums
853044dff35d21d7ca66162b6ab9ea194864e505b53c980b2005829ea6a13e10
BLAKE2b-256 checksum
How to use checksums
09560e54d99915ec7a93904d8d704cc47609276c30f1eb603cdb3db390b9ed27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / uairt-0.2.1-py3-none-win_arm64.whl

Download URL uairt-0.2.1-py3-none-win_arm64.whl
Size 47.5 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
d341b4c6948a873f4bb6ab51cdb15b96ff02001c52806ec4ccaeaaa3454b37fa
BLAKE2b-256 checksum
How to use checksums
38cbe72f590a296958f85e5e05b958ae1e662dca34acf00513f0ebfeec5c78be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / uairt-0.2.1-py3-none-win_amd64.whl

Download URL uairt-0.2.1-py3-none-win_amd64.whl
Size 49.7 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
3c68f7331bfa80f2d67a47355e2f3f2df8d98889a5ddd065aebe7d042387208f
BLAKE2b-256 checksum
How to use checksums
08cd3e6c591c3039205d64110508c3d6dfa88db9ed8fa33c669574bef54d1445
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / uairt-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL uairt-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 46.0 kB
Tags Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
ad228a1b71cc94a537451bacd8d317ff53d1a685860da36eca766c031f6fdc0f
BLAKE2b-256 checksum
How to use checksums
04cdcba70e73e680737c26a4b1e92e31d29af94bb9093937d297e53cec833c1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / uairt-0.2.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL uairt-0.2.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 46.8 kB
Tags Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
eafd270cd51cff9126d50468e42a717cb2e2fa5cffb69b920b69dd4984534fd9
BLAKE2b-256 checksum
How to use checksums
5e9c7775e1991da04e5264dcc43f6f7eb9ee9d3916d6f4b441d2231dfcb5546b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / uairt-0.2.1-py3-none-macosx_11_0_arm64.whl

Download URL uairt-0.2.1-py3-none-macosx_11_0_arm64.whl
Size 41.7 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0428c40694a56d6386ab8fd275f7cd83f2e08bdca298e6c9a0d8089d9376f4cf
BLAKE2b-256 checksum
How to use checksums
492fe4d5b6b1595506e6d95e383cb693873cd2a378b266fb96e29fc07de23609
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for uairt 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for uairt-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page