What is devpi server?
Devpi is a server and software package for managing Python packages and their development and deployment. It provides an environment for developers to share and distribute their packages, as well as a central repository for keeping track of versions and dependencies. Devpi provides an easy-to-use web interface, a set of command-line tools, and an API for interacting with the server.
Where to use devpi?
Whenever you are working as a team where each member creates an app that can be used in another team member's application. In a real-world scenario, you can't share code. You need a central repository where your builds are present and whoever wants to utilize it can just install it by providing just the package name and version (optional). In such scenario you should use devpi server.
Example
Le's take an example of the below students and teachers project structure. Will install both project applications as a package via devpi.
students | teachers |
students/__init__.py | teachers/__init__.py |
students/models/__init__.py | teachers/models/__init__.py |
students/models/student.py | teachers/models/teacher.py |
students/services/__init__.py | teachers/services/__init__.py |
students/services/service.py | teachers/services/service.py |
students/controllers/__init__.py | teachers/controllers/__init__.py |
students/controllers/attendance_controller.py | teachers/controllers/subject_controller.py |
students/constants/__init__.py | teachers/constants/__init__.py |
students/configuration/env.ini | teachers/configuration/env.ini |
requirements.txt | requirements.txt |
setup.py | setup.py |
Devpi setup
install devpi server
pip install devpi-server
start devpi server. It will start on 3141 port
devpi-server --start --init
You can provide --host=0.0.0.0 If you want to access devpi from any server within your network.
install devpi client to connect to devpi server
pip install devpi-client
Now create user and index(where packages will get uploaded) on devpi server
devpi use http://localhost:3141 # change localhost to ip if you have provided --host=0.0.0.0 in above devpi server start command
devpi user -c central_repo # it will ask to enter the password
devpi login central_repo --password="<above entered password>"
devpi index -c dev bases=root/pypi
devpi use dev
You can create an index name as an environment name.
Now go to your students path project and upload it to dev index using the following command
devpi upload --no-vcs
You will receive the below message
file_upload of students-0.1.tar.gz to http://localhost:3141/central_repo/dev/
Now go to teachers project path and make an entry of students==0.1 in requirements.txt
while installing packages from requirements.txt use the following command
pip install -i http://localhost:3141/central_repo/dev -r requirements.txt
students package will get installed successfully in your teachers project. Now you can start utilizing it.
Conclusion
Using devpi server you can manage your custom python modules or packages as a central repository. From devpi client you can install python packages wherever necessary.