Authenticating with API keys

This feature is in beta

Packagr now provides API keys as a convenient alternative to using user based authentication to upload or download packages to Packagr. You can manage your keys at any time by clicking on the API Keys link in the application sidebar

Generating API keys

New API keys can be generated at any time from the API Keys section of the app. There is no limit to the number of API keys that can be created, for all user types. To create a new API key, simply click on the Create new API Key button. This will add a new API key to your list.

## Deleting API keys

To delete an API Key, simply click on the delete icon next to the key. This will mean that you are no longer able to authenticate to your repository with this key

Using your keys

By default, API keys are hidden in the UI - to display an API key, simply click on the eye icon next to the API key you want to copy. You can also click the copy icon to copy an API key to your clipboard.

You can use an API Key in any place that you would have normally used your Packagr user password. In such cases, the username that you provide can be any string.

For example, you can upload a package using Twine to Packagr using the following syntax, using a blank string as the username and an API key as the password:

  twine upload  --repository-url[my-hash-id]/ * -u "" --password [api-key]

You can also install packages with pip in a similar way:

  pip install my-package -i[my-hash-id]/
  User for [anything]
  Password: [api-key]

A convenient way of storing your credentials is to save them locally to your ~/.netrc file, so you don't need to enter them every time. This also applies with API keys. Start by creating a ~/.netrc file on your system as follows:

# ~/.netrc
    login ""
    password [api-key]

Next, set the permissions of this file correctly:

sudo chown [local username] ~/.netrc
sudo chmod 0600 ~/.netrc

Now, you can download and install packages with pip, without being prompted for credentials, like this:

pip install my-package -i[my-hash-id]/