Skip to main content

Fast TOML parser for Python with SIMD optimizations

Project description

FastTOML

Fast TOML parser for Python with SIMD optimizations.

Features

  • Fast: 5-10x faster than existing TOML parsers
  • 🎯 SIMD Optimized: Uses AVX2/SSE4.2 for maximum performance
  • 🔧 Drop-in Replacement: Compatible API with existing TOML libraries
  • 📦 Full TOML v1.0.0 Support: Complete specification implementation
  • 🚀 C++17 Backend: High-performance native implementation

Installation

pip install fasttoml

Usage

import fasttoml

# Parse TOML string
toml_str = '''
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
age = 42
'''

data = fasttoml.loads(toml_str)
print(data)

# Parse TOML file
data = fasttoml.load('config.toml')

# Serialize dict to TOML string
toml_out = fasttoml.dumps(data)

# Write dict to a TOML file
fasttoml.dump(data, 'output.toml')

Performance

FastTOML is designed for maximum performance using SIMD optimizations. Benchmarks compare against tomli (and optionally toml).

Run benchmarks:

pip install -e .[dev]
pytest tests/test_benchmark.py -v --benchmark-only

Example results (vs tomli): ~6–9× faster depending on document size (small/medium/large/real-world TOML). Results are grouped by payload size; install tomli (or use Python 3.11+ with built-in tomllib) for comparison.

Status and limitations

  • Status: Alpha. Suitable for parsing configs and tests; run the test suite before relying in production.
  • API: loads(s), load(fp), dumps(obj), and dump(obj, fp) are provided. Serialization (dumps/dump) is implemented in Python.
  • Types: Offset datetimes (with Z or +/-HH:MM) are returned as timezone-aware datetime (UTC). Local datetime (no offset, e.g. 1979-05-27T07:32:00) is returned as a string for toml-test/tagged-JSON compatibility. Date-only and time-only TOML values are returned as strings ("YYYY-MM-DD", "HH:MM:SS").
  • Invalid TOML: Invalid input raises ValueError with an error message; the parser does not crash on malformed data.

Requirements

  • Python 3.10+
  • CMake 3.15+
  • C++17 compatible compiler

Development

# Install development dependencies
pip install -e .[dev]

# Build
python setup.py build_ext --inplace

# Run tests (excluding long benchmarks)
pytest tests/ --ignore=tests/test_benchmark.py

# Run benchmarks vs tomli
pytest tests/test_benchmark.py -v --benchmark-only

# Run toml-test suite (optional)
# Option A: use the official toml-test binary (requires Go)
#   go install github.com/toml-lang/toml-test/v2/cmd/toml-test@latest
#   python scripts/run_toml_test.py
# Option B: pytest over cloned toml-test (clone once, then)
#   pytest tests/test_toml_test_suite.py -v
#   (uses .toml-test/ if present, else clones from GitHub; by default 80 valid + 10 invalid; TOML_TEST_FULL=1 runs all valid with 9 decoder-format skips, invalid still limited to 10)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fasttoml-0.2.0b2.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fasttoml-0.2.0b2-cp310-cp310-win_amd64.whl (92.9 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file fasttoml-0.2.0b2.tar.gz.

File metadata

  • Download URL: fasttoml-0.2.0b2.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for fasttoml-0.2.0b2.tar.gz
Algorithm Hash digest
SHA256 0dffb756e7634474058cbe410e18a9276ea4d54df608ffe4fc5c29deca75ebe4
MD5 2ed66d562350d8e6b0b6378ed03ae503
BLAKE2b-256 d098be6482c22f3c615dcce91fc10ea137c71104f67c4a3f37ad96722bfecab9

See more details on using hashes here.

File details

Details for the file fasttoml-0.2.0b2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: fasttoml-0.2.0b2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 92.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for fasttoml-0.2.0b2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 106683fba49a11f51fb50f5e4f9e5e556e5a68c6871317d3f2f03f0e6249f124
MD5 286f8a5c3afa636eec5f1db34f6188b3
BLAKE2b-256 9fffd7bd3ce16d5517be8d9e64ee30f17d24071ca5ef52c0af9324b3efee006f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page