uv build
Build Python packages into source distributions (sdist) and wheels.Usage
Description
uv build accepts a path to a directory or source distribution, which defaults to the current working directory.
By default, if passed a directory, uv build will build:
- A source distribution (“sdist”) from the source directory
- A binary distribution (“wheel”) from the source distribution
--sdist and --wheel flags.
If passed a source distribution, uv build --wheel will build a wheel from the source distribution.
Arguments
[SRC]
The directory from which distributions should be built, or a source distribution archive to build into a wheel.
Defaults to the current working directory.
Options
Build output options
--sdist
Build only a source distribution from the given directory.
--wheel
Build only a binary distribution (wheel) from the given directory.
--sdist --wheel
Build both distributions from source.
Output directory
-o, --out-dir <OUT_DIR>
The output directory to which distributions should be written.
Defaults to the dist subdirectory within the source directory, or the directory containing the source distribution archive.
Workspace options
--package <PACKAGE>
Build a specific package in the workspace.
The workspace will be discovered from the provided source directory, or the current directory if no source directory is provided.
If the workspace member does not exist, uv will exit with an error.
--all-packages
Build all packages in the workspace.
The workspace will be discovered from the provided source directory, or the current directory if no source directory is provided.
--all
Build constraints
-c, --build-constraints <BUILD_CONSTRAINTS>
Constrain build dependencies using the given requirements files when building distributions.
Constraints files are requirements.txt-like files that only control the version of a build dependency that’s installed. However, including a package in a constraints file will not trigger the inclusion of that package on its own.
UV_BUILD_CONSTRAINT
Alias: --build-constraint
Hash verification
--require-hashes
Require a matching hash for each build requirement.
By default, uv will verify any available hashes in the requirements file, but will not require that all requirements have an associated hash.
When --require-hashes is enabled, all requirements must include a hash or set of hashes, and all requirements must either be pinned to exact versions (e.g., ==1.0.0), or be specified via direct URL.
Hash-checking mode introduces additional constraints:
- Git dependencies are not supported
- Editable installations are not supported
- Local dependencies are not supported, unless they point to a specific wheel (
.whl) or source archive (.zip,.tar.gz), as opposed to a directory
UV_REQUIRE_HASHES
--no-verify-hashes
Disable validation of hashes in the requirements file.
By default, uv will verify any available hashes in the requirements file, but will not require that all requirements have an associated hash. To enforce hash validation, use --require-hashes.
UV_NO_VERIFY_HASHES
Build behavior
--clear
Clear the output directory before the build, removing stale artifacts.
--no-build-logs
Hide logs from the build backend.
--force-pep517
Always build through PEP 517, don’t use the fast path for the uv build backend.
By default, uv won’t create a PEP 517 build environment for packages using the uv build backend, but use a fast path that calls into the build backend directly. This option forces always using PEP 517.
--no-create-gitignore
Do not create a .gitignore file in the output directory.
By default, uv creates a .gitignore file in the output directory to exclude build artifacts from version control. When this flag is used, the file will be omitted.
Python version
-p, --python <PYTHON>
The Python interpreter to use for the build environment.
By default, builds are executed in isolated virtual environments. The discovered interpreter will be used to create those environments, and will be symlinked or copied in depending on the platform.
See uv help python for details on Python discovery and supported request formats.
UV_PYTHON
Examples
Build both sdist and wheel
Build only a wheel
Build only a source distribution
Build with custom output directory
./artifacts instead of the default dist directory.
Build a workspace package
Build all workspace packages
Build from a source distribution
Clear previous builds
Build with specific Python version
Use cases
Preparing for publication
Build distributions before publishing to PyPI:CI/CD pipelines
Build and test distributions in continuous integration:Local testing
Build and install locally for testing:Workspace management
Build specific packages in a monorepo:Related commands
uv publish- Upload distributions to an indexuv pip install- Install packages from built wheelsuv init- Create a new project
Notes
- By default, uv builds both a source distribution and a wheel
- The build process uses PEP 517 build backends
- For packages using the uv build backend, uv uses an optimized fast path unless
--force-pep517is specified - Build artifacts are written to the
distdirectory by default - Use
--clearto ensure clean builds without stale artifacts