Registry / ai-ml / spox
library0.17.1pypypi✓ verified 84d ago

A framework for constructing ONNX computational graphs programmatically. Current version 0.17.1, supports Python >=3.10, and follows a monthly/quarterly release cadence. Spox provides a high-level API to build, inline, and manipulate ONNX models with type-safe operators and shape inference.

pip install spox
INSTALL
IMPORT
SIG · SPOX
S
spox
ai-mlpythonv0.17.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

spox
import spox
import spox as _
No common wrong import; but avoid importing private modules like spox._future directly.
make_onnx_model
from spox import build, make_onnx_model
from spox import make_model
The function is named make_onnx_model, not make_model.
onnx opset
from spox.opset.ai.onnx import v17
Use specific opset versions like v17, v18, etc., not generic 'onnx'.

Construct an ONNX model for Y = A*X + B using Spox.

import spox from spox import build, make_onnx_model from spox.opset.ai.onnx import v17 as op # Build a simple model: Y = A * X + B def build_linear_model(): A = spox.argument(spox.Tensor(spox.Float, (3, 3))) X = spox.argument(spox.Tensor(spox.Float, (3, None))) B = spox.argument(spox.Tensor(spox.Float, (1, None))) Y = op.add(op.matmul(A, X), B) return build(inputs={'A': A, 'X': X, 'B': B}, outputs={'Y': Y}) model = build_linear_model() print(make_onnx_model(model).SerializeToString()[:100])
Debug
Known issues
breakingRemoval of group_normalization constructor: spox.opset.ai.onnx.v18.group_normalization and its re-exports in v19, v20 removed in 0.14.0 due to upstream deprecation.
fix
Use group_normalization from a later opset version (v21+) or implement manually.
affects: >=0.14.0
deprecatedImporting spox._future.operator_overloading triggers DeprecationWarning since 0.13.0. Consider using ndonnx as an alternative.
fix
Replace usage with ndonnx.
affects: >=0.13.0
gotchaPython version requirement: Spox 0.17.0+ requires Python >=3.10. Older versions may support down to 3.8.
fix
Ensure Python version >=3.10, or pin spox<0.17.0 for 3.9 compat.
affects: >=0.17.0
Errors
Common errors & fixes
AttributeError: module 'spox' has no attribute 'make_model'
The function is named make_onnx_model, not make_model.
fix
Use from spox import make_onnx_model or correct the function name.
ValueError: Failed to infer shape for op MatMul
Missing or mismatched shape information for an input or output tensor.
fix
Ensure all argument tensors have correct shapes; use spox.Tensor with dimension symbols or None for unknown.
spox.exceptions.SpoxValueError: Operator 'GroupNormalization' not found in opset 'ai.onnx.v18'
group_normalization was removed from v18, v19, v20 in spox 0.14.0.
fix
Use later opset version (v21+) or alternate implementation.
Upgrade
Version history
0.17.1latest on PyPI · released Feb 17, 2026
Audit
Dependencies
onnxrequiredCore dependency for ONNX protobuf model representation and opsets.
ml_dtypesoptionalOptional; needed for extended data types like bfloat16, float8, int4.
Agent activity
21 hits · last 30 days
node
14
OpenAI (training)
1
Resources
spox — pip install spox · libregistry