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 encoderfilePrerequisites
You need an ONNX-exported model directory containing:
model.onnx— ONNX model weightstokenizer.json— tokenizer vocabulary and configurationconfig.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-modelQuick 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
Python API Reference — full documentation for every class and function
Transforms Guide — custom post-processing with Lua scripts
CLI Reference —
build,serve, andinfercommands for the compiled binary
Last updated