Pushing your first Python package to Packagr
Your private Python repository URL
When you sign up for Packagr, you'll get access to a Python repository URL:
- All premium users will get their own private repository URL, which is unique for their organization and acts as a private version and allows full access control over all Python packages
- All free users gain access to the public URL, https://api.packagr.app/public
For the purposes of this document, we'll assume that you have a private URL. However, if you're using a free account, you'll be able to use the public URL in much the same way.
You'll be able to retrieve your repository URL by clicking on Create a new Package. Your URL will contain a unique hash ID in the following format.
Packaging your Python code
The first step to pushing your Python packages to Packagr is to create a package from your code. Packagr
is fully compatible with
twine and is intended to work in much the same way as the public PyPI repository.
If you don't already have a Python package, you can follow the below simple tutorial to create a simple Hello World app.
Structuring your code
Let's start with a very simple setup like this:
/my-project /package hello.py /bin say-hello setup.py
hello.py file, add the following code:
def hello(): print('Hello, world!')
say-hello, we'll create a simple script that calls our command:
#!/usr/bin/env python from package import hello hello.hello()
And finally, we'll create a simple
setup.py configuration that tells setuptools how to create our Package:
from setuptools import setup setup( name='hello', version='1.0', packages=['package'], author='chris', email@example.com', description='say hello', scripts=['bin/say-hello'] )
Building the package
Now that we have our code, we'll need to install some dependencies
pip install wheel twine
Next, we can create our package. Note that in this case, we are creating a package in both
python setup.py sdist bdist_wheel
This will create a folder called
dist, which contains our built files. We can test our package quickly by installing it locally:
pip install dist/* say-hello -> Hello, World!
Pushing the code to Packagr
We can now push this package to Packagr. We'll need the repository URL we made a note of earlier for this - you'll need to update the URL in the below command:
twine upload --repository-url https://api.packagr.app/my-hash-id/ dist/*
You'll be prompted to enter your credentials before the upload starts. If all goes well, you'll get a success message. You'll also be able to see the package listed in your dashboard:
Now that you've seen the basic process for uploading files to Packagr, you may be interested in further reading on how to integrate Packagr with your existing workflows:
- Continuous Integration/Continous Deployment
- Authentication in Packagr
- Working with Poetry