Creating your first private package in PyPRI
First steps with PyPRI — cloud hosted Python package repository


PyPRI is a cloud based package manager that allows you to host your own private cloud repository for Python packages. In this tutorial, we will learn how to:
- Create your own private package repository in PyPRI
- Create a basic hello world app
- Push your app to your repository
- Share your app with other users
- Install your app from your repository via PIP
Creating your private python package repository
To create your private repository, simply sign up for n account at PyPRI by clicking on the Register button:


Enter an email address and choose a password to continue


You will be asked to verify your email address — enter the code emailed to you to do this


Once your account is verified, you can sign into your account. Your package list will be empty at first.


Your private cloud has now been created — to see the URL, click on the blue button at the bottom of the screen, shown above. This will give you the commands required to install packages using Twine.


We will use these commands to upload our packages later
Create a hello world app
In this section, we’ll use setuptools to create a basic hello world app, packaged ready to be pushed to our repository. Start by creating the following folder structure.
/mydir
/hello
__init__.py
setup.py
in /mydir/setup.py, add the following lines
from setuptools import setup
setup(
name='helloworld',
version='0.0.1',
description='Test',
author='Me',
author_email='me@example.com',
license='MIT',
packages=['hello'],
zip_safe=False
)
And in mydir/hello/__init__.py, add the following lines:
def hello():
return 'Hello, world!'
Our app is now ready to be packaged. To create a package, open a terminal window in your /mydir location, and run the following command
python setup.py sdist
This will add the following folder and file to your structure
/mydir
/dist
helloworld-0.0.1.tar.gz
/hello
__init__.py
setup.py
The file helloworld-0.0.1.tar.gz is our created package, which we will upload to our PyPRI repository at the next step
Push your package to your repository
Now that we have our package, we can upload it to our PyPRI repository using the commands displayed in the PyPRI package homepage. Remember to replace the package index url shown below with your own URL
# cd into the folder containing the package
$ cd dist
# install twine, if you haven't already
$ pip install twine
...
Successfully installed certifi-2018.4.16 chardet-3.0.4 idna-2.6 pkginfo-1.4.2 requests-2.18.4 requests-toolbelt-0.8.0 tqdm-4.23.4 twine-1.11.0 urllib3-1.22
# upload the package using twine. You will be prompted for credentials
$ twine upload --repository-url https://api.python-private-package-index.com/w8sKlc3L/ *
Enter your username: info@python-private-package-index.com
Enter your password:
Uploading helloworld-0.0.1.tar.gz
Your package has now been pushed to your PyPRI repository!
Sharing your package with other users
If you go back into PyPRI, you should see your newly created package in your index


To share your package with other users, you must first register those users with your account. You can create up to 100 additional users with each account (this is limited to 5 accounts during the trial period). To create additional users, click the yellow button (6 days of trial period remaining). If you already have a paid account, this link will say My account. Use the users section at the bottom of this view to create new users


Each new user you add will receive an email with a signup URL asking them to set their password. Once they have done this, they will be able to access any packages shared with them, and also create their own packages.
As the admin user, you have access to all packages created by your additional users
To share a package with a user, go back to your packages list and open the package, then click on the Access tab


Select the sub user from the drop down list and click Add to give the user access to the package. Selecting the Write access checkbox will allow that user to create new versions of your package using twine. Otherwise, the user will only have read only access, meaning that the user can install that package via pip.
Installing your package with pip
Clicking on the Installation tab for your package will show you the command required to install your


Enter the above command in a terminal window to install your package
pip install helloworld -i https://api.python-private-package-index.com/w8sKlc3L/
Once again, you will be asked for credentials. You can either enter your own credentials, or those of any user with access to install the package.
Using a pip.conf file
Rather than having to type the extra index url and your credentials every time, you can create a pip configuration file to save this for you. On MacOSX, your config file should exist at ~/.config/pip/pip.conf — to add your credentials and repository url, add the following to this file, replacing the email, password and url with your own
[global]extra-index-url =https://info%40python-private-package-index.com:mypassword@api.python-private-package-index.com/w8sKlc3L/
Note that we have used %40, instead of @ in this url.
You can now install your packages with the following line
pip install helloworld