New TOML encoder/decoder
Project description
qtoml is another Python TOML encoder/decoder. I wrote it because I found uiri/toml too unstable, and PyTOML too slow.
For information concerning the TOML language, see toml-lang/toml.
qtoml currently supports TOML v0.5.0.
Usage
qtoml is available on PyPI. You can install it using pip:
$ pip install qtoml
qtoml supports the standard load/loads/dump/dumps API common to most similar modules. Usage:
>>> import qtoml
>>> toml_string = """
... test_value = 7
... """
>>> qtoml.loads(toml_string)
{'test_value': 7}
>>> print(qtoml.dumps({'a': 4, 'b': 5.0}))
a = 4
b = 5.0
>>> infile = open('filename.toml', 'r')
>>> parsed_structure = qtoml.load(infile)
>>> outfile = open('new_filename.toml', 'w')
>>> qtoml.dump(parsed_structure, outfile)
TOML supports a fairly complete subset of the Python data model, but notably does not include a null or None value. If you have a large dictionary from somewhere else including None values, it can occasionally be useful to substitute them on encode:
>>> print(qtoml.dumps({ 'none': None }))
qtoml.encoder.TOMLEncodeError: TOML cannot encode None
>>> print(qtoml.dumps({ 'none': None }, encode_none='None'))
none = 'None'
The encode_none value must be a replacement encodable by TOML, such as zero or a string.
This breaks reversibility of the encoding, by rendering None values indistinguishable from literal occurrences of whatever sentinel you chose. Thus, it should not be used when exact representations are critical.
Development/testing
qtoml uses the poetry tool for project management. To check out the project for development, run:
$ git clone --recursive-submodules https://github.com/alethiophile/qtoml
$ cd qtoml
$ poetry install
This assumes poetry is already installed. The package and dependencies will be installed in the currently active virtualenv if there is one, or a project-specific new one created if not.
qtoml is tested against the alethiophile/toml-test test suite, forked from uiri’s fork of the original by BurntSushi. To run the tests, after checking out the project as shown above, enter the tests directory and run:
$ pytest # if you already had a virtualenv active
$ poetry run pytest # if you didn't
License
This project is available under the terms of the MIT license.
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 Distribution
File details
Details for the file qtoml-0.3.0.tar.gz
.
File metadata
- Download URL: qtoml-0.3.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0b8 CPython/3.8.0 Linux/5.3.13-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06aac0e068d1d11c55b8c2df38625e589ad63847447fff8c53078e8d9db9935d |
|
MD5 | 8b55fb2791c99ab2f9a4376115c5ac41 |
|
BLAKE2b-256 | 02ef70e74e24c112afc70a25c5abbf3e2b508fac2cf0f50becb024cf6fe0a610 |
File details
Details for the file qtoml-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: qtoml-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0b8 CPython/3.8.0 Linux/5.3.13-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 224ae6d10c7d4e7e00bfdeb19001948757d589db5dd61abcd4906e24a7f72995 |
|
MD5 | ec12256b5fa5e8bb3da61f3c8c322b6a |
|
BLAKE2b-256 | 2d4f41b1c6d99ba0b2616d5eff367f4f174b66cd75ae4c6e3cf93582299e9445 |