In this lesson, you will learn how to configure your build workflow to distribute proprietary packages to internal registries like Artifactory or DevPi instead of the public PyPI.
When working in an organizational setting, you often need to share code that contains sensitive business logic or internal dependencies that should never be made public. While tools like twine are used for public distribution, the workflow for private registries is nearly identical, with one key difference: the repository-url.
Configuring the Repository Target
To upload to an internal registry, you must point your upload tool to the specific URL provided by your infrastructure team. If you are using twine, you don't need to change your pyproject.toml or your build process (which generates your dist/ directory). Instead, you direct the upload command to the internal endpoint.
You can run the following command in your terminal to push your built artifacts to your private server:
twine upload --repository-url https://artifactory.yourcompany.com/artifactory/api/pypi/pypi-local/ dist/*
Handling Authentication
Private registries typically require authentication. Rather than typing your credentials into the terminal every time, you should configure your local environment to handle this securely. Most developers use the ~/.pypirc file to map repository URLs to specific usernames and passwords:
[distutils]
index-servers =
internal-repo
[internal-repo]
repository: https://artifactory.yourcompany.com/artifactory/api/pypi/pypi-local/
username: your_username
password: your_password
Once configured, you can simply run:
twine upload -r internal-repo dist/*
Why this matters
By decoupling your build process (creating wheels and source distributions) from your distribution target (the registry URL), you maintain a consistent workflow. Your CI/CD pipelines can be configured to toggle between PyPI and internal registries by simply overriding the --repository-url or -r flag based on the deployment environment. This ensures that internal packages remain secure and accessible only to authorized team members within your private network.
Key Takeaway: Distributing to private registries requires directing your upload tool to an internal URL and managing credentials via .pypirc or environment variables, keeping your build process identical to public distribution.