A python wrapper for tomlplusplus
See the codeThis is an python wrapper for toml++ (https://marzer.github.io/tomlplusplus/).
Some points you may want to know before use:
toml++ means that this module is fully compatible with TOML v1.0.0.json module does.pip install and we have a pre-compiled binaries ready. No need to play with clang, cmake or any C++ toolchains.In [1]: import pytomlpp
In [2]: toml_string = 'hello = "世界"'
In [3]: pytomlpp.loads(toml_string)
Out[3]: {'hello': '世界'}
In [4]: type(_)
Out[4]: dict
In [6]: pytomlpp.dumps({"你好": "world"})
Out[6]: '"你好" = "world"'
There are some existing python TOML parsers on the market but from my experience they are implemented purely in python which is a bit slow.
Parsing data.toml 1000 times:
rtoml: 0.540 s
pytomlpp: 0.542 s ( 1.00x)
tomli: 2.923 s ( 5.40x)
qtoml: 8.748 s (16.18x)
tomlkit: 51.608 s (95.49x)
toml: Parsing failed. Likely not TOML 1.0.0-compliant.
Test it for yourself using the benchmark script.
We recommend you to use pip to install this package:
pip install pytomlpp
You can also use conda to install this package, on all common platforms & python versions.
If you have an issue with a package from conda-forge, you can raise an issue on the feedstock
conda install -c conda-forge pytomlpp
You can also install from source:
git clone git@github.com:bobfang1992/pytomlpp.git --recurse-submodules=third_party/tomlplusplus --shallow-submodules
cd pytomlpp
pip install .
git clone git@github.com:bobfang1992/pytomlpp.git --recurse-submodules
cd pytomlpp
If you already cloned without submodules:
git submodule update --init --recursive
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install package in editable mode
pip install -e .
# Install test dependencies
pip install -r tests/requirements.txt
# Install build tool
pip install build
# Build wheel and source distribution
python -m build
# Output will be in dist/
ls dist/
# pytomlpp-1.1.0-cp312-cp312-macosx_*.whl
# pytomlpp-1.1.0.tar.gz
# Install in editable mode (changes to Python code take effect immediately)
pip install -e .
# Rebuild C++ extension after changes
pip install -e . --force-reinstall --no-deps
# Build extension in-place
python setup.py build_ext --inplace
# Install
python setup.py install
# From project root
pytest tests/
# With verbose output
pytest tests/ -v
# With coverage
pip install pytest-cov
pytest tests/ --cov=pytomlpp --cov-report=html
# Run only API tests
pytest tests/python-tests/test_api.py
# Run specific test function
pytest tests/python-tests/test_api.py::test_loads_valid_toml_files -v
# Run with keyword matching
pytest tests/ -k "encode"
cd tests
./run.sh # Runs the official TOML test suite
cd benchmark
pip install -r requirements.txt
python run.py
# Install pre-commit hooks
pip install pre-commit
pre-commit install
# Run manually
pre-commit run --all-files
pip install mypy
mypy src/pytomlpp/
pytomlpp/
├── src/
│ ├── pytomlpp/ # Python package
│ │ ├── __init__.py
│ │ ├── _io.py
│ │ └── _impl.pyi # Type stubs
│ ├── pytomlpp.cpp # C++ bindings (main)
│ ├── type_casters.cpp # Python/C++ type conversions
│ └── encoding_decoding.cpp # TOML encoding/decoding
├── include/
│ └── pytomlpp/ # C++ headers
├── third_party/
│ └── tomlplusplus/ # toml++ submodule
├── tests/
│ └── python-tests/ # Python test suite
├── benchmark/ # Performance benchmarks
├── pyproject.toml # Project metadata (PEP 621)
└── setup.py # C++ extension build config
git submodule update --init --recursive
Make sure you have a C++17 compatible compiler:
Reinstall in editable mode:
pip install -e . --force-reinstall --no-deps
git checkout -b feature/amazing-feature)pytest tests/)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)See CONTRIBUTING.md for detailed guidelines (if available).
C++
65.0%
Python
34.6%
A python wrapper for tomlplusplus
See the codeThis is an python wrapper for toml++ (https://marzer.github.io/tomlplusplus/).
Some points you may want to know before use:
toml++ means that this module is fully compatible with TOML v1.0.0.json module does.pip install and we have a pre-compiled binaries ready. No need to play with clang, cmake or any C++ toolchains.In [1]: import pytomlpp
In [2]: toml_string = 'hello = "世界"'
In [3]: pytomlpp.loads(toml_string)
Out[3]: {'hello': '世界'}
In [4]: type(_)
Out[4]: dict
In [6]: pytomlpp.dumps({"你好": "world"})
Out[6]: '"你好" = "world"'
There are some existing python TOML parsers on the market but from my experience they are implemented purely in python which is a bit slow.
Parsing data.toml 1000 times:
rtoml: 0.540 s
pytomlpp: 0.542 s ( 1.00x)
tomli: 2.923 s ( 5.40x)
qtoml: 8.748 s (16.18x)
tomlkit: 51.608 s (95.49x)
toml: Parsing failed. Likely not TOML 1.0.0-compliant.
Test it for yourself using the benchmark script.
We recommend you to use pip to install this package:
pip install pytomlpp
You can also use conda to install this package, on all common platforms & python versions.
If you have an issue with a package from conda-forge, you can raise an issue on the feedstock
conda install -c conda-forge pytomlpp
You can also install from source:
git clone git@github.com:bobfang1992/pytomlpp.git --recurse-submodules=third_party/tomlplusplus --shallow-submodules
cd pytomlpp
pip install .
git clone git@github.com:bobfang1992/pytomlpp.git --recurse-submodules
cd pytomlpp
If you already cloned without submodules:
git submodule update --init --recursive
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install package in editable mode
pip install -e .
# Install test dependencies
pip install -r tests/requirements.txt
# Install build tool
pip install build
# Build wheel and source distribution
python -m build
# Output will be in dist/
ls dist/
# pytomlpp-1.1.0-cp312-cp312-macosx_*.whl
# pytomlpp-1.1.0.tar.gz
# Install in editable mode (changes to Python code take effect immediately)
pip install -e .
# Rebuild C++ extension after changes
pip install -e . --force-reinstall --no-deps
# Build extension in-place
python setup.py build_ext --inplace
# Install
python setup.py install
# From project root
pytest tests/
# With verbose output
pytest tests/ -v
# With coverage
pip install pytest-cov
pytest tests/ --cov=pytomlpp --cov-report=html
# Run only API tests
pytest tests/python-tests/test_api.py
# Run specific test function
pytest tests/python-tests/test_api.py::test_loads_valid_toml_files -v
# Run with keyword matching
pytest tests/ -k "encode"
cd tests
./run.sh # Runs the official TOML test suite
cd benchmark
pip install -r requirements.txt
python run.py
# Install pre-commit hooks
pip install pre-commit
pre-commit install
# Run manually
pre-commit run --all-files
pip install mypy
mypy src/pytomlpp/
pytomlpp/
├── src/
│ ├── pytomlpp/ # Python package
│ │ ├── __init__.py
│ │ ├── _io.py
│ │ └── _impl.pyi # Type stubs
│ ├── pytomlpp.cpp # C++ bindings (main)
│ ├── type_casters.cpp # Python/C++ type conversions
│ └── encoding_decoding.cpp # TOML encoding/decoding
├── include/
│ └── pytomlpp/ # C++ headers
├── third_party/
│ └── tomlplusplus/ # toml++ submodule
├── tests/
│ └── python-tests/ # Python test suite
├── benchmark/ # Performance benchmarks
├── pyproject.toml # Project metadata (PEP 621)
└── setup.py # C++ extension build config
git submodule update --init --recursive
Make sure you have a C++17 compatible compiler:
Reinstall in editable mode:
pip install -e . --force-reinstall --no-deps
git checkout -b feature/amazing-feature)pytest tests/)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)See CONTRIBUTING.md for detailed guidelines (if available).
C++
65.0%
Python
34.6%