# Python registry

Upload Python packages with twine; install them with pip or uv.

## What it is

A Python package index for your organization, served by the platform and spoken to with the ordinary tools: `twine` uploads, `pip` and `uv` install. Find it under **Python registry** in the console: the page gives you the index URL, the upload URL and every project you have uploaded.

There is nothing to create. The registry exists from the moment your organization does, and a project appears on its first upload. Projects are private until you make one public; a public project installs with no credential at all.

## Concepts

| Term           | Meaning                                                                                                                                     |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| **Registry**   | One per organization, addressed as `https://pypi.<domain>/<organization>/`. The index pip reads is `…/simple/`, the upload URL `…/legacy/`. |
| **Project**    | A package name with all its versions. Names are compared the way pip compares them: `My_Package` and `my-package` are one project.          |
| **File**       | One wheel (`.whl`) or source distribution (`.tar.gz`) of a version. Its bytes never change: the same filename cannot be uploaded twice.     |
| **Yank**       | Marks every file of a version as withdrawn. pip and uv skip a yanked version unless someone pins it exactly (`==1.4.0`).                    |
| **Access key** | A Deutsche Cloud access key `<key id>:<secret>`, the password for uploads and private installs; the username is always `__token__`.            |

## How to

### Upload a package

Build the distributions as usual (`python -m build`), then upload them with an access key allowed `pypi:UploadPackage`:

```sh
TWINE_USERNAME=__token__ TWINE_PASSWORD='<key id>:<secret>' \
  twine upload --repository-url https://pypi.<domain>/<organization>/legacy/ dist/*
```

`uv publish --publish-url https://pypi.<domain>/<organization>/legacy/ --username __token__ --password '<key id>:<secret>'` does the same. The first upload of a name creates the project. Uploading a file whose name exists already is refused with 400 `File already exists`; upload a new version instead.

### Install a package

A private project needs the access key in the index URL:

```sh
pip install --index-url 'https://__token__:<key id>:<secret>@pypi.<domain>/<organization>/simple/' my-package
```

With `uv`, use the same URL as `--index-url` (`uv pip install`) or as an `[[tool.uv.index]]` in `pyproject.toml`. To keep public packages coming from pypi.org, use `--extra-index-url` for this registry, and pin versions with hashes (`--require-hashes`), so a package of the same name elsewhere cannot be picked instead.

### Make a project public

Open the project, then **Visibility** and **Make public**. Anyone can then install every file of that project with the index URL and no key; listing the index without a key shows only public projects. **Make private** reverses it.

### Yank a version

Open the project and choose **Yank** next to the version. Its files stay, and anyone who pinned the version still installs it; everyone else gets the newest version that is not yanked. **Un-yank** reverses it.

### Delete a project

Open the project, then **Delete project**. Every file is deleted, and anything that installs the project fails from then on.

### Give someone access

Access is IAM. Attach `PypiFullAccess` to upload and manage, or `PypiReadOnlyAccess` to browse. `PypiReadOnlyAccess` does not include `pypi:DownloadPackage`, because downloading a distribution hands over its code, so add it where installs are needed. A custom policy can narrow any action to one project (`rn:ews::<org id>:pypi:project/<project id>`).

## Reference

### Registry endpoints

pip, uv and twine call these; you do not call them by hand.

| Request                                      | What                                                                                |
| -------------------------------------------- | ----------------------------------------------------------------------------------- |
| `GET /<organization>/simple/`                | the project list (HTML, or JSON with `Accept: application/vnd.pypi.simple.v1+json`) |
| `GET /<organization>/simple/<project>/`      | a project's files with their SHA-256, `Requires-Python` and yanked state            |
| `GET /<organization>/files/<project>/<file>` | a file                                                                              |
| `POST /<organization>/legacy/`               | an upload, as `twine` sends it                                                      |

Anonymous requests for the index pages are limited to 600 a minute per address and answered 429 above it; files are not limited.

### Actions

| Action                  | Allows                                                |
| ----------------------- | ----------------------------------------------------- |
| `pypi:ListProjects`     | the project list and the registry's URLs              |
| `pypi:DescribeProjects` | a project's versions and files                        |
| `pypi:DownloadPackage`  | downloading files (pip install)                       |
| `pypi:UploadPackage`    | uploading files; the first upload creates the project |
| `pypi:UpdateProject`    | making a project public or private, its summary       |
| `pypi:YankRelease`      | yanking and un-yanking versions                       |
| `pypi:DeleteProject`    | deleting a project or one of its files                |

### Limits

| Limit      | Value                                                 |
| ---------- | ----------------------------------------------------- |
| File size  | 100 MB                                                |
| Projects   | 1,000 per organization; ask for more under **Quotas** |
| File types | wheels (`.whl`) and source distributions (`.tar.gz`)  |

### Storage and billing

Every uploaded file is stored in your organization's storage and metered on your bill. Deleting a project or a file releases that storage.

## Not supported

- `pip search` and the XML-RPC API.
- Upload signatures (`.asc`) and attestations.
- Mirroring pypi.org: install public packages from pypi.org with `--extra-index-url`.
- Deleting a file and uploading another under the same name.

## Troubleshooting

| Symptom                                 | Cause                                                        | Fix                                                           |
| --------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------- |
| 401 `Unauthorized`                      | no credential, or the username is not `__token__`            | username `__token__`, password the access key `<id>:<secret>` |
| 404 on a private project you can see    | the key belongs to another organization, or lacks the action | use a key of this organization allowed `pypi:DownloadPackage` |
| 400 `File already exists`               | that filename was uploaded before                            | bump the version and upload again                             |
| 400 `The filename … is not a file of …` | the file was renamed after `python -m build`                 | upload the files as the build wrote them                      |
