This is an example project demonstrating how to build a Python package (wheel or sdist) using uv with pyproject.toml for configuration.
[!INFO] uv does not currently have a build backend and defaults to using hatchling for building packages. For most users, this will be sufficient and invisible.
Create a new project structure if starting from scratch:
uv init --package demo-uv Install project dependencies and create a virtual environment:
uv syncExecute Python code in the project environment:
uv run python -c "import demo"Build both wheel and source distribution:
uv buildTo build only one format:
uv build --wheel # Build wheel only
uv build --sdist # Build source distribution onlyUpload built distributions to PyPI:
uv publishFor TestPyPI, configure an alternative index in pyproject.toml:
[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"Then publish using:
uv publish --index testpypiThe built distributions will be placed in the dist/ directory by default.
{{< callout type="info" >}}
Remember to set up authentication before publishing. Use UV_PUBLISH_TOKEN environment variable or the --token flag to provide your PyPI API token.
{{< /callout >}}