Defining an Index
To include an additional index when resolving dependencies, add a[[tool.uv.index]] entry to your pyproject.toml:
pyproject.toml
Optional identifier for the index. Must contain only alphanumeric characters, dashes, underscores, and periods (valid ASCII).
The URL of the package index (Simple API endpoint).
Command-Line Usage
Indexes can also be provided via command line or environment variables:Index Priority
Indexes are prioritized in the order they’re defined:- Command-line indexes (highest priority)
- Configuration file indexes (in order of appearance)
- Default index (lowest priority)
Default Index
By default, uv includes PyPI as the “default” index (used when a package is not found on other indexes). To replace PyPI with a different default index:pyproject.toml
Mark this index as the default. The default index is always treated as lowest priority, regardless of position.
Pinning Packages to an Index
Pin a package to a specific index usingtool.uv.sources:
pyproject.toml
torch is always installed from the pytorch index.
Platform-Specific Indexes
Use environment markers to select indexes by platform:pyproject.toml
Explicit Indexes
Mark an index asexplicit = true to prevent packages from being installed from it unless explicitly pinned:
pyproject.toml
When true, packages can only be installed from this index if explicitly pinned via
tool.uv.sources.Named indexes referenced via
tool.uv.sources must be defined within the project’s pyproject.toml. Indexes provided via command-line, environment variables, or user-level configuration will not be recognized.Index Search Strategies
Control how uv searches across multiple indexes using the--index-strategy option or UV_INDEX_STRATEGY environment variable:
first-index (Default)
Search for each package across all indexes, limiting candidate versions to those present in the first index that contains the package.unsafe-first-match
Search across all indexes, but prefer the first index with a compatible version, even if newer versions are available on other indexes.unsafe-best-match
Search across all indexes and select the best version from the combined set of candidate versions (closest to pip’s behavior).Authentication
Most private package indexes require authentication. See the Authentication documentation for detailed information.Credentials via Environment Variables
Provide credentials without storing them in plaintext:pyproject.toml
UV_INDEX_<NORMALIZED_NAME>_USERNAME and UV_INDEX_<NORMALIZED_NAME>_PASSWORD, where <NORMALIZED_NAME> is the uppercase index name with non-alphanumeric characters replaced by underscores.
Credentials in URL
Alternatively, embed credentials directly in the URL:pyproject.toml
Authentication Behavior
Control when uv searches for credentials:Controls credential discovery behavior:
"auto": Attempt unauthenticated request first, search for credentials on failure"always": Always search for credentials before making requests (required for some indexes like GitLab)"never": Never search for credentials (prevents credential leaking)
pyproject.toml
If a username is set, uv will search for credentials before making an unauthenticated request, regardless of the
authenticate setting.Error Handling
Ignored Error Codes
When using thefirst-index strategy, uv stops searching across indexes on HTTP 401 or 403 errors. Customize this behavior:
pyproject.toml
List of HTTP status codes to ignore when searching across indexes. uv will continue to the next index if these codes are encountered.
uv always continues searching on 404 Not Found errors. This cannot be overridden.
Cache Control
Customize caching behavior for an index:pyproject.toml
Override HTTP cache control headers:
api: Controls caching for Simple API requests (package metadata)files: Controls caching for artifact downloads (wheels and source distributions)
- Metadata:
max-age=600(10 minutes) - Artifacts:
max-age=365000000, immutable(indefinite)
pyproject.toml
Flat Indexes
In addition to PyPI-style registries (PEP 503), uv supports “flat” indexes (local directories or HTML pages with flat lists of wheels and source distributions):pyproject.toml
Index format:
"simple": PyPI-style registry (PEP 503 Simple Repository API)"flat": Flat index (equivalent to pip’s--find-links)
explicit = true and pinning via tool.uv.sources.
Legacy pip Compatibility
For compatibility with pip, uv supports--index-url and --extra-index-url:
--index-url→--default-index(sets default index)--extra-index-url→--index(adds additional index)
[[tool.uv.index]] configuration and follow the same prioritization rules.
Examples
Multiple Indexes with Priority
pyproject.toml
Private Registry with Authentication
pyproject.toml
Explicit Index for Specific Packages
pyproject.toml
Related Resources
- Authentication - Index authentication methods
- Alternative Indexes Guide - Provider-specific setup (AWS, Azure, GCP)
- Configuration Files - Configure indexes in pyproject.toml