Info: | Basic(TM) library meant to work with a subset of TOML spec, intended to be used on CircuitPython. |
---|---|
Author: | Pablo Martinez Bernal <[email protected]> |
As of summer 2023, os.getenv:
- Only supports reading base-10 integers and strings.
- File to be read is hardcoded at compilation (settings.toml by default).
- Can only read one key at a time.
- Cant change values. To be fair, most of the times CircuitPython will have read-only access t othe filesystem, anyway.
While this is good enough for many use cases, i felt like writing a feature-complete(ish) parser would be nice for the sake of learning but also to help other users getting around these limitations.
This driver depends on:
i.e. No dependencies :)
Will not be in PyPI (yet?). Reason for this is simple, CPython ships with tomllib on its stdlib, use it instead.
Make sure that you have circup
installed in your Python environment.
Install it with the following command if necessary:
pip3 install circup
With circup
installed and your CircuitPython device connected use the
following command to install:
circup install toml
Or the following command to update an existing version:
circup update
It's pretty straight forward, it's similar to the toml module on CPython's standard lib. Here's a little example showing the power of Dotty for accessing nested items.
>>> import toml
>>>
>>> with open("settings.toml", "r") as f:
>>> data = toml.load(f)
>>>
>>> data["foo"]["bar"]
"baz"
>>> data["foo.bar"]
"baz"
Maybe in the future
TODO: Proper list of requisites and whatnot. For now just open PRs and issues, they are very much welcome!!
dotty_dict For the inspiration to do a wrapper on top of a dict to easily access items based on dotted keys (Dotty is a subset of said library)