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.
Release files for numbertoolkit 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| numbertoolkit-0.1.1.tar.gz | 101.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| numbertoolkit-0.1.1-cp310-abi3-pyemscripten_2026_0_wasm32.whl | CPython 3.10 | abi3 | PyEmscripten 2026.0+ WebAssembly | Details |
| numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| numbertoolkit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size:2.6 MB
Release files / numbertoolkit-0.1.1.tar.gz
| Download URL | numbertoolkit-0.1.1.tar.gz |
|---|---|
| Size | 101.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3704427d300a26eb8fb2158e35a2c6d803bbf0063db70cc836773dce3858b82
|
|
BLAKE2b-256 checksum How to use checksums |
0b7c2743c2b8cb61ab03063cf6383e33155a4d2075076bc554de31a32152d22f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / numbertoolkit-0.1.1-cp310-abi3-pyemscripten_2026_0_wasm32.whl
| Download URL | numbertoolkit-0.1.1-cp310-abi3-pyemscripten_2026_0_wasm32.whl |
|---|---|
| Size | 426.9 kB |
| Tags | CPython 3.10 PyEmscripten 2026.0+ WebAssembly abi3 |
|
SHA-256 checksum How to use checksums |
4918ee822dbfbf7ed146df58803a6142b17ef1012e456c0450191592a73a9781
|
|
BLAKE2b-256 checksum How to use checksums |
41d48bcb16eb4fa34c15ce7aea413c60d95e26e7fbe22f42db55765a5bad1896
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 782.6 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
9c8738053f298c3b21e4685cca6950d7b0d9f205f141d2374ee9290ef48c3615
|
|
BLAKE2b-256 checksum How to use checksums |
a5c4632a9b4dbaf509d1a40c5da58d4b11159ae46be31fd7ed117249503c7864
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | numbertoolkit-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 625.9 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
6d60d257501639c77f0a3bf10ea73e946f6e095cf62d47c9927faf31ae235dff
|
|
BLAKE2b-256 checksum How to use checksums |
a6e3b457c168834398c809b3d1cb7a564dfa3837415e3bff9ab245f6b1eb6756
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / numbertoolkit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | numbertoolkit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 618.8 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
713cfdd22527111c65dc61c27ab16d200a15717285ff31ddf2a4d6150abf0b15
|
|
BLAKE2b-256 checksum How to use checksums |
4ba9b902f148b6db43a43fdb156ac2160d51305ae75e408aadb785747033b648
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|