In cases of total internet shutdown a local PyPI cache can be used.

There are many tools that support this functionality, the one that I found most useful according to my use case is devpi, which can be configured in a way so that it only caches software packages that I requested by running pip install or uv add commands, it also caches dependencies of those packages.

It is capable of much more: full mirroring, updates, user accounts, etc.

Quick Setup

Install devpi through something like pip or uv:

uv tool install devpi-server

Initialize server directory, the default is: .devpi/server:

devpi-init

Create a user systemd service file that executes devpi-server. You can also configure devpi-server through command-line options.

[Unit]
Description=Devpi Server (Local PyPI Cache)
After=network.target

[Service]
Type=simple
ExecStart=/home/user/.local/bin/devpi-server --threads 4
Restart=always
RestartSec=3

[Install]
WantedBy=default.target

Enable and start the service, check for service status and ensure successful start, finnaly tell pip or uv to use the devpi index instead of PyPI:

pip install -i http://localhost:3141/root/pypi/+simple/
uv add --default-index http://localhost:3141/root/pypi/+simple/

You can also add these to your .profile file for global effect:

export PIP_INDEX_URL=http://localhost:3141/root/pypi/+simple/
export UV_DEFAULT_INDEX=http://localhost:3141/root/pypi/+simple/