Skip to content

python-developer-tooling-handbook/demo-uv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example Python Package

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.

Commands

Initialize the Project

Create a new project structure if starting from scratch:

uv init --package demo-uv 

Setup Project Environment

Install project dependencies and create a virtual environment:

uv sync

Running Code

Execute Python code in the project environment:

uv run python -c "import demo"

Building

Build both wheel and source distribution:

uv build

To build only one format:

uv build --wheel  # Build wheel only
uv build --sdist  # Build source distribution only

Publishing

Upload built distributions to PyPI:

uv publish

For 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 testpypi

The 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 >}}

About

Python Package repository example using uv

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages