For the complete documentation index, see llms.txt. This page is also available as Markdown.

Building with Python

The encoderfile Python package lets you build encoderfile binaries programmatically — no separate CLI installation required. It is a thin wrapper around the same Rust build pipeline used by the CLI tool.

Installation

pip install encoderfile
# or with uv
uv add encoderfile

Prerequisites

You need an ONNX-exported model directory containing:

  • model.onnx — ONNX model weights

  • tokenizer.json — tokenizer vocabulary and configuration

  • config.json — model architecture metadata

Export any HuggingFace model with Optimum:

pip install 'optimum[onnx]'
optimum-cli export onnx \
  --model distilbert-base-uncased-finetuned-sst-2-english \
  --task text-classification \
  ./sentiment-model

Quick Start

The simplest build uses EncoderfileBuilder directly:

Three Ways to Build

1. EncoderfileBuilder (full control)

Best when you need fine-grained control over tokenizer settings, transforms, or cross-compilation targets.

2. build() convenience function (flat arguments)

Best for scripts where you want to avoid importing supporting classes.

3. build_from_config() (YAML config file)

Best when your build configuration lives in a file alongside your model.

Where sentiment-config.yml contains:

Model Types

See the Building Guide for a full description of each model type, including supported HuggingFace AutoModel classes and inference output shapes.

ModelType values are plain strings (StrEnum), so you can pass the string directly instead of importing the enum:

Tokenizer Configuration

Override tokenizer padding and truncation settings at build time with TokenizerBuildConfig. These settings are baked into the binary and applied at every inference call.

When using the build() convenience function, use flat tokenizer_* arguments instead:

Lua Transforms

Embed a Lua post-processing script to transform model logits before they are returned. See the Transforms guide for the full scripting API.

Cross-compilation

Build a binary targeting a different platform by passing a target triple:

You can also use a TargetSpec object:

Inspecting a Binary

Use read_metadata() to read the metadata embedded in an existing encoderfile binary without running inference:

Next Steps

Last updated