python-frontmatter icon indicating copy to clipboard operation
python-frontmatter copied to clipboard

Use tomli in TOML handler

Open eyeseast opened this issue 3 years ago • 6 comments

Looks like this is the new standard: https://pypi.org/project/tomli/

Need to check if this has the same API as the original toml. It might be worth creating an additional TOML handler using tomli, so you can import each one separately.

eyeseast avatar Feb 26 '22 18:02 eyeseast

As noted here, I should add an extra so you can do pip install python-frontmatter[toml] (or [tomli]) and get everything in one shot.

eyeseast avatar Feb 26 '22 21:02 eyeseast

I would recommend rtoml

See: https://github.com/pwwang/toml-bench

pwwang avatar May 13 '22 02:05 pwwang

FYI Python is gaining tomllib in the 3.11 standard library, which is adapted from tomli

merwok avatar May 13 '22 11:05 merwok

FYI Python is gaining tomllib in the 3.11 standard library, which is adapted from tomli

tomli is also a good choice, not only because of the reason you mentioned, it's implemented in pure python. If we don't need .load() or .loads(), which is implemented in a different package (tomli_w), then I am not against tomli here.

pwwang avatar May 13 '22 21:05 pwwang

With Python 3.11 now available this feels like a higher priority. Since tomllib is read-only, I need to think about how to include it. Some options, in no particular order:

  1. Use tomllib but make the TOMLHandler read-only by default. In that case, you could read TOML but would have to write in another format, unless you install another library (probably tomli_w).
  2. Add tomli_w as a dependency. That preserves current functionality, maybe extends it a bit, but adds a dependency.
  3. Require tomli_w to use TOMLHandler. Again, basically the same as now, but with a different optional dependency.
  4. Use tomlkit to get reading and writing and also preserve format.

I don't use TOML enough to have a strong opinion here. Would like to hear from people who use the current TOML support.

eyeseast avatar Oct 25 '22 02:10 eyeseast