Fast number theory utilities backed by Rust
Project description
numbertoolkit
Fast number theory utilities for Python, backed by Rust.
import numbertoolkit
numbertoolkit.pi_digits(10)
# '3141592653'
numbertoolkit.pi_digits(10, decimal_point=True)
# '3.141592653'
Functions
pi_digits,e_digits,phi_digits— firstnsignificant digits of pi, e, and the golden ratiosqrt_digits— firstnsignificant digits of the square root of any positive integeris_prime— primality checkfirst_n_primes— the firstnprimes in ascending order
Digit functions return truncated (not rounded) digit strings, computed with exact integer arithmetic in Rust — fast well into the millions of digits.
Documentation
Full docs live at koaning.github.io/numbertools,
built with Zensical from the docs/ directory. To
preview locally:
make docs # live-reloading preview at http://localhost:8000
Demo
An interactive marimo notebook demoing the package:
uv run marimo edit demo.py
Benchmarks
Compare against mpmath and stdlib baselines:
uv run --group bench benchmarks/bench_pi.py
uv run --group bench benchmarks/bench_e.py
uv run --group bench benchmarks/bench_sqrt.py
On an Apple Silicon laptop:
| digits | numbertoolkit | mpmath | speedup vs mpmath |
|---|---|---|---|
| 10,000 | 0.0008s | 0.0052s | 6x |
| 100,000 | 0.0154s | 0.1926s | 13x |
| 1,000,000 | 0.2526s | 9.0297s | 36x |
Development
make install # uv sync: build the extension and set up .venv
make test # cargo test + pytest
make bench # run the benchmark suite
uvx maturin develop --uv -r # fast rebuild loop (release mode)
Note: maturin develop without -r produces a debug build that is 10–50x
slower — always use release mode when timing anything.
Releasing
Tests run automatically on GitHub (.github/workflows/ci.yml); publishing to
PyPI is done manually. Thanks to abi3, each wheel covers Python 3.10+ on its
platform, and cross-compiling doesn't need a target Python interpreter.
make wheels builds the native release set (macOS wheel, both Linux wheels
via zig, sdist). make wasm-wheel builds a Pyodide/WebAssembly wheel (PEP 783
pyemscripten tag, Python 3.14) so micropip.install("numbertoolkit") works
in Pyodide ≥ 314 runtimes such as marimo WASM; on first run it sets up emsdk
and the pinned Rust toolchain under .wasm-toolchain/. Unlike the native
wheels, the wasm wheel's platform tag pins one Pyodide ABI year, so it needs
a rebuild whenever Pyodide moves to a new ABI. make pypi runs the tests,
builds all of the above, and uploads. The underlying commands for the native
set:
# wheel for this machine + source distribution (lands in target/wheels/)
uvx maturin build --release
uvx maturin sdist
# optional: manylinux wheels cross-compiled from macOS via zig
rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu
uvx --with ziglang maturin build --release --zig --target x86_64-unknown-linux-gnu
uvx --with ziglang maturin build --release --zig --target aarch64-unknown-linux-gnu
# upload everything (needs a PyPI API token, e.g. via UV_PUBLISH_TOKEN)
uv publish target/wheels/*
Bump the version in pyproject.toml before building. Platforms without an
uploaded wheel (e.g. Windows) fall back to the sdist, which requires a Rust
toolchain to install.
License
This project is MIT licensed. It statically links malachite (LGPL-3.0-only) for big-integer arithmetic; malachite's source is available on crates.io. If you embed this library in a closed-source distribution, the LGPL relinking requirements apply to the bundled malachite code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numbertoolkit-0.1.1.tar.gz.
File metadata
- Download URL: numbertoolkit-0.1.1.tar.gz
- Upload date:
- Size: 101.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3704427d300a26eb8fb2158e35a2c6d803bbf0063db70cc836773dce3858b82
|
|
| MD5 |
73c419129c4bc77e9223f72a8abb9954
|
|
| BLAKE2b-256 |
0b7c2743c2b8cb61ab03063cf6383e33155a4d2075076bc554de31a32152d22f
|
File details
Details for the file numbertoolkit-0.1.1-cp310-abi3-pyemscripten_2026_0_wasm32.whl.
File metadata
- Download URL: numbertoolkit-0.1.1-cp310-abi3-pyemscripten_2026_0_wasm32.whl
- Upload date:
- Size: 426.9 kB
- Tags: CPython 3.10+, PyEmscripten 2026.0 wasm32
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4918ee822dbfbf7ed146df58803a6142b17ef1012e456c0450191592a73a9781
|
|
| MD5 |
a085a8b4fccb7c06b4f645ae24312120
|
|
| BLAKE2b-256 |
41d48bcb16eb4fa34c15ce7aea413c60d95e26e7fbe22f42db55765a5bad1896
|
File details
Details for the file numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 782.6 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c8738053f298c3b21e4685cca6950d7b0d9f205f141d2374ee9290ef48c3615
|
|
| MD5 |
846e266955c73dd4c82024c2ce1f2e1d
|
|
| BLAKE2b-256 |
a5c4632a9b4dbaf509d1a40c5da58d4b11159ae46be31fd7ed117249503c7864
|
File details
Details for the file numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 625.9 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d60d257501639c77f0a3bf10ea73e946f6e095cf62d47c9927faf31ae235dff
|
|
| MD5 |
57033ee17495ee3ba9b2ab87ebb9a3e0
|
|
| BLAKE2b-256 |
a6e3b457c168834398c809b3d1cb7a564dfa3837415e3bff9ab245f6b1eb6756
|
File details
Details for the file numbertoolkit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: numbertoolkit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 618.8 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
713cfdd22527111c65dc61c27ab16d200a15717285ff31ddf2a4d6150abf0b15
|
|
| MD5 |
d14890b8b667383cd4348bb18c8322af
|
|
| BLAKE2b-256 |
4ba9b902f148b6db43a43fdb156ac2160d51305ae75e408aadb785747033b648
|