{"id":19946116,"url":"https://github.com/quantco/spox","last_synced_at":"2025-04-04T03:02:37.069Z","repository":{"id":80955420,"uuid":"604199009","full_name":"Quantco/spox","owner":"Quantco","description":"Pythonic framework for building ONNX graphs","archived":false,"fork":false,"pushed_at":"2025-04-01T16:28:43.000Z","size":1619,"stargazers_count":80,"open_issues_count":6,"forks_count":5,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-01T17:01:26.941Z","etag":null,"topics":["machine-learning","ndonnx","onnx","python"],"latest_commit_sha":null,"homepage":"https://spox.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Quantco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-20T14:45:10.000Z","updated_at":"2025-04-01T16:22:13.000Z","dependencies_parsed_at":"2023-12-04T11:27:09.658Z","dependency_job_id":"6251d89a-789f-4c9c-84f7-f24175b4cd7d","html_url":"https://github.com/Quantco/spox","commit_stats":{"total_commits":220,"total_committers":7,"mean_commits":"31.428571428571427","dds":"0.46818181818181814","last_synced_commit":"dd986055c76690967e2c6714386e53220fb6740c"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantco%2Fspox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantco%2Fspox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantco%2Fspox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantco%2Fspox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quantco","download_url":"https://codeload.github.com/Quantco/spox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247112739,"owners_count":20885606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["machine-learning","ndonnx","onnx","python"],"created_at":"2024-11-13T00:28:22.195Z","updated_at":"2025-04-04T03:02:37.020Z","avatar_url":"https://github.com/Quantco.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spox\n\n[![CI](https://github.com/Quantco/spox/actions/workflows/ci.yml/badge.svg)](https://github.com/Quantco/spox/actions/workflows/ci.yml)\n[![Documentation Status](https://readthedocs.org/projects/spox/badge/?version=latest)](https://spox.readthedocs.io/en/latest/?badge=latest)\n\nSpox makes it easy to construct [ONNX](https://github.com/onnx/onnx/) models through clean and idiomatic Python code.\n\n## Why use Spox?\n\nA common application of ONNX is converting models from various frameworks. This requires replicating their runtime behaviour with ONNX operators.\nIn the past this has been a major challenge.\nBased on our experience, we designed Spox from the ground up to make the process of writing converters (and ONNX models in general) as easy as possible.\n\nSpox's features include:\n\n- Eager operator validation and type inference\n- Errors with Python tracebacks to offending operators\n- First-class support for subgraphs (control flow)\n- A lean and predictable API\n\n## Installation\n\nSpox releases are available on PyPI:\n\n```bash\npip install spox\n```\n\nThere is also a package available on conda-forge:\n\n```bash\nconda install spox\n```\n\n## Quick start\n\nIn Spox, you primarily interact with `Var` objects - **variables** - which are placeholders for runtime values.\nThe initial `Var` objects, which represent the _arguments_ of a model (the model inputs in ONNX nomenclature), are created with an explicit type using the `argument(Type) -\u003e Var` function. The possible types include `Tensor`, `Sequence`, and `Optional`.\nAll further `Var` objects are created by calling functions which take existing `Var` objects as inputs and produce new `Var` objects as outputs. Spox determines the `Var.type` for these eagerly to allow validation.\nSpox provides such functions for all operators in the standard. They are grouped by domain and version in the `spox.opset` submodule.\n\nThe final `onnx.ModelProto` object is built by passing input and output `Var`s for the model to the `spox.build` function.\n\nBelow is an example for defining an ONNX graph which computes the [geometric mean](https://en.wikipedia.org/wiki/Geometric_mean) of two inputs.\nMake sure to consult the Spox [documentation](https://spox.readthedocs.io/en/latest) to find more details and tutorials.\n\n```python\nimport onnx\n\nfrom spox import argument, build, Tensor, Var\n# Import operators from the ai.onnx domain at version 17\nfrom spox.opset.ai.onnx import v17 as op\n\ndef geometric_mean(x: Var, y: Var) -\u003e Var:\n    # use the standard Sqrt and Mul\n    return op.sqrt(op.mul(x, y))\n\n# Create typed model inputs. Each tensor is of rank 1\n# and has the runtime-determined length 'N'.\na = argument(Tensor(float, ('N',)))\nb = argument(Tensor(float, ('N',)))\n\n# Perform operations on `Var`s\nc = geometric_mean(a, b)\n\n# Build an `onnx.ModelProto` for the given inputs and outputs.\nmodel: onnx.ModelProto = build(inputs={'a': a, 'b': b}, outputs={'c': c})\n```\n\n## Credits\n\nOriginal designed and developed by [@jbachurski](https://github.com/jbachurski) with the supervision of [@cbourjau](https://github.com/cbourjau).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantco%2Fspox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquantco%2Fspox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantco%2Fspox/lists"}