A private Python package repository is a PyPI-compatible index you control, so pip install, Poetry, and twine upload can use internal packages instead of the public PyPI. The five choices covered here are devpi and pypiserver (self-hosted), AWS CodeArtifact and GCP Artifact Registry (managed), and JFrog Artifactory (self-hosted or cloud). Pick devpi when you need an on-premises index or promotion workflows; pick CodeArtifact or Artifact Registry when you already use that cloud and want managed infrastructure; pick Artifactory when you need one system to hold Python, npm, Docker, and Maven artifacts under a single access model.
The decision tree and comparison below help you choose under real constraints. The dependency-confusion diagram shows why installs can pull the wrong package. Provider CLIs and repository settings change; check the linked vendor documentation and test commands in your environment before using them in production.
Which Private Repository Should You Use? (Decision Tree)
Walk this tree before installing anything. Compare operational needs and current vendor pricing for your expected storage, requests, and network usage.
When You Need Private Repositories
┌─────────────────────────────────────────────────────────────┐
│ Private Repository Use Cases │
├─────────────────────────────────────────────────────────────┤
│ │
│ PROPRIETARY CODE │
│ ├── Internal libraries shared across projects │
│ ├── Company-specific tools and utilities │
│ └── Code you can't publish to public PyPI │
│ │
│ CONTROL & COMPLIANCE │
│ ├── Freeze specific versions for reproducibility │
│ ├── Audit trail for package usage │
│ └── Air-gapped or regulated environments │
│ │
│ RELIABILITY & PERFORMANCE │
│ ├── Cache PyPI packages (survive outages) │
│ ├── Faster installs from local/regional servers │
│ └── Reduce external network dependencies │
│ │
│ SECURITY │
│ ├── Scan packages before allowing use │
│ ├── Prevent dependency confusion attacks │
│ └── Control what packages developers can install │
│ │
└─────────────────────────────────────────────────────────────┘
Solution Comparison
| Feature | devpi | pypiserver | CodeArtifact | Artifact Registry | Artifactory |
|---|---|---|---|---|---|
| Self-hosted | Yes | Yes | No | No | Yes / Cloud |
| PyPI caching (proxy) | Yes | No | Yes | Yes | Yes |
| Multiple indexes / promotion | Yes | No | Yes (repositories, upstreams, package copying) | Yes (repos) | Yes (virtual) |
| Auth model | Users / tokens | htpasswd | AWS IAM | GCP IAM | Users / tokens / SSO |
| Vulnerability scanning | Separate tooling | Separate tooling | Separate tooling | Check service integration | Xray integration (separate add-on) |
| Non-Python formats | No | No | npm, Maven, NuGet | npm, Maven, Docker+ | Many formats |
| Pricing | Open source; hosting costs apply | Open source; hosting costs apply | Check current AWS pricing | Check current Google Cloud pricing | Check current JFrog pricing |
| Setup complexity | Medium | Low | Low | Low | High |
| Ops burden (you patch it) | Yes | Yes | No | No | Yes (self-hosted) / No (cloud) |
| Best for / when to use | On-premises indexes or promotion workflows (dev→staging→prod) | Serving a handful of private wheels without a PyPI proxy | Teams already on AWS wanting IAM auth and no server | Teams on GCP wanting keyring auth and no server | One registry for many artifact types and access controls |
Read the last row first, then check the feature and pricing rows against your requirements. If two options tie, choose the one that fits your existing identity and operations setup. Check each vendor's current pricing page before budgeting.
Self-Hosted: devpi
devpi is the most capable self-hosted solution, offering caching, replication, and multiple indexes.
Installation
# Install devpi server and client
pip install devpi-server devpi-client devpi-web
# Initialize server (creates ~/.devpi/server directory)
devpi-init
# Start server
devpi-server --host 0.0.0.0 --port 3141
Basic Configuration
# Connect client to server
devpi use http://localhost:3141
# Login as root (default password is empty)
devpi login root --password=""
# Change root password
devpi user -m root password="${DEVPI_ADMIN_PASSWORD}"
# Create a user
devpi user -c mycompany password="${DEVPI_USER_PASSWORD}"
# Create an index that inherits from PyPI
devpi login mycompany --password="${DEVPI_USER_PASSWORD}"
devpi index -c dev bases=root/pypi
Index Hierarchy
┌─────────────────────────────────────────────────────────────┐
│ devpi Index Structure │
├─────────────────────────────────────────────────────────────┤
│ │
│ root/pypi (built-in) │
│ └── Mirrors/caches packages from pypi.org │
│ │
│ mycompany/dev │
│ ├── bases=root/pypi (inherits PyPI packages) │
│ └── Upload private packages here │
│ │
│ mycompany/staging │
│ ├── bases=mycompany/dev │
│ └── Promoted packages for testing │
│ │
│ mycompany/prod │
│ ├── bases=mycompany/staging │
│ └── Approved packages for production │
│ │
│ Package lookup: prod → staging → dev → pypi.org │
│ │
└─────────────────────────────────────────────────────────────┘
Uploading Packages
# Select your index
devpi use mycompany/dev
# Upload a package
devpi upload dist/*
# Or use twine
twine upload --repository-url http://localhost:3141/mycompany/dev \
-u mycompany -p userpass dist/*
Configuring pip to Use devpi
# ~/.pip/pip.conf (Linux/macOS) or %APPDATA%\pip\pip.ini (Windows)
[global]
index-url = http://localhost:3141/mycompany/dev/+simple/
trusted-host = localhost
Production Deployment
# Run with nginx reverse proxy
# /etc/nginx/sites-available/devpi
server {
listen 443 ssl;
server_name devpi.company.com;
ssl_certificate /etc/ssl/certs/devpi.crt;
ssl_certificate_key /etc/ssl/private/devpi.key;
location / {
proxy_pass http://localhost:3141;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# Run as systemd service
# /etc/systemd/system/devpi.service
[Unit]
Description=devpi PyPI server
After=network.target
[Service]
User=devpi
ExecStart=/usr/local/bin/devpi-server --host 127.0.0.1 --port 3141
Restart=always
[Install]
WantedBy=multi-user.target
Self-Hosted: pypiserver (Simple)
For basic needs, pypiserver is simpler than devpi.
Quick Setup
# Install
pip install pypiserver
# Create packages directory
mkdir -p /var/pypi/packages
# Run server
pypi-server run -p 8080 /var/pypi/packages
# With authentication
pip install passlib
htpasswd -sc /var/pypi/.htpasswd admin
pypi-server run -p 8080 -P /var/pypi/.htpasswd /var/pypi/packages
Upload Packages
# Configure .pypirc
# ~/.pypirc
[distutils]
index-servers = local
[local]
repository = http://localhost:8080
username = admin
# Upload (Twine prompts for the password)
twine upload --repository local dist/*
AWS CodeArtifact
CodeArtifact is AWS's managed artifact repository.
Setup
# Create domain and repository
aws codeartifact create-domain --domain mycompany
aws codeartifact create-repository \
--domain mycompany \
--repository python-packages
# Connect to PyPI upstream
aws codeartifact associate-external-connection \
--domain mycompany \
--repository python-packages \
--external-connection public:pypi
Authentication
# Get authorization token (expires in 12 hours)
aws codeartifact login --tool pip \
--domain mycompany \
--repository python-packages
# Or get token manually
export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \
--domain mycompany \
--query authorizationToken \
--output text)
Configure pip
# Automatic configuration
aws codeartifact login --tool pip --domain mycompany --repository python-packages
# This creates/updates pip.conf with:
# [global]
# index-url = https://aws:TOKEN@mycompany-123456789.d.codeartifact.us-east-1.amazonaws.com/pypi/python-packages/simple/
Configure Poetry
# Get repository URL
REPO_URL=$(aws codeartifact get-repository-endpoint \
--domain mycompany \
--repository python-packages \
--format pypi \
--query repositoryEndpoint \
--output text)
# Configure Poetry
poetry config repositories.codeartifact $REPO_URL
poetry config http-basic.codeartifact aws $CODEARTIFACT_AUTH_TOKEN
CI/CD Integration (GitHub Actions)
# .github/workflows/publish.yml
name: Publish to CodeArtifact
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write # For OIDC
contents: read
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789:role/github-actions
aws-region: us-east-1
- name: Login to CodeArtifact
run: |
aws codeartifact login --tool pip \
--domain mycompany \
--repository python-packages
aws codeartifact login --tool twine \
--domain mycompany \
--repository python-packages
- name: Build and publish
run: |
pip install build twine
python -m build
twine upload --repository codeartifact dist/*
Google Cloud Artifact Registry
GCP's Artifact Registry supports Python packages.
Setup
# Enable API
gcloud services enable artifactregistry.googleapis.com
# Create repository
gcloud artifacts repositories create python-packages \
--repository-format=python \
--location=us-central1 \
--description="Private Python packages"
# Create a remote repository to cache packages from PyPI
gcloud artifacts repositories create pypi-remote \
--repository-format=python \
--mode=remote-repository \
--remote-python-repo=PYPI \
--location=us-central1
For one install URL that can serve private packages and cached PyPI packages, create a virtual repository with both repositories as upstreams. The example gives the private repository higher priority when both upstreams contain the requested version. See Google's virtual repository setup for the upstream policy file and access requirements.
[
{
"id": "private",
"repository": "projects/myproject/locations/us-central1/repositories/python-packages",
"priority": 100
},
{
"id": "pypi",
"repository": "projects/myproject/locations/us-central1/repositories/pypi-remote",
"priority": 10
}
]
Save this example as upstreams.json, then create the virtual repository:
gcloud artifacts repositories create python-virtual \
--repository-format=python \
--mode=virtual-repository \
--upstream-policy-file=upstreams.json \
--location=us-central1
Before installing through python-virtual, grant the Artifact Registry service agent the Artifact Registry Reader role on both upstream repositories, python-packages and pypi-remote, unless it already has equivalent access; see Google's virtual repository setup.
Authentication
# Configure pip authentication
gcloud artifacts print-settings python \
--project=myproject \
--repository=python-virtual \
--location=us-central1
# Output shows pip.conf settings
Configure pip
Publish private packages to the standard python-packages repository. The python-virtual repository above gives pip one install URL for those packages and packages fetched through pypi-remote. Google recommends a virtual index because pip does not prioritize extra-index-url sources.
Priority alone does not make unpinned installs private-first: for an unpinned package, Artifact Registry may return the latest version even if it comes from the lower-priority PyPI upstream. A higher public version of an internal package can still be selected. Pin approved versions (and hashes for reproducible installs). When internal packages require exclusive private resolution, install them from the standard private repository instead of this mixed virtual endpoint. See Google's virtual repository selection rules.
# pip.conf
[global]
index-url = https://us-central1-python.pkg.dev/myproject/python-virtual/simple/
# Use keyring for authentication
pip install keyring keyrings.google-artifactregistry-auth
# Keyring handles authentication automatically
pip install my-private-package
Publishing
# Configure twine
# ~/.pypirc
[distutils]
index-servers = artifact-registry
[artifact-registry]
repository = https://us-central1-python.pkg.dev/myproject/python-packages/
# Upload (keyring handles auth)
twine upload --repository artifact-registry dist/*
JFrog Artifactory
Artifactory is an enterprise solution with extensive features.
Creating a Python Repository
The REST examples use credentials from a protected .netrc entry for artifactory.company.com.
# Via REST API
curl -X PUT "https://artifactory.company.com/artifactory/api/repositories/python-local" \
-H "Content-Type: application/json" \
--netrc \
-d '{
"key": "python-local",
"rclass": "local",
"packageType": "pypi"
}'
# Create remote repository (PyPI proxy)
curl -X PUT "https://artifactory.company.com/artifactory/api/repositories/python-remote" \
-H "Content-Type: application/json" \
--netrc \
-d '{
"key": "python-remote",
"rclass": "remote",
"packageType": "pypi",
"url": "https://pypi.org"
}'
# Create virtual repository (combines local and remote)
curl -X PUT "https://artifactory.company.com/artifactory/api/repositories/python-virtual" \
-H "Content-Type: application/json" \
--netrc \
-d '{
"key": "python-virtual",
"rclass": "virtual",
"packageType": "pypi",
"repositories": ["python-local", "python-remote"]
}'
Configure pip
# pip.conf
[global]
index-url = https://artifactory.company.com/artifactory/api/pypi/python-virtual/simple
Authentication Options
Artifactory's PyPI repository documentation gives the basic-auth URL shape https://<USER>:<PASSWORD>@artifactory.company.com/artifactory/api/pypi/python-virtual/simple and the token URL shape https://<USER>:<ACCESS_TOKEN>@artifactory.company.com/artifactory/api/pypi/python-virtual/simple. Use these as URL templates, not literal credentials in a committed pip.conf or shell history. Supply the password or token through a credential helper, .netrc, or a CI secret store; URL-encode special characters if you must place credentials in a URL. The same /api/pypi/<repository>/simple path works without embedded credentials when your client obtains them separately:
pip install --index-url https://artifactory.company.com/artifactory/api/pypi/python-virtual/simple mypackage
Publishing to Artifactory
# ~/.pypirc
[distutils]
index-servers = artifactory
[artifactory]
repository = https://artifactory.company.com/artifactory/api/pypi/python-local
username = deployer
The corresponding upload URL with basic auth is https://<USER>:<PASSWORD>@artifactory.company.com/artifactory/api/pypi/python-local; an access token can occupy the password field as https://<USER>:<ACCESS_TOKEN>@artifactory.company.com/artifactory/api/pypi/python-local. Keep the URL in .pypirc free of secrets as shown, and supply the upload credential through a keyring or secret store before running Twine.
twine upload --repository artifactory dist/*
GitHub Packages
GitHub Packages has no native PyPI (simple) registry — unlike npm, Maven, or NuGet, there is no first-class Python feed you can point pip index-url at. Teams can attach wheels to releases or use GitHub Actions as the build and publish runner for PyPI or another Python index. The workflow below publishes to PyPI using Trusted Publishing; configure the matching publisher on PyPI before running it.
Publishing
# Use GitHub Actions to publish to a Python package index
# .github/workflows/publish.yml
name: Publish Python Package
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Build package
run: |
pip install build
python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Configuring Tools
pip Configuration
# ~/.config/pip/pip.conf (per-user on Linux)
# or $VIRTUAL_ENV/pip.conf (per-virtual-environment on Linux/macOS)
[global]
# Use a private index that serves approved public dependencies as well as internal packages.
index-url = https://private.company.com/simple/
For deployments that use hash checking, run pip install --require-hashes -r requirements.txt with a requirements file that pins every package and transitive dependency and supplies an approved hash for each distribution you install. Pip's secure installs guide explains the full-file requirement. Keep hash checking out of the general pip configuration if you also use the unpinned install examples in this guide.
Poetry Configuration
# pyproject.toml
[[tool.poetry.source]]
name = "private"
url = "https://private.company.com/simple/"
priority = "primary"
[[tool.poetry.source]]
name = "PyPI"
priority = "supplemental"
# Configure authentication
poetry config http-basic.private username
# Or supply credentials through environment variables from a secret store
export POETRY_HTTP_BASIC_PRIVATE_USERNAME=user
export POETRY_HTTP_BASIC_PRIVATE_PASSWORD="${PRIVATE_REPO_PASSWORD}"
pip-tools Configuration
# Use custom index in requirements.in
--index-url https://private.company.com/simple/
django>=4.0
my-private-package>=1.0
# Compile with custom index
pip-compile --index-url https://private.company.com/simple/ requirements.in
Security Best Practices
1. Use HTTPS for Networked Repositories
# Avoid HTTP for networked package repositories
# BAD
index-url = http://internal-pypi.company.com/simple/
# GOOD
index-url = https://internal-pypi.company.com/simple/
2. Credential Management
# Keep the index URL free of embedded credentials
export PIP_INDEX_URL=https://private.company.com/simple/
# Use .netrc for local development
# ~/.netrc
machine private.company.com
login username
password token
# Keep credentials out of source control
# .gitignore
.netrc
.pypirc
pip.conf
3. Namespace Private Packages
The reason this matters: with --extra-index-url, pip has no index priority; it evaluates candidates from all configured indexes. If your internal package utils is at 1.4.0 privately and an attacker publishes a compatible utils 99.0.0 to public PyPI, pip can pick the attacker's build. This is the dependency-confusion attack.
Resolve internal names from an authoritative private index that does not fall through to PyPI for those names. If public dependencies are also needed, configure a server-side upstream with explicit policy, rather than adding PyPI as a second pip index. Pin package versions and hashes so an unexpected artifact fails the install. A company prefix such as acme-utils helps naming consistency but does not reserve the name on public PyPI.
# Use a recognizable prefix for private packages; this does not reserve names on PyPI
# setup.py / pyproject.toml
name = "acme-internal-utils" # Not just "utils"
name = "acme-auth-client" # Not just "auth-client"
4. Package Signing
# Sign packages with GPG
gpg --detach-sign -a dist/mypackage-1.0.0.tar.gz
# Upload signature with package
twine upload dist/mypackage-1.0.0.tar.gz dist/mypackage-1.0.0.tar.gz.asc
CI/CD Integration Patterns
GitLab CI
GitLab forwards requests for packages missing from its PyPI registry to pypi.org by default, even when PIP_INDEX_URL points at GitLab. To keep missing private package names from resolving publicly, turn off Forward PyPI package requests in the group's Settings > Packages and registries > Package forwarding before using this example. The group Owner can change that setting. With forwarding disabled, build, twine, their dependencies, and the package's build dependencies must be available in the GitLab registry (or installed separately from an approved source before setting PIP_INDEX_URL).
# .gitlab-ci.yml
variables:
PIP_INDEX_URL: https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/api/v4/projects/${CI_PROJECT_ID}/packages/pypi/simple
publish:
stage: deploy
script:
- pip install build twine
- python -m build
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token
twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
only:
- tags
Jenkins
// Jenkinsfile
pipeline {
agent any
environment {
PYPI_CREDS = credentials('private-pypi')
}
stages {
stage('Build') {
steps {
sh '''
pip install build
python -m build
'''
}
}
stage('Publish') {
when {
tag pattern: "v\\d+\\.\\d+\\.\\d+", comparator: "REGEXP"
}
steps {
sh '''
pip install twine
twine upload --repository-url https://pypi.company.com \
-u $PYPI_CREDS_USR -p $PYPI_CREDS_PSW dist/*
'''
}
}
}
}
Azure DevOps
# azure-pipelines.yml
trigger:
tags:
include:
- v*
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
- script: |
pip install build twine
python -m build
displayName: 'Build package'
- task: TwineAuthenticate@1
inputs:
artifactFeed: 'MyFeed'
- script: |
twine upload -r MyFeed --config-file $(PYPIRC_PATH) dist/*
displayName: 'Publish to Azure Artifacts'
Troubleshooting
Package Not Found
# Check if package exists in private repo
pip index versions my-package --index-url https://private.company.com/simple/
# Try with verbose output
pip install my-package -vvv --index-url https://private.company.com/simple/
Authentication Failures
# Test credentials
curl --netrc https://private.company.com/simple/
# Check pip is using correct config
pip config list
# Clear pip cache
pip cache purge
SSL/Certificate Issues
# For a private CA, use its PEM-encoded CA bundle
pip install --cert /path/to/ca-bundle.crt my-package
# Or configure globally
# pip.conf
[global]
cert = /path/to/ca-bundle.crt
Next Steps
- Learn about package publishing in our PyPI Publishing Guide
- Explore dependency management in our Dependency Management Tools Guide
- See the complete ecosystem in our Python Packaging Complete Guide
For more Python development guides, explore our complete Python packaging series.