Skip to content

Repository files navigation

betto_onnxrt

ONNX Runtime for Dart and Flutter — binary delivery via the native-assets build hook, a generalised inference API, and model-download infrastructure.

Wraps ONNX Runtime v1.22.0. Targets macOS, Linux, Windows, Android, and iOS. Web is excluded (no FFI in the browser).


Packages

Package Directory Description
betto_onnxrt packages/betto_onnxrt/ Pure-Dart library — build hook, FFI session API, model downloader
betto_onnxrt_ios packages/betto_onnxrt_ios/ Flutter plugin SPM shim for iOS — statically links ORT via Xcode

betto_onnxrt has no Flutter dependency and works in CLI, server, and Flutter contexts. Add betto_onnxrt_ios as an additional dependency only when targeting iOS.


Documentation

Document Description
Specification Public API contract, platform support, architecture, thread safety
Roadmap v0 development goals and completion status
Plans Implementation plans (open, in-progress, and completed)
Releasing Release process and pub.dev publication checklist

Quick start

Add to pubspec.yaml:

dependencies:
  betto_onnxrt: ^0.1.0-dev.2
  betto_onnxrt_ios: ^0.1.0-dev.2 # Flutter + iOS targets only

Run dart pub get (or flutter pub get). The native-assets build hook downloads and verifies the ORT binary for your target platform automatically — no manual binary management needed.

import 'package:betto_onnxrt/betto_onnxrt.dart';

final runtime = OnnxRuntime.load();
final session = runtime.createSession('/path/to/model.onnx');
final outputs = session.run({'input': inputTensor});
session.dispose();

See the specification for the full API.


Example

packages/betto_onnxrt/example/magika/ is a standalone Dart CLI tool that detects file types using Google's Magika v3.3 ONNX model. It demonstrates end-to-end use of OnnxRuntime, OnnxSession, and ModelDownloader with a real-world model, and its output mirrors the Python Magika --json format.

cd packages/betto_onnxrt/example/magika

# Run directly (JIT — no build step needed):
dart run bin/magika.dart <file>

# Or compile to a native binary:
dart build cli
./build/cli/macos_arm64/bundle/bin/magika <file>

The model is downloaded and SHA-256 verified on first run; no manual setup is required.


Development

All build, test, and quality targets are available from the repo root via make. The Makefile composes per-package .mk fragments.

make              # full quality gate (format, analyze, test, coverage, doc)
make pre_commit   # subset run before committing
make test         # unit tests
make macos_test   # on-device integration tests (macOS)
make ios_test     # iOS simulator integration tests
make android_test # Android emulator integration tests

See CLAUDE.md for the full command reference and architectural notes aimed at AI-assisted development.


Status

Pre-release (0.1.0-dev.2).

See the v0 roadmap for remaining work before the first stable release.


License

Apache 2.0. See LICENSE.

About

ONNX Runtime for Dart — build-time binary via native-assets hook, generalised OnnxSession API, and model-download infrastructure.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages