Building Python packages and managing dependencies is still a non-trivial problem even in 2024. I wrote a blog post about some of the challenges in 2021. Many of these challenges are still true today.
There are lots of options for build backends such as PDM but also setuptools and hatchling.
The official website has a tutorial for doing packaging.