skillfed

onnxscript

Naturally author ONNX functions and models using a subset of Python

onnxscript v0.7.1 3.6M downloads/30d#2,579 on PyPI451
Permissive license MIT License Copyright (c) Microsoft Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to… (full text in the JSON record) Active released

What it is and what it does

ONNX Script is a Python-to-ONNX compiler that lets you define ONNX functions and models using Python syntax decorated with the @script decorator. The decorator parses your Python code, traverses its abstract syntax tree, and builds an equivalent ONNX graph that can be saved and validated. It supports a subset of Python—not the full language—and includes eager-mode evaluation for debugging, where functions execute using ONNX Runtime as a shim to test intermediate results.

Beyond compilation, the package provides an ONNX Optimizer (constant folding, dead code elimination) and an ONNX Rewriter (pattern-based graph transformation using user-defined rules). The rewriter allows you to match subgraph patterns and replace them with optimized alternatives. All of this is built on top of onnx and onnx_ir, with support for modern Python versions (3.9 through 3.14).

Use it for:

  • Author ONNX functions in readable Python instead of manually constructing protobuf graphs.
  • Debug ONNX model logic by running functions in eager mode to inspect intermediate tensor values.
  • Optimize ONNX models by applying constant folding and dead code elimination automatically.
  • Rewrite ONNX graph patterns (e.g., replace a custom Erf-based GELU with a native Gelu operator).
  • Round-trip between Python ONNX Script and ONNX graphs for model inspection and modification.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Write ONNX functions and models in Python syntax, then convert them to ONNX graphs; includes tools for optimization and pattern-based graph rewriting.

Yes. Active maintenance, low install friction, permissive MIT license, and no known vulnerabilities make this a safe choice. Install if you author or optimize ONNX models and want to work in Python syntax rather than protobuf. The eager-mode debugger is a real productivity gain for model development, though not for production inference.

Install

onnxscript on PyPI

pip

pip install onnxscript

uv

uv add onnxscript

poetry

poetry add onnxscript

Installing onnxscript

Before you install

Low friction: pure Python wheel with six runtime dependencies (numpy, onnx, packaging, and type-support libraries). Active maintenance with recent releases and 451 repository stars.

License in practice

MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects.

Quickstart

pip install onnxscript

from onnxscript import script, opset15 as op

@script()
def my_function(X):
    return op.MatMul(X, X)

onnx_model = my_function.to_model_proto()

Verify before relying

  • Whether the eager-mode runtime performance is suitable for your debugging workflow (docs note it is not optimized for speed).
  • Exact scope of Python language subset supported beyond the examples shown.

Package facts

License MIT License Copyright (c) Microsoft Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 6 — ml_dtypes, numpy, onnx_ir, onnx, packaging, typing_extensions
Maintenance actively maintained — 46 days since the last release
Last repo commit
First released
Downloads 3,553,221/month — #2,579 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: onnxscript-0.7.1-py3-none-any.whl

Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9

Tags

write onnx in pythononnx function authoringpython to onnx compileronnx model optimizationonnx graph rewritingonnx eager mode debuggingonnx script converter
onnx-toolingmodel-optimizationgraph-rewriting

More Artificial Intelligence packages