As an alternative to a Curated PyPI repository, which requires online access to packages, a Local Python source can serve packages while disconnected from the public internet. This allows for use in air-gapped environments until a Python Offline Downloader for air-gapped PyPI packages is available in Package Manager. This script demonstrates how to download package distributions from PyPI and upload them to Posit Package Manager locally.
- A working version of Python
- Twine installed in Python
pip install twine
- Access to a Posit Package Manager server with a local Python source created
rspm create source --type=local-python --name=python rspm create repo --type=python --name=python rspm subscribe --repo=python --source=python
- An API Token for your Posit Package Manager server with permissions to upload to the local Python source
rspm create token --sources=python --description="Upload packages to Python source"
Download the script add-pypi-package.sh locally and set the following environment variables to refer to your Posit Package Manager instance:
Environment Variable | Description | Default |
---|---|---|
PACKAGEMANAGER_SOURCE | A Package Manager local-python source to add packages |
python |
PACKAGEMANAGER_ADDRESS | URL to Package Manager | http://localhost:4242 |
PACKAGEMANAGER_TOKEN | API token generated by rspm create token with access to the local Python source |
|
TEMPDIR | Temporary base directory to download packages | $TMPDIR, if set or /tmp |
KEEP_PACKAGES | If "false", delete the temporary packages once uploaded to Package Manager | false |
./add-pypi-package.sh package [version]
Specify a version number to download a specific version of the package. If version is omitted, will download the latest version available from PyPI.