Interview Prep/Python for DevOps/Environments, dependencies & packaging

How do you build and publish a Python package?

IntermediateConceptEnvironments, dependencies & packaging
Answer
pip install build twine
python -m build              # dist/*.whl and dist/*.tar.gz
twine check dist/*
twine upload --repository-url https://pypi.internal/ dist/*

The build backend (setuptools, hatchling, flit-core, pdm-backend, poetry-core) is declared in [build-system]. For internal tools we publish to a private index (CodeArtifact, Artifactory, Nexus, GitLab package registry). For PyPI, use Trusted Publishing from CI via OIDC instead of API tokens.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, dependencies & packaging