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("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:
.dlcand.bingo toqnn,.onnxtoonnxruntime(thenopenvino),.xmltoopenvino,.paramtoncnn,.engineand.plantotensorrt,.tflitetotflite,.mlmodelc,.mlpackageand.mlmodeltocoreml. A directory is judged by what it holds (an ultralytics_openvino_modelor_ncnn_modelexport). Passbackend=to choose. - Device:
cpu,gpu,npu,cuda,tensorrtorvulkan, with an optional index (gpu:1), orNonefor the backend's default. It is mapped to that backend's own options (device=npufor QNN,execution_provider=cudafor ONNX Runtime,device=GPUfor OpenVINO,device=vulkanfor NCNN, and so on). QNN's default isnpu. - 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 raisesNotFound. Both say why each candidate was passed over.model.plan.skippedlists 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.UairtErrorsubclasses (NotFound,Unsupported,IncompatibleModel,IoFailure, ...) carrying.statusand.message. Engine.alloc_buffer(n, "host" | "dmabuf" | "pinned")andModel.run_buffersgive 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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| uairt-0.2.0.tar.gz | 273.2 kB | With provenance | Details for uairt-0.2.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| uairt-0.2.0-py3-none-win_arm64.whl | Python 3 | none | Windows ARM64 | Details for uairt-0.2.0-py3-none-win_arm64.whl |
| uairt-0.2.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for uairt-0.2.0-py3-none-win_amd64.whl |
| uairt-0.2.0-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.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
| uairt-0.2.0-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.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
| uairt-0.2.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for uairt-0.2.0-py3-none-macosx_11_0_arm64.whl |
Total release size: 493.2 kB
Release files / uairt-0.2.0.tar.gz
| Download URL | uairt-0.2.0.tar.gz |
|---|---|
| Size | 273.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e4fec4a81907e48b5a273539904a0f480707c64858ffd9afca52f94425dd7e3
|
|
BLAKE2b-256 checksum How to use checksums |
06e31128e75f167db491b635037576b456b8789d9b77214511ec0877747b252d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / uairt-0.2.0-py3-none-win_arm64.whl
| Download URL | uairt-0.2.0-py3-none-win_arm64.whl |
|---|---|
| Size | 45.3 kB |
| Tags | Python 3 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
4d21a9d791f2b3c7ada8a7616c6ab85db6fc90092bb7d6c6c912ebf367470b4f
|
|
BLAKE2b-256 checksum How to use checksums |
b1d7f3b39c96d147ff790b9621bc5862a8505bbd646e70d0d6802d09794c4d3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / uairt-0.2.0-py3-none-win_amd64.whl
| Download URL | uairt-0.2.0-py3-none-win_amd64.whl |
|---|---|
| Size | 47.2 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
45fc07228437744a12c6151555ccc40cb41a6aa0fef3aaa2d1d9269d4b1c859f
|
|
BLAKE2b-256 checksum How to use checksums |
adb21c8ebe7211d749123e8a7e9f1a9afb39278e480b24789c258606480bc083
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / uairt-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | uairt-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 43.6 kB |
| Tags | Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
fa05828b46ecee95afce9dff56525d3bad4783afe06ee813efaf59ca27bbf2d8
|
|
BLAKE2b-256 checksum How to use checksums |
67e8682fd8c6db42c153c103a661393702939c33d4a2dfb1e75dca6fd5c10adb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / uairt-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | uairt-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 44.2 kB |
| Tags | Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
9bec6ee68496923c2f6e66c3ed5f2687c4763c1320267eeb2556100540a01820
|
|
BLAKE2b-256 checksum How to use checksums |
a5e1871861bbdd1131244dceb32d3f1b14d8146be5e2015a2313aa51b2290cf5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / uairt-0.2.0-py3-none-macosx_11_0_arm64.whl
| Download URL | uairt-0.2.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 39.6 kB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
375697cb2bba3672f8ebdea491868f3e26ec21364b09cc3e051e02001cd346b1
|
|
BLAKE2b-256 checksum How to use checksums |
9a25cef624b680d4f5ccf2132a0458051c6396f87f2446ef80b8986db1a09d0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logSecurity for uairt 0.2.0
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.
Attestation for uairt-0.2.0.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 Oct 19, 2026.
Transparency logA 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.