Using the Packagr CLI

Introducing the new command line interface for Packagr — making Python package management even easier than before!

In this latest post, we’ll be looking at the brand new Packager CLI, which aims to give you the ability to manage your Packagr account programatically.

Why does Packagr need a CLI?

Ultimately Packagr relies heavily on two existing command-based tools to operate — pip and twine. However, one of the recurring bits of feedback we receive about Packagr is that manually typing the additional command line arguments that these tools need to work with Packagr quickly becomes tiresome. It’s possible to remove the need to type your credentials with every single command by editing your pip.conf file, but given that most developers spend a lot of time switching between various virtualenvs, its still a problematic solution.

Another common problem that we see is queries about why developer’s packages haven’t uploaded to Packagr due to a 409 error — unfortunately, due to the very non-verbose nature of twine's output, Packagr is limited in terms of the feedback it is able to provide the user

What the new CLI seeks to achieve is to abstract away the additional complexity that Packagr adds to pip in a way that can be easily be replicated across multiple development environments, while doing away with twine altogether. Add to that the ability to perform some of Packagr’s other functionality programatically, such as access token creation and making packages public/private, and we think the CLI could be something of a game-changer in the way that Packagr can manage your Python ecosystem

Getting started

Packagr-CLI is still in beta — if you encounter any bugs, please log them in the Github repository here

Packagr-CLI can be installed with pip

pip install packagr-cli

Keep in mind that Packagr-CLI currently does not support pip==19.x. Next we need to configure the CLI, so we can use it across all of our projects. This is done with the packagr configure command. For this we’ll need the email address/password used to create our Packagr account, and our Packagr hash id — this is the last part of the unique repository URL that gets generated on creating a Packagr account:

Packagr hash ID

Now that we have that, we can enter the configure command:

packagr configure 63cdQSDO chris@packagr.app password

Packagr-CLI is now ready to use. You’ll only need to configure it once, unless your details change. Let’s create a new test project by using the init command:

packagr init test-project

Note that the project name is optional here — if you don’t provide it, it will default to the name of your current folder structure

This command creates a file called packagr.toml, and a subfolder with the name you specified (if it doesn’t already exist). So you should have a folder structure that looks something like this:

Let’s take a look at the content of the packagr.toml file:

name = "test-project"
version = "0.1.0"
packages = [ "test-project",]

This is a very simple config file that the Packagr-CLI will manage for us. It works in the exact same way as setuptools setup file (in fact, this file is dynamically parsed as a setup.py file when the package is built, and accepts the exact same options).

The test-project folder is empty — the idea is that you should put your code in it. Let’s create a simple hello world sample called hello.py

def hello(*args, **kwargs):
return 'Hello, world'

Now that we have some code, we can use Packagr-CLI to build and upload it to Packagr. This is extremely simple:

packagr package
packagr upload

And we’re done! We can now see our new package in Packagr:

To install it, we can use the normal pip command:

pip install test-project --extra-index-url https://api.packagr.app/63cdQSDO/
User for api.package.app: christopherdavies553@gmail.com
Password: **********

Alternatively, we can use the far shorter equivalent command in Packagr-CLI:

packagr install test-project

Next steps

You can see what’s currently possible in Packagr CLI by checking out the docs. More functionality will be added shortly so the feature set is being expanded all the time