Eric J Ma's Website

How to configure a minimum Python version in pyproject.toml

written by Eric J. Ma on 2023-07-12 | tags: til python python310 pythonversioning pyproject.toml pythontips llamabot


Today, I learned how to set the minimum version of Python in pyproject.toml.

If I want a minimum version of Python:

[project]
python = ">=3.10"

If I want a maximum version of Python:

[project]
python = "<=3.10"

This problem came up within the context of llamabot, where I was using relatively new syntax to indicate the union of types:

doc_paths: List[str] | List[Path] | str | Path = None

Pre-Python 3.10, the only way to show this was:

doc_paths: Union[List[str], List[Path], str, Path] = None

Visually, I think the post-Python 3.10 syntax is a bit easier to reason about.

h/t my colleague Jiayi Cox who helped me identify the bug in this issue.


I send out a newsletter with tips and tools for data scientists. Come check it out at Substack.

If you would like to sponsor the coffee that goes into making my posts, please consider GitHub Sponsors!

Finally, I do free 30-minute GenAI strategy calls for organizations who are seeking guidance on how to best leverage this technology. Consider booking a call on Calendly if you're interested!