Skip to main content

unirt (Python binding)

Python binding for the UniRT SDK — run LLMs locally through a single API with interchangeable backends:

runtime models hardware in the published wheels
llama_cpp GGUF (LLM, VLM, embeddings, rerank) CPU, Metal on macOS every wheel
mlx HF safetensors (SmolLM2-style Llama/ByteLevel-BPE layout; dense or MLX-quantized) Apple Silicon Metal GPU macOS wheel (Apple-only)
onnxruntime ONNX encoder embeddings CPU, Apple Core ML every wheel

unirt devices lists what your install actually has. The llama_cpp runtime is built for a generic CPU baseline plus Metal on macOS — no CUDA, no Vulkan.

The bundled llama_cpp runtime supports GGUF VLMs through libmtmd when an mmproj is present. MLX remains text-only and fails explicitly for VLM models. MLX also requires a usable Metal device; if none is visible, model loading fails before native model allocation.

Install

pip install unirt

Wheels ship the native libraries — no toolchain, no build step — for macOS 14+ arm64, Linux x86_64 and arm64 (manylinux_2_31, glibc 2.31+), and Windows 10+ x86_64 and arm64. Python 3.10+.

Quickstart (CLI)

unirt chat bartowski/SmolLM2-135M-Instruct-GGUF   # download + interactive chat
unirt serve <model> --port 8080                   # OpenAI-compatible server
unirt embed <encoder> "some text"                 # one vector per argument
unirt rerank <cross-encoder> "a query" "doc one" "doc two"
unirt pull <hf-repo>                              # download only
unirt ls                                          # cached models
unirt devices                                     # plugins + devices

Usage

from unirt.auto import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(
    'bartowski/SmolLM2-135M-Instruct-GGUF',
    precision='Q4_K_M',
    device_map='llama_cpp',
)
out = model.generate(prompt, max_new_tokens=128, temperature=0.7)
print(out.text)
model.close()

Embedding repositories select an ONNX variant and tokenizer sidecars without downloading the PyTorch checkpoint:

from unirt import AutoModelForEmbedding

with AutoModelForEmbedding.from_pretrained(
    'sentence-transformers/all-MiniLM-L6-v2',
    device_map='cpu',  # or 'coreml' on Apple Silicon
) as model:
    vectors = model.encode(['a cat on a mat', 'a kitten on a rug'])
    print(len(vectors), len(vectors[0]))  # 2, 384

Repository ids are inspected and downloaded with huggingface_hub. GGUF repositories download only the selected quantization (including all of its shards) plus tokenizer/config sidecars. The default cache is ~/.cache/unirt; set UNIRT_DATADIR to move it and UNIRT_HFTOKEN for gated or private repositories.

Generation is stateless by default (n_past=0 clears prior KV state before prefilling the supplied prompt). To continue from a known cached prefix, pass the exact prefix length through n_past; invalid values are rejected rather than silently duplicating context.

Structured output

Constrain decoding so the reply is guaranteed to parse — the grammar masks invalid tokens at every step, which makes even small models reliable JSON emitters (llama_cpp backend; MLX rejects these options):

schema = {'type': 'object',
          'properties': {'city': {'type': 'string'}, 'country': {'type': 'string'}},
          'required': ['city', 'country']}
out = model.generate('Facts about the capital of France as JSON.',
                     json_schema=schema)      # dict or serialized JSON string
data = json.loads(out.text)                    # always parses

model.generate(prompt, json_mode=True)         # any syntactically valid JSON
model.generate(prompt, grammar='root ::= ...')  # raw GBNF

The server accepts the OpenAI response_format field with types json_object and json_schema. Note a length finish can still truncate mid-object — budget max_tokens accordingly.

OpenAI-compatible server

python3 -m unirt.server --model bartowski/SmolLM2-135M-Instruct-GGUF \
  --backend llama_cpp --port 8080

Then point any OpenAI client (or plain curl) at http://localhost:8080/v1/chat/completions — streaming SSE included, and GGUF VLMs accept image content parts when loaded with an mmproj.

--embedding-model <encoder> adds /v1/embeddings and --rerank-model <cross-encoder> adds /v1/rerank; either may be given without --model, so a retrieval sidecar needs no chat model at all.

Sampling takes temperature, top_p, top_k, min_p, seed, repetition_penalty, presence_penalty and frequency_penalty. --api-key (or UNIRT_API_KEY) requires Authorization: Bearer <key> on every /v1 endpoint, leaving /health open for probes — worth setting whenever --host is not loopback.

The native library is closed-source and ships prebuilt. A wheel already bundles it under unirt/lib/; a source checkout is discovered at <repo>/sdk/pkg-unirt/lib after building the SDK, and installing from source without building means populating unirt/lib/ yourself from a Release's native-libs archive before pip install .. UNIRT_LIB_PATH / UNIRT_PLUGIN_PATH override the search.

Metadata

Release files for unirt 0.5.0

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

Built distributions (wheels)

Table of built distributions (wheels) for unirt 0.5.0
File
unirt-0.5.0-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details
unirt-0.5.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl Python 3 none Linux glibc 2.31+ x86-64 Details
unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl Python 3 none Linux glibc 2.31+ ARM64 Details
unirt-0.5.0-py3-none-macosx_14_0_arm64.whl Python 3 none macOS 14.0+ ARM64 Details

Total release size: 110.1 MB

Release files / unirt-0.5.0-py3-none-win_arm64.whl

Download URL unirt-0.5.0-py3-none-win_arm64.whl
Size 9.5 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
5b611b5e028791ed0c4d7c12c2fe1d4956f0a22bc33a62f3c160501b5aea5f33
BLAKE2b-256 checksum
How to use checksums
101587c568e5a9de9a2d2e2c6674033837e8dd35d0751dd71534bdcd92648192
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 Aug 3, 2026.

Transparency log

Release files / unirt-0.5.0-py3-none-win_amd64.whl

Download URL unirt-0.5.0-py3-none-win_amd64.whl
Size 12.3 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
2fb22e5d0a3ecb2fdd60f8bb91b983fac9801d18ccb4d969d3a113cc110f4156
BLAKE2b-256 checksum
How to use checksums
d623f3073b2a51af3c3e9199e54dedade8d794c2488ae5a25b7cd6d8e03b3abf
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 Aug 3, 2026.

Transparency log

Release files / unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl

Download URL unirt-0.5.0-py3-none-manylinux_2_31_x86_64.whl
Size 36.7 MB
Tags Linux glibc 2.31+ x86-64 Python 3
SHA-256 checksum
How to use checksums
4affe6b13215c58b0e36482be5be8db44a5809f4179309da0641d6e652b8d6e3
BLAKE2b-256 checksum
How to use checksums
ac5bc3f540d28f3ce8f07f8716159440ee58f85040f1e1a6f151f4f77ca94db0
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 Aug 3, 2026.

Transparency log

Release files / unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl

Download URL unirt-0.5.0-py3-none-manylinux_2_31_aarch64.whl
Size 31.6 MB
Tags Linux glibc 2.31+ ARM64 Python 3
SHA-256 checksum
How to use checksums
18a18c527ae61143007d4943869f6dbd58875432b23895fec5cdf7da022c5216
BLAKE2b-256 checksum
How to use checksums
e44ae96d47b883c1ac3d866aaafe053946c337af1973b596e77c8bfd71c9ac4c
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 Aug 3, 2026.

Transparency log

Release files / unirt-0.5.0-py3-none-macosx_14_0_arm64.whl

Download URL unirt-0.5.0-py3-none-macosx_14_0_arm64.whl
Size 20.1 MB
Tags Python 3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
d464ddc94f9b9d70117f891ad64f61b42a0a2bf1cd6b1a9072679534ebddd5be
BLAKE2b-256 checksum
How to use checksums
97a3eb09c73af558b2c33b6d79aa4b8ce4a400e04158a7ebadaaa4406fa82627
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 Aug 3, 2026.

Transparency log

Security for unirt 0.5.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 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for unirt-0.5.0-py3-none-win_arm64.whl

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 Aug 3, 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.

Release history Release notifications | RSS feed

This release

0.5.0 This release

5 release files Full provenance

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