Authentication Sources
Credentials are retrieved from the following sources, in order of precedence:- URL credentials - Embedded in the URL (e.g.,
https://user:[email protected]) - netrc files - Standard
.netrcconfiguration - uv credentials store - Managed via
uv authcommands - Keyring providers - External keyring integration (opt-in)
The uv auth CLI
uv provides a high-level interface for managing credentials.
Logging In
Add credentials for a service:Viewing Credentials
Show stored credentials for a URL:Logging Out
Remove credentials from local storage:Credentials are only removed locally, not invalidated on the remote server.
uv Credentials Store
The uv credentials store persists credentials in a plaintext file located in uv’s state directory:Native Auth Storage (Preview)
A secure, system-native storage mechanism is available as a preview feature:- macOS: Keychain Services
- Windows: Windows Credential Manager
- Linux: DBus-based Secret Service API
Currently, uv only retrieves credentials it has added to the native store. It will not retrieve credentials persisted by other applications.
netrc Files
.netrc files are a standard plaintext format for storing credentials.
Configuration
Create a.netrc file in your home directory:
~/.netrc
The hostname of the server.
The username for authentication.
The password or token for authentication.
Custom netrc Location
Use theNETRC environment variable to specify a custom location:
Reading credentials from
.netrc files is always enabled. If NETRC is not defined, uv falls back to ~/.netrc.Keyring Providers
Keyring providers allow credential retrieval from external tools compatible with Python’s keyring package.Subprocess Provider
The “subprocess” provider invokes thekeyring command-line tool:
pyproject.toml
Keyring provider to use:
"disabled": No keyring (default)"subprocess": InvokekeyringCLI
Authentication Context
Authentication applies to hosts specified in:[[tool.uv.index]]- Custom package indexes--index-url/--extra-index-url- Command-line index URLs--find-links- Flat index locationspackage @ https://...- Direct URL dependencies
Index Authentication
Environment Variable Credentials
Provide credentials for named indexes via environment variables:pyproject.toml
- Pattern:
UV_INDEX_<NORMALIZED_NAME>_USERNAMEandUV_INDEX_<NORMALIZED_NAME>_PASSWORD <NORMALIZED_NAME>: Uppercase index name with non-alphanumeric characters replaced by underscores
| Index Name | Username Variable | Password Variable |
|---|---|---|
internal-proxy | UV_INDEX_INTERNAL_PROXY_USERNAME | UV_INDEX_INTERNAL_PROXY_PASSWORD |
my.registry | UV_INDEX_MY_REGISTRY_USERNAME | UV_INDEX_MY_REGISTRY_PASSWORD |
azure_artifacts | UV_INDEX_AZURE_ARTIFACTS_USERNAME | UV_INDEX_AZURE_ARTIFACTS_PASSWORD |
URL-Embedded Credentials
Embed credentials directly in the index URL:pyproject.toml
Authentication Behavior
Control credential discovery behavior per index:pyproject.toml
Controls when uv searches for credentials:
"auto": Attempt unauthenticated request first; search for credentials on failure"always": Eagerly search for credentials before making requests; error if not found"never": Never search for credentials; error if credentials are provided directly
"always" when:
- The index forwards unauthenticated requests to public indexes (like GitLab)
- You want to fail fast if credentials are missing
"never" when:
- You want to prevent credential leaking
- The index should never use authentication
If a username is set (in URL or environment variable), uv searches for credentials before attempting an unauthenticated request, regardless of the
authenticate setting.Credential Persistence
Request-Level Caching
If authentication is found for an index URL or net location (scheme, host, port), it’s cached for the duration of the command and reused for other queries to that location. Credentials are not cached across invocations of uv.In Project Files
When usinguv add, uv will not persist index credentials to pyproject.toml or uv.lock (files often included in source control).
Exception: uv will persist credentials for direct URL dependencies:
pyproject.toml
Authentication Examples
Private PyPI Mirror with netrc
~/.netrc
pyproject.toml
Azure Artifacts with Environment Variables
pyproject.toml
Google Artifact Registry with Keyring
pyproject.toml
AWS CodeArtifact with Token
pyproject.toml
Using uv auth for Multiple Indexes
pyproject.toml
TLS Certificates
For custom TLS certificate configuration, see the TLS Certificates documentation.Third-Party Services
For provider-specific authentication guides:Related Resources
- Indexes - Configure custom package indexes
- Environment Variables - All UV_* variables reference
- Alternative Indexes Guide - Provider-specific setup