--- id: onnxscript version: "0.7.1" 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) license_treatment: permissive maintenance: active --- # onnxscript — Naturally author ONNX functions and models using a subset of Python License: permissive · Maintenance: active · Downloads: 3.6M/mo ## 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 above — 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 pip install onnxscript uv add onnxscript 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_current - Install friction: low - Maintenance: active - Downloads: 3.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags write onnx in python, onnx function authoring, python to onnx compiler, onnx model optimization, onnx graph rewriting, onnx eager mode debugging, onnx script converter, onnx-tooling, model-optimization, graph-rewriting [View on SkillFed](https://skillfed.io/packages/onnxscript) · [View on PyPI](https://pypi.org/project/onnxscript/)