How host its own PyPi server?
There are multiple ways to host its own Python packages.
The most used and documented are:
– devpi-server (Python lib)
– pypiserver (Python lib)
– artifactory professional version (Repository manager handing many things)
devpi-server
Description
In fact, devpi consists of multiple modules.
We have the server module, but also the web and the client modules to provide all features needed by the users.
– devpi-server: for serving a pypi.python.org consistent caching index as well as local github-style overlay indexes.
– devpi-web: plugin for devpi-server that provides a web and search interface
– devpi-client: command line tool with sub commands for creating users, using indexes, uploading to and installing from indexes, as well as a « test »
command for invoking tox.
Quickstart: create a user and an index, upload, test, push release
Installing devpi client and server
pip install -U devpi-web devpi-client
initializing a basic server and index, steps:
– start and initialize a background devpi-server at http://localhost:3141
devpi-init
For the next startups of the server, we have to use this command:
devpi-server
– configure the client-side tool devpi to connect to the started server:
devpi use http://localhost:3141
– create and login a user:
devpi user -c testuser password=123
devpi login testuser --password=123
– create an index and use it:
devpi index -c dev bases=root/pypi \
http://localhost:3141/testuser/dev?no_projects=: \
type=stage \
bases=root/pypi \
volatile=True \
acl_upload=testuser \
acl_toxresult_upload=:ANONYMOUS: \
mirror_whitelist= \
mirror_whitelist_inheritance=intersection
– Finally we use the new index:
devpi use testuser/dev
We are now ready to go for uploading and testing packages.
devpi install: installing a package
We can now either use the devpi client to trigger a pip install of a pypi package using the index from our repository:
devpi install pytest
upload a package
devpi way
First, verify we are logged in to the correct index:
devpi use
If it is ok, we can trigger the upload:
devpi upload
command (that may rely on setup.py or pyproject.toml)
We can now check that we are able to download the package from the repository with devpi:
devpi install my-package
twine way
– First we need to define a .pypirc
file where we specify our private repository to upload packages.
By default, the file is expected in the home directory of the user, but if it is desirable, we can specify the file location.
[distutils] index-servers = david-repository [david-repository] repository = http://localhost:3141/testuser/dev username = testuser password = 123 |
– After building the Python package, we can upload the distribution in this way:
twine upload --config-file .pypirc --repository david-repository dist/*
Note: In this example, we specify the location of the .pypirc
file
– We can now check that we are able to download the package from the repository with pip.
You have to specify our private repository to download packages with pip.
You can specify that with the pip command or in the pip.ini file.
The pip.ini file may be created in %HOME%/pip
directory:
[global] timeout = 60 index-url = http://localhost:3141/testuser/dev |
Now you can install the package with pip:
pip install my-package