Use poetry-bumpversion with poetry. Its a poetry plugin, and not tied to the project (wich would have been nice).

poetry self add poetry-bumpversion

And in your pyproject.toml, configure as needed:


With this example it will update __version__ in ${module_name}/ to the version in pyproject.toml, and also keep the version number in tests/ up to date.