Registry / serialization / pytoml

pytoml

JSON →
library0.1.21pypypi✓ verified 89d ago

pytoml is a Python library designed for parsing and writing TOML (Tom's Obvious, Minimal Language) files. It specifically targets version 0.4.0 of the TOML specification. The library provides an interface similar to Python's standard `json` module, offering `load`, `loads`, `dump`, and `dumps` functions. The project is no longer actively maintained, with its last release (0.1.21) in July 2019.

pip install pytoml
INSTALL
IMPORT
SIG · PYTOML
P
pytoml
serializationpythonv0.1.21
Install
1.6s avg
Import
24ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.1.21 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.026s · 17.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.022s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load, loads, dump, dumps
✓ import pytoml as toml
✗ import pytoml
The common and recommended practice is to import `pytoml` as `toml` to align with other TOML libraries and the common CLI tool name.

Demonstrates loading TOML data from a string and a file-like object, and dumping a Python dictionary to a TOML string. Note that `load` expects a binary-read file object (e.g., opened with 'rb').

import pytoml as toml import io # Loading from a string toml_string = 'title = "My TOML Document"\nowner = { name = "John Doe" }' data_from_string = toml.loads(toml_string) print(f"From string: {data_from_string}") # Loading from a file-like object (e.g., a file) # Using io.BytesIO to simulate reading a file in binary mode ('rb') toml_file_content = b'[database]\nserver = "192.168.1.1"\nports = [8001, 8002, 8003]' file_like_object = io.BytesIO(toml_file_content) data_from_file = toml.load(file_like_object) print(f"From file-like object: {data_from_file}") # Dumping to a string dict_to_dump = {'server': '10.0.0.1', 'connection_max': 5000} dumped_string = toml.dumps(dict_to_dump) print(f"Dumped TOML string:\n{dumped_string}")
Debug
Known issues
breakingThe `pytoml` library is officially deprecated and no longer actively maintained. Its GitHub README explicitly advises users to consider alternatives. This means it will not receive updates for new Python versions, TOML specification changes, or security fixes.
fix
Migrate to actively maintained TOML parsers such as `tomli` (standard library in Python 3.11+, read-only) or `tomlkit` (for full round-trip preservation and writing).
affects: All versions, especially 0.1.21 and older
breakingpytoml only supports TOML specification version 0.4.0. The current stable TOML specification is 1.0.0. Using `pytoml` with modern `pyproject.toml` files or other TOML 1.0.0 compliant configurations will likely lead to parsing errors or incorrect data interpretation due to syntax changes between versions.
fix
Switch to a TOML 1.0.0 compliant parser. `tomli` (for Python 3.6-3.10 and earlier 3.11+, read-only) and `tomlkit` (for full TOML 1.0.0 support, including preserving formatting) are recommended alternatives.
affects: All versions, as it's an inherent design limitation.
gotchaWhen using `toml.load()`, the file object must be opened in binary read mode (`'rb'`). Passing a text-mode file object (`'r'`) will result in a `TypeError` or unexpected behavior.
fix
Always open TOML files for reading with `with open('your_file.toml', 'rb') as f: data = toml.load(f)`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytoml'
The 'pytoml' library is not installed in the current Python environment or the environment is not active.
fix
pip install pytoml
TypeError: a string-like object is required, not 'bytes'
The `pytoml.loads()` function (or similar) was passed a bytes-like object (e.g., from a file opened in binary mode) when it expects a string.
fix
Ensure the input is a string. If reading from a file, open it in text mode (e.g., `open('file.toml', 'r', encoding='utf-8')`) or decode the bytes if already read (e.g., `data.decode('utf-8')`).
pytoml.tomllang.TomlParsingError
The input TOML string or file contains syntax errors or does not conform to the TOML 0.4.0 specification that `pytoml` implements.
fix
Review and correct the TOML syntax in the input data to ensure it is valid according to the TOML 0.4.0 specification.
DeprecationWarning: distutils Version classes are deprecated
This warning occurs in newer Python versions (3.10+) because `pytoml` internally uses `distutils.version`, which has been deprecated.
fix
This is a warning from the library itself due to its age and not an error that stops execution. No direct fix for the user's code, but you can ignore the warning or consider migrating to a more actively maintained TOML library if it's bothersome.
Upgrade
Version history
0.1.21latest on PyPI · released Jul 21, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
pytoml — pip install pytoml · libregistry