Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tomli in TOML handler #92

Open
eyeseast opened this issue Feb 26, 2022 · 6 comments
Open

Use tomli in TOML handler #92

eyeseast opened this issue Feb 26, 2022 · 6 comments
Milestone

Comments

@eyeseast
Copy link
Owner

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
Copy link
Owner Author

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.

@pwwang
Copy link

pwwang commented May 13, 2022

I would recommend rtoml

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

@merwok
Copy link

merwok commented May 13, 2022

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

@pwwang
Copy link

pwwang commented May 13, 2022

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.

@eyeseast
Copy link
Owner Author

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.

@tusharsadhwani
Copy link
Contributor

My suggestion: Add tomli_w as a dependency, and tomli as a dependency for when Python version is < 3.11

Something like this:

install_requires = 
  tomli==1.2.3; python_version < 3.11
  tomli-w==1.2.3

And in your Python code:

import tomli_w
if sys.version_info() >= (3, 11):
    import tomllib as tomli
else:
    import tomli

@eyeseast eyeseast added this to the 2.0 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants