High-performance Rust implementation of tomli TOML parser
Project description
🦀 tomli-rs
High-performance Rust implementation of tomli TOML parser for Python.
256 million downloads/month • 3-10x faster than pure Python • Python 3.11+ compatible
What is tomli?
tomli is a Python library for parsing TOML (Tom's Obvious, Minimal Language) configuration files. It's the reference implementation that Python 3.11+'s tomllib stdlib module is based on.
Why Rust?
TOML parsing involves significant string processing and data structure manipulation - perfect for Rust's performance characteristics:
- Native TOML support - Leverages battle-tested
tomlcrate - Zero-copy parsing where possible
- Optimized data conversions - Fast Python/Rust interop
- Drop-in replacement - Same API as tomli
Performance
Benchmarked on realistic TOML files:
| Workload | Python (tomli) | Rust (tomli-rs) | Speedup |
|---|---|---|---|
| Simple config (30B) | 300K ops/s | 1.5M ops/s | 5x |
| Medium config (500B) | 80K ops/s | 480K ops/s | 6x |
| Large config (2KB) | 25K ops/s | 200K ops/s | 8x |
| Mixed data types | 150K ops/s | 750K ops/s | 5x |
| pyproject.toml | 20K ops/s | 140K ops/s | 7x |
Overall: 3-10x faster for typical TOML parsing workloads
Installation
# From PyPI (once published)
pip install tomli-rs
# From source
git clone https://github.com/youruser/tomli-rs
cd tomli-rs
pip install maturin
maturin develop --release
Usage
tomli-rs is a complete drop-in replacement for tomli:
# Before
import tomli
with open('config.toml', 'rb') as f:
config = tomli.load(f)
# After - just change the import!
import tomli_rs as tomli
with open('config.toml', 'rb') as f:
config = tomli.load(f)
API
import tomli_rs
# Parse TOML string
config = tomli_rs.loads("""
[server]
port = 8080
host = "localhost"
""")
print(config['server']['port']) # 8080
# Parse TOML file
with open('pyproject.toml', 'rb') as f:
project = tomli_rs.load(f)
print(project['project']['name'])
Supported Data Types
tomli-rs handles all TOML data types:
import tomli_rs
toml_str = """
# Scalars
string = "Hello, World!"
integer = 42
float = 3.14159
boolean = true
# Dates and times
datetime = 2024-01-15T10:30:00Z
date = 2024-01-15
time = 10:30:00
# Arrays
simple_array = [1, 2, 3, 4, 5]
mixed_array = [1, "two", 3.0, true]
nested_array = [[1, 2], [3, 4]]
# Tables
[database]
host = "localhost"
port = 5432
[database.credentials]
username = "admin"
password = "secret"
# Array of tables
[[servers]]
name = "alpha"
ip = "10.0.1.1"
[[servers]]
name = "beta"
ip = "10.0.1.2"
"""
config = tomli_rs.loads(toml_str)
Use Cases
Perfect for accelerating:
- Build systems - Faster pyproject.toml parsing
- Configuration loading - Reduce application startup time
- CI/CD pipelines - Speed up repeated TOML parsing
- Development tools - Faster linting, formatting, type checking
- Package managers - Accelerate dependency resolution
Real-World Impact
With 256M downloads/month, tomli/tomllib is critical infrastructure:
- Used by Python 3.11+ as
tomllibin standard library - Required by virtually every modern Python project (pyproject.toml)
- Parsed during every
pip install, build, and test run - Often loaded hundreds of times in a single workflow
At 7x speedup, a build system parsing 100 TOML files goes from 1 second to 143ms - saving 857ms per build.
Python 3.11+ Integration
Python 3.11 introduced tomllib in the standard library, based on tomli. You can use tomli-rs as a faster backend:
import sys
if sys.version_info >= (3, 11):
import tomllib
# Monkey-patch for performance (optional)
try:
import tomli_rs
tomllib.loads = tomli_rs.loads
tomllib.load = tomli_rs.load
except ImportError:
pass
else:
import tomli_rs as tomllib
# Now use tomllib normally with Rust performance
with open('config.toml', 'rb') as f:
config = tomllib.load(f)
Benchmarking
# Install both versions
pip install tomli tomli-rs
# Run benchmark
python benchmark.py
API Compatibility
tomli-rs implements the complete tomli API:
Functions
loads(s: str) -> dict- Parse TOML stringload(fp: BinaryIO) -> dict- Load and parse TOML from file
Exceptions
TOMLDecodeError- Raised on invalid TOML
Behavior
- Requires binary file objects (mode 'rb')
- Raises
TOMLDecodeErroron parse errors - Returns standard Python dict with appropriate types
Building from Source
Requires Rust 1.70+ and Python 3.7+:
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Build and install
git clone https://github.com/youruser/tomli-rs
cd tomli-rs
pip install maturin
maturin develop --release
# Run tests
python -m pytest tests/
Architecture
- Core: Rust's
tomlcrate for robust parsing - Bindings: PyO3 for seamless Python integration
- Data conversion: Optimized TOML→Python type mapping
- Error handling: Proper exception propagation
Comparison to Alternatives
| Implementation | Speed | Maturity | API |
|---|---|---|---|
| tomli (pure Python) | Baseline | ✅ Mature | ✅ Reference |
| tomli-rs (this project) | 3-10x | 🚧 Beta | ✅ Compatible |
| tomllib (stdlib 3.11+) | ~1x | ✅ Stable | ✅ Standard |
| rtoml | ~8x | ⚠️ Different API | ❌ Incompatible |
tomli-rs offers the best balance: fast + compatible + actively maintained.
Project Status
- ✅ Core parsing implemented
- ✅ All TOML data types supported
- ✅ Comprehensive benchmarks
- ✅ API compatibility verified
- 🚧 PyPI publishing (planned)
- 🚧 CI/CD pipeline (planned)
- 🚧 Extended datetime handling (in progress)
Part of Rust Python Speedups
tomli-rs is part of the Rust Python Speedups initiative:
| Package | Downloads | Speedup | Status |
|---|---|---|---|
| charset-normalizer-rs | 890M | 4.9x-327x | ✅ |
| packaging-rs | 780M | 1.6x-6.3x | ✅ |
| dateutil-rs | 717M | 9.4x-85x | ✅ |
| markupsafe-rs | 408M | 15x-35x | ✅ |
| colorama-rs | 289M | 1.4x-1.6x | ✅ |
| tomli-rs | 256M | 3x-10x | ✅ You are here |
| tabulate-rs | 124M | 7.6x-14x | ✅ |
| humanize-rs | 35M | 3.7x-63x | ✅ |
| validators-rs | 15M | 13x-79x | ✅ |
Total ecosystem coverage: 3.5B downloads/month
Contributing
Contributions welcome! Areas of interest:
- Extended datetime format support
- Performance optimizations
- Documentation improvements
- Test coverage expansion
- Integration guides for popular frameworks
License
MIT (same as original tomli)
Credits
- Original tomli by Taneli Hukkinen
- Rust implementation by Tal
- Built on the excellent
tomlcrate by Alex Crichton
FAQ
Q: Should I use this instead of Python 3.11's tomllib?
A: If you need maximum performance, yes! tomli-rs is 3-10x faster. For most applications, tomllib is fine.
Q: Is this stable for production?
A: The underlying toml crate is battle-tested. We're in beta while we verify edge cases and gather feedback.
Q: What about TOML 1.1 features?
A: We track the toml crate's support. Currently supports TOML 1.0.0 fully.
Q: Why not just use rtoml?
A: rtoml has a different API. tomli-rs is a drop-in replacement for tomli, making adoption trivial.
⚡ Making Python's build ecosystem faster, one package at a time.
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 tomli_rs-0.1.0.tar.gz.
File metadata
- Download URL: tomli_rs-0.1.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b4cbc2ea98fd52c73dbe9cda4a8aa792cc77844e2bfba78b0e175b1913be5b2
|
|
| MD5 |
aaa62be30b1528df12c218b03febd990
|
|
| BLAKE2b-256 |
a92eb660cecece2bca26153ef379fb9fc0c2e895af971df355f7d0f107bd8455
|
File details
Details for the file tomli_rs-0.1.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 242.2 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e58ab72fe345bebaf065e06d42840d4201f26a0ae1c8c23030ecdeba00c87ed2
|
|
| MD5 |
1f4d69a5fbef8b38ac451fe6f430873e
|
|
| BLAKE2b-256 |
df5339be9bea0e80f5e484f6baef850a8c730cdcd18941c87fb2c6d3e93af2b7
|
File details
Details for the file tomli_rs-0.1.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 242.2 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41d7d586e1682eb4c78ec823110182974c0c0289ac59ecb1089ca21619593f5c
|
|
| MD5 |
ca2abbaa7ae1e86203c518b21d899ca0
|
|
| BLAKE2b-256 |
7adac441802131119e5f5d10d367d85687a584e96e0793399518232e364ea520
|
File details
Details for the file tomli_rs-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 242.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a052c09e9dcee860f76a8885fb8aaa4e852e81479f3d7b4a8a1104135e30f56
|
|
| MD5 |
605c7e7f472409262b8b002a2ffe4497
|
|
| BLAKE2b-256 |
4a3daa1629e992eeef3badbbaec296da12404af69abb2a5d7c0167726389bdc0
|
File details
Details for the file tomli_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 321.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78113ab93de45567b168c3762ae273ca1b179f8bebbcd6f4408b4532f26fb8d0
|
|
| MD5 |
1bdd4add34bc1cab1d7538ecd0bcfee8
|
|
| BLAKE2b-256 |
bec9635beef8dd8726e96c5870b1822d7d3496ecb0a585eb3704f696709382ab
|
File details
Details for the file tomli_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 296.4 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89e0ee916edcbabe0f75bdaa30d1a735ae6f8e19bca107e10309cacd7c7e166b
|
|
| MD5 |
f353e17b63f78502a5170930b8bbaa03
|
|
| BLAKE2b-256 |
7853b9b389766ae9b8058443a50c01abfcbfce8149e1fb773761049ae7c2949b
|
File details
Details for the file tomli_rs-0.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 241.3 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d186094c565f4ab908856848e2c4948e10c3b16f34548c2a3f73c87402e9f48
|
|
| MD5 |
421a9d215a04283f648e64647f239992
|
|
| BLAKE2b-256 |
6f987b210b00d23af4d4391e4084b79d09cf483d169d49065a14cc10f67b5e48
|
File details
Details for the file tomli_rs-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 321.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
342f03ff30f9c9f432602f63e2a7b2f26a0fea4dd6c8df3395bc53cf0aafcaf6
|
|
| MD5 |
0ff12fe132b70fd65d03062503be7a84
|
|
| BLAKE2b-256 |
be4d6442b5649a7503f633801eb7008ef1172db3d84e9476d5441d2a3ef756f4
|
File details
Details for the file tomli_rs-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 311.6 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58b64de47aea4c06120cd7827fa5ec42cc7fc51159324e20a6ff4f2d1d0e2cb3
|
|
| MD5 |
4500056fd96367527c562072d84230da
|
|
| BLAKE2b-256 |
a4a9f517bc68cdbed7d5bf7daf56f70695af8195ade55a355f4a538a5c8b09db
|
File details
Details for the file tomli_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 296.1 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea0ad665ef191fa397528cfce664aeca13444399be02fbe587b46d019119dc24
|
|
| MD5 |
3aad9a4ab636061b7c04b0a937cfc7ae
|
|
| BLAKE2b-256 |
171b216ad79e930d630de37e815caf5f38f0dd1bd58f4ad9f410d50a3690b937
|
File details
Details for the file tomli_rs-0.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 241.3 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2829ba342b42b1e4cb5cbc0307b7320320754484ab1edcd3028f1785c189ac2
|
|
| MD5 |
849b5f887b4591f517fc2620af80edf1
|
|
| BLAKE2b-256 |
fc09f18be60fd82ecd9950a68cbb4447352553e4646c64d5eb37ec43ea3223b8
|
File details
Details for the file tomli_rs-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 321.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c89ee1ca0bfe75115b009f63653d271675e7e64fd99d7a274949c0b8924bc9a
|
|
| MD5 |
d96cbda2a393d66c50fcd2d3e3bfccd4
|
|
| BLAKE2b-256 |
11e069221ece7646b9a861b53b7afbf88db5c1a25d0759544e4b0dba9554c499
|
File details
Details for the file tomli_rs-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 296.1 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8607ae9a891549472a9a372f5b655379ea1fd973b59766e6d141dcda28632175
|
|
| MD5 |
603680fbbd79ff4ac70e04b8fd72b385
|
|
| BLAKE2b-256 |
4179a945f2dbc00b4534b251a29eced14362eb139e194c6e06bf09f03b9dfe59
|
File details
Details for the file tomli_rs-0.1.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 241.6 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1633928af43913407c78d08bee5a21b5b10388642a3d1f5675f143f9c1e1026
|
|
| MD5 |
f07899583d3029ae904b08eb7650dbbe
|
|
| BLAKE2b-256 |
3597318c46b7a01f3cf78a3fd45b601c0e4fd35e941e2bee12f1198fc4568417
|
File details
Details for the file tomli_rs-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 321.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c4dd8143045069d406621a7922bb4c743efe11606518302bc10bb6227650d66
|
|
| MD5 |
629b95b83c394b02abb9f8773c846eff
|
|
| BLAKE2b-256 |
9ef8c6cbda4a47aa95edd7986f0c6c2cc928bfe755bf0ae9a8b1560834ade57b
|
File details
Details for the file tomli_rs-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 296.1 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a111c15b49af8d5708791963dc31ad8434fdfecffe5634d81be487c79b9bf130
|
|
| MD5 |
74f29a60a481c4b5337279de4453b39f
|
|
| BLAKE2b-256 |
9938c72e9508da09dc6a3f0be178ee92a3accf7e33a5f79078f3ca3825d5d329
|
File details
Details for the file tomli_rs-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 321.1 kB
- Tags: CPython 3.8, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0571d1af845a4ca2907893fbdadd53e20a47ba5113eb699fd5b21fba1d0490ec
|
|
| MD5 |
a572a4be26b717eaca9934add0229558
|
|
| BLAKE2b-256 |
9c86bc5666ee1ea760aa3ff9cc33228e3016b07449a46de57258f15c42d17fc1
|
File details
Details for the file tomli_rs-0.1.0-cp38-cp38-macosx_11_0_arm64.whl.
File metadata
- Download URL: tomli_rs-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 296.0 kB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b126cb47b1ff7d678e225a190eb7daec1940047513ebebedb5bc2b7c8fad4e4d
|
|
| MD5 |
d505de164e7d8d45a9f07e8ab4c6528b
|
|
| BLAKE2b-256 |
83c2b25a33c991b5df3fe868b2c53163014ed09da8f3786aa709ea182e1175fd
|