Anaconda Enterprise: Documentation

# Working with packages

- Overview
- Using package managers
- Uploading packages
- Using private packages
- Removing a previous version of a package
- Adding a collaborator to a package
- Removing a collaborator from a package
- Transferring a package to a new owner
- Deleting a package

## Overview

All files uploaded to Anaconda Cloud are stored in packages. Each Cloud package is visible at its own unique URL based on the name of the user who owns the package and the name of the package.

Users can create a Cloud package and then upload files into it.

NOTE: All packages are public if uploaded by users of free accounts. Packages may be designated as private by upgrading to a paid account.

For more information, see package.

### Namespaces

A namespace is the part of Cloud where a user or organization may host packages. For example, the user namespace https://anaconda.org/travis contains packages that were uploaded and shared by a user named `travis`.

For more information, see namespace.

### Labels

A label is part of the URLs on Cloud where conda looks for packages.

Each file within a package may be tagged with one or more labels, or not tagged at all to accept the default label of `main`.

For more information, see label.

## Using package managers

Cloud supports two package managers, conda and PyPI. To work with conda or PyPI packages, you must use their corresponding subdomains:

- To install conda packages from the user `travis`, use the repository URL `https://conda.anaconda.org/travis`
- To install PyPI packages from the user `travis`, use the repository URL `https://pypi.anaconda.org/travis`

### Conda packages

#### Uploading conda packages

This example shows how to build and upload a conda package to Cloud using `conda build`.

Use the Terminal window or an Anaconda Prompt to perform the following steps:

1. Before you start, install `anaconda-client` and `conda-build`:

       conda install anaconda-client conda-build

2. Choose the repository for which you would like to build the package. In this example, we use a simple public conda test package:

       git clone https://github.com/Anaconda-Platform/anaconda-client
       cd anaconda-client/example-packages/conda/

   In this directory, there are two required files, meta.yaml and build.sh.

   macOS and Linux systems are Unix systems. Packages built for Unix systems require a `build.sh` file, packages built for Windows require a `bld.bat` file, and packages built for both Windows and Unix systems require both a `build.sh` file and a `bld.bat` file. All packages require a `meta.yaml` file.

3. To build the package, turn off automatic Client uploading and then run the `conda build` command:

       conda config --set anaconda_upload no
       conda build .

   All packages built in this way are placed in a subdirectory of Anaconda’s `conda-bld` directory.

4. You can check where the resulting file was placed with the `--output` option:

       conda build . --output

5. You can upload the test package to Cloud with the anaconda upload command:

       anaconda login
       anaconda upload /path/to/conda-package.tar.bz2

   NOTE: Replace `/path/to/` with the actual path where you stored the package.

For more information on conda’s overall build framework, you may also want to read the articles Building conda packages and Tutorials on conda build.

#### Installing conda packages

You can install conda packages from Cloud by adding channels to your conda configuration.

Use the Terminal window or an Anaconda Prompt to perform the following steps:

1. Because conda knows how to interact with Cloud, specifying the channel `sean` translates to https://anaconda.org/sean:

       conda config --add channels sean

2. You can now install public conda packages from Sean’s Cloud account. Try installing the `testci` package at https://anaconda.org/sean/testci:

       conda install testci

3. You can install a package from a channel with a token and a label:

       conda install -c https://conda.anaconda.org/t/<token>/<channel>/label/<labelname> <package>

   NOTE: Replace `<token>` with the provided token,``<channel>`` with a user channel, `<labelname>` with the label name and <package> with the package name you want to install.

### PyPI packages

#### Uploading PyPI packages

We can test PyPI package uploading with a small public example package saved in the anaconda-client repository.

Use the Terminal window or an Anaconda Prompt to perform the following steps:

1. Begin by cloning the repository from the command line:

       git clone git@github.com:Anaconda-Platform/anaconda-client.git
       cd anaconda-client/example-packages/pypi/

2. You can now create your PyPI package with the `setup.py` script:

       python setup.py sdist

3. The package has now been built as a source tarball and is ready to be uploaded:

       anaconda upload dist/*.tar.gz

   Your package is now available at `http://anaconda.org/USERNAME/PACKAGE`.

   NOTE: Replace `USERNAME` with your username, and `PACKAGE` with the package name.

#### Installing PyPI packages

The best way to install a PyPI package is using `pip`. For the following command, we use the package we authored in the examples above. In your Terminal window or an Anaconda Prompt, run:

    pip install --extra-index-url https://pypi.anaconda.org/USERNAME/simple pypi-test-package

#### Installing private PyPI packages

The best way to manage access or make PyPI and other packages private is to create organizations or groups, which allow you to set separate permissions per package, notebook or environment.

You can also control access with the token system. All Cloud URLs can be prefixed with `/t/$TOKEN` to access private packages.

In your Terminal window or an Anaconda Prompt, run:

    TOKEN=$(anaconda auth --create --name YOUR-TOKEN-NAME)
    pip install --index-url https://pypi.anaconda.org/t/$TOKEN/USERNAME/simple test-package

NOTE: Replace `YOUR-TOKEN-NAME` with the name of the token you created, `USERNAME` with your username and `simple test-package` with the actual test-package name.

## Uploading packages

1. To upload package files to Cloud, use the Terminal window or an Anaconda Prompt and the upload command:

       anaconda login
       anaconda upload PACKAGENAME

   NOTE: Replace `PACKAGENAME` with the actual package name.

   Cloud automatically detects packages and notebooks, package or notebook types, and their versions.

2. Your package is now available at:

       https://anaconda.org/<USERNAME>/<PACKAGENAME>

   NOTE: Replace `<USERNAME>` with your username, and `<PACKAGENAME>` with the package name.

3. Your package also can be downloaded by anyone using Client from the Terminal window or an Anaconda Prompt:

       anaconda download USERNAME/PACKAGENAME

   NOTE: Replace `<USERNAME>` with your username, and `<PACKAGENAME>` with the package name.

## Using private packages

By default, all packages, notebooks and environments uploaded to Cloud are accessible to anyone who has access to the repository.

Packages uploaded to your user channel on Cloud can be marked as private using the Web UI:

1. Select the desired package.

2. Select the Settings tab.

3. Select Admin in the sidebar.

4. Alternatively, you can reach this page with the following URL:

       https://anaconda.org/<username>/<package>/settings/admin

   NOTE: Replace `<username>` with your username, and `<package>` with the package name.

NOTE: Jupyter notebooks and conda environments can also be marked private using this procedure and URL.

NOTE: Other Cloud users may access your private packages either with tokens or by logging in.

### Private packages with tokens

To make your private packages available to be accessed with tokens:

1. First create an access token that includes the following scope for Client:

       conda:download

   Or, in the Web UI with:

       Allow private downloads from conda repositories

   The token is a random alphanumeric string and this is used to install a package or add a channel from which you want to install private packages.

2. Using the provided token, a user channel can be added to `config` from the Terminal window or an Anaconda Prompt with:

       conda config --add channels https://conda.anaconda.org/t/<token>/<channel>

   NOTE: Replace `<token>` with the provided token, and `<channel>` with a user channel.

3. The token can also be used to install packages without first adding the channel. In the Terminal window or an Anaconda Prompt, run:

         conda install -c https://conda.anaconda.org/t/<token>/<channel> <package>

       To install a package from a channel using token and label name::

         conda install -c https://conda.anaconda.org/t/<token>/<channel>/label/<labelname> <package>

   NOTE: Replace `<token>` with the provided token, `<channel>` with a user channel, `<labelname>` with the label name and `<package>` with a package name you want to install.

4. Private PyPI packages can also be installed in the Web UI:

       https://pypi.anaconda.org/t/<token>/<channel>

   NOTE: Replace `<token>` with the provided token, and `<channel>` with a user channel.

### Private packages with login

To make your private packages available to users who have logged in:

1. Create an organization.
2. Create a group in that organization, which may be a read-only group.
3. Add to the group the users that you want to grant access to.
4. Upload the package to the organization, or transfer an existing package to the organization.

After you grant them access, other users can download and install your package using the Web UI or Client.

To download a package:

1. In a browser, navigate to the desired channel.

2. If the organization name is `OrgName` and the package name is `conda-package`, use these commands in the Terminal window or an Anaconda Prompt:

       conda install anaconda-client
       anaconda login
       conda install -c OrgName conda-package

Or instead:

    conda install anaconda-client
    anaconda login
    conda install -c https://conda.anaconda.org/OrgName conda-package

## Removing a previous version of a package

To remove a previous version of one of your packages from Cloud:

1. Select the package name.
2. Select the Files tab.
3. Select the checkbox to the left of the version you want to remove.
4. In the Actions menu, select Remove.

You may instead use the Terminal window or an Anaconda Prompt:

1. Run:

       anaconda remove jsmith/testpack/0.2

   NOTE: Replace `jsmith` with your username, `testpack` with the package name and `0.2` with the desired version.

2. You can now see the change on your profile page:

       https://anaconda.org/<USERNAME>/<PACKAGE>

   NOTE: Replace `<USERNAME>` with your username, and `<PACKAGE>` with the package name.

## Adding a collaborator to a package

You can add other users that are not part of an organization to collaborate on your packages. You will need the usernames of the other users.

1. From your dashboard, select the package by clicking on its name.
2. To display the package settings, select the Settings option.
3. To display the current collaborators, select the Collaborators option.
4. Type the username of the person you want to add as a collaborator, and then click the Add button.

NOTE: All collaborators are given full read/write permissions to the package, even private packages.

## Removing a collaborator from a package

To revoke package access previously granted to a collaborator:

1. From your dashboard select the package by clicking on its name.
2. To display the package settings, select the Settings option.
3. To display the current collaborators, select the Collaborators option.
4. Click the red X button next to a collaborator to revoke their access.

## Transferring a package to a new owner

By default, when you create or add packages, they are attached to your individual profile. You can transfer ownership to another owner account you control, such as an organization profile you manage.

To transfer a package to a new owner:

1. From your dashboard–or the dashboard of an organization you administer–select the package for which you want to transfer ownership.

   The system displays options for that package.

2. To display the package settings, select the Settings option.

3. Select the Admin option.

4. Under Transfer this package to a new owner, click the Transfer button.

5. Select the organization name for the new owner.

6. Click the Transfer Ownership button.

## Deleting a package

To delete a package from Cloud, including all of its versions:

1. Select the package name.
2. Select the Settings option.
3. In the left sidebar, select Admin.
4. Click Delete.

You may instead use the Terminal window or an Anaconda Prompt:

1. Run:

       anaconda remove jsmith/testpak

   NOTE: Replace `jsmith` with your user name, and `testpak` with the package name.

2. You can now see the change on your profile page:

       https://anaconda.org/<USERNAME>

   NOTE: Replace `<USERNAME>` with your username.