|
| 1 | +# HTTP credentials |
| 2 | + |
| 3 | +uv supports credentials over HTTP when querying package registries. |
| 4 | + |
| 5 | +Authentication can come from the following sources, in order of precedence: |
| 6 | + |
| 7 | +- The URL, e.g., `https://<user>:<password>@<hostname>/...` |
| 8 | +- A [netrc](#netrc-files) configuration file |
| 9 | +- The uv credentials store |
| 10 | +- A [keyring provider](#keyring-providers) (off by default) |
| 11 | + |
| 12 | +Authentication may be used for hosts specified in the following contexts: |
| 13 | + |
| 14 | +- `[index]` |
| 15 | +- `index-url` |
| 16 | +- `extra-index-url` |
| 17 | +- `find-links` |
| 18 | +- `package @ https://...` |
| 19 | + |
| 20 | +## netrc files |
| 21 | + |
| 22 | +[`.netrc`](https://everything.curl.dev/usingcurl/netrc) files are a long-standing plain text format |
| 23 | +for storing credentials on a system. |
| 24 | + |
| 25 | +Reading credentials from `.netrc` files is always enabled. The target file path will be loaded from |
| 26 | +the `NETRC` environment variable if defined, falling back to `~/.netrc` if not. |
| 27 | + |
| 28 | +## The uv credentials store |
| 29 | + |
| 30 | +uv can read and write credentials from a store using the [`uv auth` commands](./cli.md). |
| 31 | + |
| 32 | +Credentials are stored in a plaintext file in uv's state directory, e.g., |
| 33 | +`~/.local/share/uv/credentials/credentials.toml` on Unix. This file is currently not intended to be |
| 34 | +edited manually. |
| 35 | + |
| 36 | +!!! note |
| 37 | + |
| 38 | + A secure, system native storage mechanism is in [preview](../preview.md) — it is still |
| 39 | + experimental and being actively developed. In the future, this will become the default storage |
| 40 | + mechanism. |
| 41 | + |
| 42 | + When enabled, uv will use the secret storage mechanism native to your operating system. On |
| 43 | + macOS, it uses the Keychain Services. On Windows, it uses the Windows Credential Manager. On |
| 44 | + Linux, it uses the DBus-based Secret Service API. |
| 45 | + |
| 46 | + Currently, uv only searches the native store for credentials it has added to the secret store — |
| 47 | + it will not retrieve credentials persisted by other applications. |
| 48 | + |
| 49 | + Set `UV_PREVIEW_FEATURES=native-auth` to use this storage mechanism. |
| 50 | + |
| 51 | +## Keyring providers |
| 52 | + |
| 53 | +A keyring provider is a concept from `pip` allowing retrieval of credentials from an interface |
| 54 | +matching the popular [keyring](https://github.com/jaraco/keyring) Python package. |
| 55 | + |
| 56 | +The "subprocess" keyring provider invokes the `keyring` command to fetch credentials. uv does not |
| 57 | +support additional keyring provider types at this time. |
| 58 | + |
| 59 | +Set `--keyring-provider subprocess`, `UV_KEYRING_PROVIDER=subprocess`, or |
| 60 | +`tool.uv.keyring-provider = "subprocess"` to use the provider. |
| 61 | + |
| 62 | +## Persistence of credentials |
| 63 | + |
| 64 | +If authentication is found for a single index URL or net location (scheme, host, and port), it will |
| 65 | +be cached for the duration of the command and used for other queries to that index or net location. |
| 66 | +Authentication is not cached across invocations of uv. |
| 67 | + |
| 68 | +When using `uv add`, uv _will not_ persist index credentials to the `pyproject.toml` or `uv.lock`. |
| 69 | +These files are often included in source control and distributions, so it is generally unsafe to |
| 70 | +include credentials in them. However, uv _will_ persist credentials for direct URLs, i.e., |
| 71 | +`package @ https://username:password:example.com/foo.whl`, as there is not currently a way to |
| 72 | +otherwise provide those credentials. |
| 73 | + |
| 74 | +If credentials were attached to an index URL during `uv add`, uv may fail to fetch dependencies from |
| 75 | +indexes which require authentication on subsequent operations. See the |
| 76 | +[index authentication documentation](../indexes.md#authentication) for details on persistent |
| 77 | +authentication for indexes. |
| 78 | + |
| 79 | +## Learn more |
| 80 | + |
| 81 | +See the [index authentication documentation](../indexes.md#authentication) for details on |
| 82 | +authenticating index URLs. |
| 83 | + |
| 84 | +See the [`pip` compatibility guide](../../pip/compatibility.md#registry-authentication) for details |
| 85 | +on differences from `pip`. |
0 commit comments