Most Hatch environment types, like the default virtual, simply use pip to install dependencies. Therefore, you can use the standard environment variables that influence pip
's behavior.
Here's an example of setting up the default environment to look at 2 private indices (using context formatting for authentication) before finally falling back to PyPI:
[tool.hatch.envs.default.env-vars]
PIP_INDEX_URL = "https://token:{env:GITLAB_API_TOKEN}@gitlab.com/api/v4/groups/<group1_path>/-/packages/pypi/simple/"
PIP_EXTRA_INDEX_URL = "https://token:{env:GITLAB_API_TOKEN}@gitlab.com/api/v4/groups/<group2_path>/-/packages/pypi/simple/ https://pypi.org/simple/"
Note that Hatch's internal environments, such as the hatch-test
matrix used by the test
command,
now use uv
. Therefore if you wish change their dependency
resolution behaviour, you will need to also set the corresponding
environment variables, as described below.
If you're using UV, a different set of environment variables are available to configure its behavior. The previous example would look like this instead:
[tool.hatch.envs.default.env-vars]
UV_EXTRA_INDEX_URL = "https://token:{env:GITLAB_API_TOKEN}@gitlab.com/api/v4/groups/<group1_path>/-/packages/pypi/simple/"
UV_INDEX_URL = "https://token:{env:GITLAB_API_TOKEN}@gitlab.com/api/v4/groups/<group2_path>/-/packages/pypi/simple/ https://pypi.org/simple/"
!!! tip
If you need precise control over the prioritization of package indices, then using UV is recommended because pip
has no index order guarantee.