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.


Cite this blog post:
@article{
    ericmjl-2023-how-pyprojecttoml,
    author = {Eric J. Ma},
    title = {How to configure a minimum Python version in pyproject.toml},
    year = {2023},
    month = {07},
    day = {12},
    howpublished = {\url{https://ericmjl.github.io}},
    journal = {Eric J. Ma's Blog},
    url = {https://ericmjl.github.io/blog/2023/7/12/how-to-configure-a-minimum-python-version-in-pyprojecttoml},
}
  

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 teams that are looking to leverage GenAI for maximum impact. Consider booking a call on Calendly if you're interested!