⌘K ctrl+k
Search Shortcut cmd + k | ctrl + k
Rust Client

Installation To use the DuckDB Rust client, visit the Rust installation page.

The latest stable version of the DuckDB Rust client is 1.5.5.

The DuckDB Rust client, duckdb-rs, is an ergonomic wrapper over the DuckDB C API that exposes an interface modeled on rusqlite. It supports type-safe queries, bulk loading with the Appender, Apache Arrow interchange, user-defined functions, and building DuckDB extensions in Rust. This page focuses on installation. The other pages in this section cover connecting and each feature in detail.

Installation

The DuckDB Rust client is published on crates.io. The full API is documented on docs.rs. Add it to a project with cargo, enabling the bundled feature so that DuckDB is compiled from source and no system library is required:

cargo add duckdb --features bundled

The equivalent Cargo.toml entry pins the version. Starting with DuckDB v1.5.0 the crate version has the form 1.⟨major_minor_patch⟩.x. A tilde requirement receives patch releases without changing the bundled DuckDB version:

[dependencies]
duckdb = { version = "~1.10505.0", features = ["bundled"] }

The bundled feature is the simplest way to get started. Without it, the libduckdb-sys crate links against a system DuckDB library instead of compiling one, which is covered in Troubleshoot.

To track the latest bindings before they are released on crates.io, depend on the main branch or a specific commit from git. The bundled DuckDB version is whatever that commit vendors:

[dependencies]
# Latest development version
duckdb = { git = "https://github.com/duckdb/duckdb-rs", branch = "main", features = ["bundled"] }

# A specific commit
duckdb = { git = "https://github.com/duckdb/duckdb-rs", rev = "abc123def", features = ["bundled"] }

For the LTS release line that stays on DuckDB 1.4 Andium, use the v1.4-andium branch.

Tip The Rust client offers a large set of Cargo feature flags that turn on file-format readers, the Arrow and Polars integrations, connection pooling, and the function and extension interfaces. Enable only the features a project uses to keep build times and binary size down.

Basic API Usage

To use DuckDB, first initialize a Connection with Connection::open_in_memory() for an in-memory database, or Connection::open(path) for a database file. Queries are sent with execute() and execute_batch(), and results are read by preparing a statement and mapping each row to a Rust value with query_map():

use duckdb::{params, Connection, Result};

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>,
}

fn main() -> Result<()> {
    let conn = Connection::open_in_memory()?;

    conn.execute_batch(
        r"CREATE SEQUENCE seq;
          CREATE TABLE person (
              id   INTEGER PRIMARY KEY DEFAULT NEXTVAL('seq'),
              name TEXT NOT NULL,
              data BLOB
          );",
    )?;

    let me = Person {
        id: 0,
        name: "Steven".to_string(),
        data: None,
    };
    conn.execute(
        "INSERT INTO person (name, data) VALUES (?, ?)",
        params![me.name, me.data],
    )?;

    let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
    let person_iter = stmt.query_map([], |row| {
        Ok(Person {
            id: row.get(0)?,
            name: row.get(1)?,
            data: row.get(2)?,
        })
    })?;

    for person in person_iter {
        println!("Found person {:?}", person.unwrap());
    }
    Ok(())
}

This example is adapted from the crate's basic example. Run Queries covers sending queries and reading results in full.

Feature Flags

The crate is modular: most integrations are gated behind Cargo features that are off by default. Enable them in the dependency declaration, for example features = ["bundled", "vtab", "appender-arrow"]. The following is the complete set of the crate's Cargo features, grouped by purpose.

Building DuckDB

Feature Enables
bundled Compile DuckDB from the bundled source with the cc crate, so no system library is needed.
bundled-cmake Experimental. Compile the bundled source with DuckDB's upstream CMake build instead of cc, which is required for the bundled extensions below. Only available from a git checkout, not from crates.io. Implies bundled and parquet.
buildtime_bindgen Regenerate the C API bindings at build time with bindgen instead of using the shipped pregenerated bindings.

File Formats

Both imply bundled.

Feature Enables
json Reading and writing JSON, statically linked.
parquet Reading and writing Parquet, statically linked.

Bundled Extensions

Each statically links the matching bundled extension. All imply bundled-cmake, so they need a git checkout.

Feature Enables
autocomplete The autocomplete extension.
icu The ICU extension for locale-aware and time-zone-aware operations, which the plain bundled build omits.
tpch The TPC-H benchmark extension.
tpcds The TPC-DS benchmark extension.

Table and Scalar Functions

Feature Enables
vtab Base support for table functions.
vtab-arrow Apache Arrow integration for table functions, converting between an Arrow RecordBatch and DuckDB data chunks. Implies vtab.
vscalar Scalar functions. Implies vtab-arrow.
vscalar-arrow Arrow-optimized scalar functions, intended for use alongside vscalar.
appender-arrow Append Arrow RecordBatches through the Appender. Implies vtab-arrow.
loadable-extension Experimental. Build a loadable DuckDB extension rather than a client application. See Building a Loadable Extension.

Ecosystem Integrations

Feature Enables
polars Exchange query results as Polars data frames. See Handle Results.
r2d2 A connection pool through the r2d2 crate. See Connect.
chrono ToSql and FromSql conversions for chrono date and time types.
rust_decimal ToSql and FromSql conversions for rust_decimal::Decimal.
serde_json ToSql and FromSql conversions for serde_json::Value.
url ToSql and FromSql conversions for url::Url.
uuid ToSql and FromSql conversions for uuid::Uuid.

Umbrella Features

Feature Enables
vtab-full vtab-arrow and appender-arrow, plus the deprecated vtab-excel.
extensions-full json, parquet and vtab-full.
modern-full chrono, serde_json, url, r2d2, uuid, polars and rust_decimal.

Deprecated Features

Feature Enables
vtab-excel A no-op retained for feature compatibility.
vtab-loadable Superseded by loadable-extension.

Further Reading

  • Connect — opening in-memory and file-backed databases, Config options, connection pooling, and thread safety.
  • Run Queriesexecute(), prepared statements, parameter binding, and mapping rows to Rust types.
  • Import Data — bulk loading with the Appender and reading directly from Parquet, CSV, and JSON files.
  • Handle Results — Apache Arrow and Polars result interchange.
  • Write User Defined Functions — user-defined scalar and table functions, and loadable extensions.
  • Profile and Monitor — query profiling and interrupting long-running queries.
  • Troubleshoot — linking, the ICU extension, and extension-versus-client build issues.
  • Clients Overview — the other client APIs DuckDB provides alongside Rust.

Pages in This Section

© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog