#webassembly #neural-network


High-level Rust bindings for wasi-nn

7 releases (breaking)

0.6.0 Aug 25, 2023
0.5.0 Aug 15, 2023
0.4.0 Jun 23, 2023
0.3.0 Mar 13, 2023
0.1.0 Apr 12, 2021

#106 in WebAssembly

Download history 216/week @ 2023-07-27 206/week @ 2023-08-03 241/week @ 2023-08-10 311/week @ 2023-08-17 390/week @ 2023-08-24 415/week @ 2023-08-31 476/week @ 2023-09-07 457/week @ 2023-09-14 579/week @ 2023-09-21 452/week @ 2023-09-28 292/week @ 2023-10-05 443/week @ 2023-10-12 552/week @ 2023-10-19 557/week @ 2023-10-26 630/week @ 2023-11-02 471/week @ 2023-11-09

2,290 downloads per month
Used in 2 crates


896 lines

wasi-nn bindings for Rust

This package contains high-level Rust bindings for wasi-nn system calls. It is similar in purpose to the WASI bindings but this package provides optional access to a system's machine learning functionality from WebAssembly.

NOTE: These bindings are experimental (use at your own risk) and subject to upstream changes in the wasi-nn specification.


  1. Depend on this crate in your Cargo.toml:

    wasi-nn = "0.6.0"
  2. Use the wasi-nn APIs in your application, for example:

    use wasi_nn;
    let graph = GraphBuilder::new(GraphEncoding::TensorflowLite, ExecutionTarget::CPU)
    let mut ctx = graph.init_execution_context()?;
    ctx.set_input(0, TensorType::F32, &input_dims, &input_buffer)?;
    let output_num_bytes = ctx.get_output(0, &mut output_buffer)?;
  3. Compile the application to WebAssembly:

    cargo build --target=wasm32-wasi
  4. Run the generated WebAssembly in a runtime supporting wasi-nn, e.g., Wasmtime.


To build this crate from source, use: cargo build --target wasm32-wasi.


This crate contains code (src/generated.rs) generated by witx-bindgen. To regenerate this code, run the following script:

$ scripts/regenerate-bindings-from-witx.sh


The examples demonstrate how to use wasi-nn from a Rust program.


This project is licensed under the Apache 2.0 license. See LICENSE for more details.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.


~20K SLoC