rust-numpy

Library Featured

PyO3-based Rust bindings of the NumPy C-API

Checked · Sources

Downloads
3,598,884
Dependents
388
Stars
1,391
Forks
140
Contributors
65
Commits
1,131
Latest release
0.30.0 ·

About

From the project README ·

Rust bindings for the NumPy C-API.

API documentation

Requirements

  • Rust >= 1.85.0
    • Basically, our MSRV follows the one of PyO3
  • Python >= 3.9
    • Python 3.7 support was dropped from 0.29
    • Python 3.8 support was dropped from 0.30
  • Some Rust libraries
  • numpy installed in your Python environments (e.g., via pip install numpy)
    • We recommend numpy >= 1.16.0, though older versions may work

Example

Write a Python module in Rust

Please see the simple example for how to get started.

There are also examples using ndarray-linalg and rayon.

[lib]
name = "rust_ext"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.30" }
numpy = "0.30"
Read the full README
#[pyo3::pymodule]
mod rust_ext {
    use numpy::ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
    use numpy::{IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn, PyArrayMethods};
    use pyo3::{pyfunction, PyResult, Python, Bound};

    // example using immutable borrows producing a new array
    fn axpy(a: f64, x: ArrayViewD<'_, f64>, y: ArrayViewD<'_, f64>) -> ArrayD<f64> {
        a * &x + &y
    }

    // example using a mutable borrow to modify an array in-place
    fn mult(a: f64, mut x: ArrayViewMutD<'_, f64>) {
        x *= a;
    }

    // wrapper of `axpy`
    #[pyfunction(name = "axpy")]
    fn axpy_py<'py>(
        py: Python<'py>,
        a: f64,
        x: PyReadonlyArrayDyn<'py, f64>,
        y: PyReadonlyArrayDyn<'py, f64>,
    ) -> Bound<'py, PyArrayDyn<f64>> {
        let x = x.as_array();
        let y = y.as_array();
        let z = axpy(a, x, y);
        z.into_pyarray(py)
    }

    // wrapper of `mult`
    #[pyfunction(name = "mult")]
    fn mult_py<'py>(a: f64, x: &Bound<'py, PyArrayDyn<f64>>) {
        let x = unsafe { x.as_array_mut() };
        mult(a, x);
    }
}
Execute a Python program from Rust and get results
[package]
name = "numpy-test"

[dependencies]
pyo3 = { version = "0.30", features = ["auto-initialize"] }
numpy = "0.30"
use numpy::{PyArray1, PyArrayMethods};
use pyo3::{types::{IntoPyDict, PyAnyMethods}, PyResult, Python};

fn main() -> PyResult<()> {
    Python::attach(|py| {
        let np = py.import("numpy")?;
        let locals = [("np", np)].into_py_dict(py)?;

        let pyarray = py
            .eval(c"np.absolute(np.array([-1, -2, -3], dtype='int32'))", Some(&locals), None)?
            .cast_into::<PyArray1<i32>>()?;

        let readonly = pyarray.readonly();
        let slice = readonly.as_slice()?;
        assert_eq!(slice, &[1, 2, 3]);

        Ok(())
    })
}

Dependency on ndarray

This crate uses types from ndarray in its public API. ndarray is re-exported in the crate root so that you do not need to specify it as a direct dependency.

Furthermore, this crate is compatible with multiple versions of ndarray and therefore depends on a range of semver-incompatible versions, currently >= 0.15, <= 0.17. Cargo does not automatically choose a single version of ndarray by itself if you depend directly or indirectly on anything but that exact range. It can therefore be necessary to manually unify these dependencies.

For example, if you specify the following dependencies

numpy = "0.30"
ndarray = "0.15"

this will currently depend on both version 0.15.6 and 0.16.1 of ndarray by default even though 0.15.6 is within the range >= 0.15, <= 0.17. To fix this, you can run

cargo update --package ndarray:0.16.1 --precise 0.15.6

to achieve a single dependency on version 0.15.6 of ndarray.

Contributing

We welcome issues and pull requests.

PyO3's Contributing.md is a nice guide for starting.

Also, we have a Gitter channel for communicating.

Runs on
GPU support unknown
What shows it
  • no dependency or feature matches a backend row
Native code
None found
  • No native code found
Python bindings
Has Python bindings
  • numpy needs Python
License
BSD-2-Clause

Compare with similar projects

Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.

rust-numpy beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
rust-numpy This page Featured

PyO3-based Rust bindings of the NumPy C-API

Python bindings

3,598,884 downloads over 30 days 388 1,391 0.30.0 GPU support unknown No native code found BSD-2-Clause
statrs Featured

Statistical computing library for Rust

4,515,476 downloads over 30 days 444 839 0.19.1 GPU support unknown No native code found MIT
rustfft Featured

High-performance FFT library written in pure Rust.

4,266,035 downloads over 30 days 571 963 6.4.1 GPU support unknown No native code found Apache-2.0 OR MIT
argmin Featured

Numerical optimization in pure Rust

310,783 downloads over 30 days 98 1,278 0.11.0 GPU support unknown Binds native code: lapack-sys (feature ndarray_v0_15) Apache-2.0 OR MIT
numr Listed

The base for numerical code in Rust, in the role NumPy has in Python: n-dimensional tensors, linear algebra, FFT, statistics and autograd on CPU, CUDA and WebGPU. The backends use native kernels, with no cuBLAS, MKL or other vendor math library.

1,673 downloads over 30 days 7 59 0.15.2 CUDA, WebGPU Binds native code: ring (feature distributed) Apache-2.0
pounce New

Single-crate facade for POUNCE from Rust: re-exports the TNLP trait, the IpoptApplication driver, and the supporting types in one place (plus a prelude), with feature-gated modules for the convex/LP/QP, active-set QP, and sensitivity paths.

2,486 downloads over 30 days 9 81 0.16.0 GPU support unknown Binds native code: pounce-hsl (feature ma57) EPL-2.0
Why FeaturedIt passes every Featured gate.

What it meets

  • It has 180 active dependents and 137 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days.
  • Active dependents are at 100% of their peak. Featured needs at least 50%.
  • Docs are present. The release commit or a manifest ties the crate to the repository.
  • No vulnerability advisory stays unpatched past the grace window. At least one version is neither a prerelease nor 0.0.x.
  • The last activity is on 21 Oct 2026, 19 days ago. The rules expect an update within 560 days. Dormancy rule

Exact rules: Featured library. The check on applied thresholds version 9.

Every rule outcome, as the check records it
  • expected-interval: version 0.30.0 base 140, doubled for 3598884 downloads per month, doubled for 179.5 active users: E = 560 days
  • dormancy: last activity 2026-10-21, 19 days ago, E = 560: active
  • featured: featured: active_users 179.5, new_adopters 137, former_glory 1

Measurements and sources

Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.

Sources6 sources
Adoption180 active dependents, 137 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents179.5crates.io database dumpYes
New dependents (365 days)137crates.io database dumpYes
Peak active dependents180crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 19 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-10-21GitHub repositoryYes
Latest release2026-10-15crates.io database dumpYes
First release2017-05-10crates.io database dumpYes
Latest version0.30.0crates.io database dumpYes
Days the oldest outside issue waits for a reply809GitHub repositoryYes
Maintainer replies over 365 days52GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution47 releases, 3,598,884 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases47crates.io database dumpYes
Downloads over 30 days3598884crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository1,391 stars, 140 forks, 65 contributors, 1,131 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars1391GitHub repositoryYes — one part of the repository route
GitHub forks140GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account65GitHub contributorsYes — one part of the repository route
Commits on the default branch1131GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseBSD-2-Clausecrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesNo native code foundcrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesHas Python bindings: numpy needs Pythoncrates.io database dumpNo
Crates that depend on a listed crate directly388crates.io database dumpNo

Corrections and review history

Report a correction

No correction applies to this entry.

Judgments

A judgment enters only through an approved issue and a merged pull request.

No judgment applies to this entry.