How to configure PyPI package management using Nexus Repository
Due to restrictive limitations in Nexus 3.81 Community Edition, this version has been discontinued. Once usage reaches the quota limits (100,000 total components and 200,000 requests per day), the instance will cease to function properly.
If you have already upgraded to version 3.81, please follow the Rollback to Nexus 3.76 guide to downgrade.
For more information about Community Edition limitations, see Community Edition Limitations.
TOC
Overview
The Python Package Index, or PyPI, is a vast repository of open-source Python packages supplied by the worldwide community of Python developers. The official index is available at https://pypi.org, and the site itself is maintained by the Python Software Foundation.
Nexus Repository supports proxying the Python Package Index. This takes advantage of the packages in the official Python Package Index without incurring repeated downloads to reduce time and bandwidth usage for accessing Python packages.
Also, you can publish your packages to a private index as a hosted repository, and expose the remote and private repositories as a repository group that merges and exposes the contents of multiple repositories in one convenient URL.
Repository Types Overview
PyPI Proxy - Acts as a proxy to remote PyPI repositories (like https://pypi.org), caching packages locally for faster access and reduced bandwidth usage. When a package is requested, it first checks the local cache, and if not found, downloads from the remote repository and caches it locally.
PyPI Hosted - Stores packages that are uploaded directly to your Nexus instance. This is typically used for private packages, internal libraries, or packages that you want to maintain full control over.
PyPI Group - Combines multiple PyPI repositories (proxy, hosted, or other groups) into a single logical repository. When a package is requested from a group, Nexus searches through the member repositories in a specified order until the package is found. Note: the PyPI Group repository is only used to downloaded PyPI packages, not to deploy PyPI packages.
Typical Architecture
A common setup includes:
- PyPI Hosted - For private/internal packages
- PyPI Proxy - For caching public packages from PyPI.org
- PyPI Group - Combines both hosted and proxy repositories, providing a unified access point
This architecture allows clients to use a single repository URL while accessing both private and public packages seamlessly.
Prerequisites
- Nexus instance has been deployed and you have logged in with admin credentials.
- Python environment is installed locally with pip package manager available.
Create PyPI Proxy Repository
If you want to use PyPI Proxy to cache the PyPI packages, you need to create a PyPI Proxy repository. Note: the nexus instance should be accessible from the internet.
Navigate to the Nexus interface and follow these steps:
- Click
Settings→Repositories→Create repository→PyPI (proxy) - Fill in the configuration details and click
Create repository
Configuration Parameters:
- Name: Enter a repository name, e.g.,
pypi-proxy - Remote storage: Enter the remote repository URL, e.g.,
https://pypi.org - Storage: Select the appropriate storage type based on your requirements
Create PyPI Hosted Repository
If you want to use PyPI Hosted to store the PyPI packages, you need to create a PyPI Hosted repository.
Navigate to the Nexus interface and follow these steps:
- Click
Settings→Repositories→Create repository→PyPI (hosted) - Fill in the configuration details and click
Create repository
Configuration Parameters:
- Name: Enter a repository name, e.g.,
pypi-hosted - Storage: Select the appropriate storage type based on your requirements
- Deployment policy: Choose
Allow redeployorDisable redeploybased on your needs
Create PyPI Group Repository
Navigate to the Nexus interface and follow these steps:
- Click
Settings→Repositories→Create repository→PyPI (group) - Fill in the configuration details and click
Create repository
Configuration Parameters:
- Name: Enter a repository name, e.g.,
pypi-group - Member repositories: Select the previously created
pypi-proxyandpypi-hostedrepositories, m - Order: Configure the search order of repositories based on your requirements
Using Nexus repository with Python client
Before proceeding with the following scenarios, you can obtain the repository URL from the Nexus web interface. Click Browse, select the previously created repository, and click the Copy button to get the repository URL. This URL will be used in the configuration examples below.
Scenario 1: Upload to a hosted repository using twine
This scenario demonstrates how to use the PyPI Hosted repository to deploy and publish your own Python packages to Nexus. This is particularly useful for:
- Private packages: Internal libraries and applications that should not be published to public PyPI
- Custom builds: Modified versions of public packages with your specific configurations
- Proprietary software: Commercial or confidential packages that require controlled distribution
- Development packages: Pre-release versions for internal testing and validation
The process involves building your Python package, configuring the deployment target, and uploading the package to your Nexus PyPI Hosted repository.
After successfully uploading packages to the PyPI Hosted repository, you can view and manage them through the Nexus web interface: Browse → Select PyPI Hosted Repository → Browse Package Contents
Scenario 2: Download and install packages using pip for a PyPI Group repository
This scenario demonstrates how to configure pip to use a PyPI Group repository for managing Python package dependencies. This is particularly useful for:
- Unified package access: Use a single repository URL to access both public packages (via proxy) and private packages (via hosted)
- Performance optimization: Local caching of frequently used packages reduces download times and bandwidth usage
- Centralized management: All package dependencies are managed through a single Nexus instance
- Security control: Centralized authentication and access control for package downloads
The process involves configuring pip to use the PyPI Group repository URL, which automatically searches through member repositories to find and download the required packages.
Configure pip for Anonymous Access
Configure pip for Authenticated Access
If Nexus has disabled anonymous access, you need to add username and password to the pip.conf file:
Configuration Notes
- Special characters in passwords must be URL-encoded (e.g.
@becomes%40) - Consider security implications of storing credentials in plain text
- Always append
/simple/to the repository URL - If Nexus uses an insecure connection or untrusted certificate, configure the
trusted-hostparameter