45 stable releases (15 major)

Uses new Rust 2024

39.0.1 Nov 24, 2025
38.0.4 Nov 11, 2025
37.0.3 Nov 11, 2025
36.0.3 Nov 11, 2025
24.0.2 Nov 5, 2024

#2007 in WebAssembly

Download history 429/week @ 2025-08-18 781/week @ 2025-08-25 866/week @ 2025-09-01 160/week @ 2025-09-08 377/week @ 2025-09-15 375/week @ 2025-09-22 276/week @ 2025-09-29 362/week @ 2025-10-06 166/week @ 2025-10-13 773/week @ 2025-10-20 317/week @ 2025-10-27 388/week @ 2025-11-03 456/week @ 2025-11-10 585/week @ 2025-11-17 297/week @ 2025-11-24 361/week @ 2025-12-01

1,724 downloads per month
Used in 5 crates (3 directly)

Apache-2.0 WITH LLVM-exception

4MB
65K SLoC

Wasmtime's wasi-keyvalue Implementation

This crate provides a Wasmtime host implementation of the wasi-keyvalue API. With this crate, the runtime can run components that call APIs in wasi-keyvalue and provide components with access to key-value storages.

Currently supported storage backends:

  • In-Memory (empty identifier)

Examples

The usage of this crate is very similar to other WASI API implementations such as wasi:cli and wasi:http.

A common scenario is accessing KV store in a wasi:cli component. A standalone example of doing all this looks like:

use wasmtime::{
    component::{Linker, ResourceTable},
    Config, Engine, Result, Store,
};
use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
use wasmtime_wasi_keyvalue::{WasiKeyValue, WasiKeyValueCtx, WasiKeyValueCtxBuilder};

#[tokio::main]
async fn main() -> Result<()> {
    let mut config = Config::new();
    config.async_support(true);
    let engine = Engine::new(&config)?;

    let mut store = Store::new(&engine, Ctx {
        table: ResourceTable::new(),
        wasi_ctx: WasiCtx::builder().build(),
        wasi_keyvalue_ctx: WasiKeyValueCtxBuilder::new().build(),
    });

    let mut linker = Linker::<Ctx>::new(&engine);
    wasmtime_wasi::p2::add_to_linker_async(&mut linker)?;
    // add `wasi-keyvalue` world's interfaces to the linker
    wasmtime_wasi_keyvalue::add_to_linker(&mut linker, |h: &mut Ctx| {
        WasiKeyValue::new(&h.wasi_keyvalue_ctx, &mut h.table)
    })?;

    // ... use `linker` to instantiate within `store` ...

    Ok(())
}

struct Ctx {
    table: ResourceTable,
    wasi_ctx: WasiCtx,
    wasi_keyvalue_ctx: WasiKeyValueCtx,
}

impl WasiView for Ctx {
    fn ctx(&mut self) -> WasiCtxView<'_> {
        WasiCtxView { ctx: &mut self.wasi_ctx, table: &mut self.table }
    }
}

Dependencies

~22–37MB
~672K SLoC