---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-pypi.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-pypi.md
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/ru/llms.txt

# Настроить PyPI для работы с реестром SourceCraft

1. [Создайте](https://sourcecraft.dev/portal/docs/ru/sourcecraft/security/pat.md#create) персональный токен (PAT).
1. В корневой директории пользователя создайте файл `~/.pypirc` со следующим содержимым, указав в нем полученный токен:

    ```text
    [distutils]
    index-servers =
        sourcecraft

    [sourcecraft]
    repository = https://pkg.sourcecraft.tech/pypi/<слаг_организации>/<идентификатор_реестра>/legacy/
    username = iam
    password = <персональный_токен_PAT>
    ```

    <!-- source: ru/_includes/sourcecraft/get-slug-registry-id-notice.md -->
    {% note tip %}

    Слаг организации и идентификатор реестра вы можете узнать на странице реестра в интерфейсе SourceCraft.

    {% endnote %}
    <!-- endsource: ru/_includes/sourcecraft/get-slug-registry-id-notice.md -->

1. Чтобы отправить [подготовленный](https://packaging.python.org/en/latest/tutorials/packaging-projects/) пакет [pip](https://ru.wikipedia.org/wiki/Pip_(менеджер_пакетов)) в реестр SourceCraft, выполните команду:

    {% note info %}

    Пакет должен быть [собран](https://packaging.python.org/en/latest/tutorials/packaging-projects/) в [виртуальном окружении](https://docs.python.org/3/library/venv.html) Python.

    {% endnote %}

    ```bash
    python3 -m twine upload <путь_к_пакету> \
      --repository sourcecraft
    ```

    Результат:

    ```text
    Uploading distributions to https://pkg.sourcecraft.tech/pypi/myorg/cn1bgtp9c21b********/legacy/
    Uploading my_package-0.0.1-py3-none-any.whl
    100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.1/4.1 kB • 00:00 • ?
    Uploading my_package-0.0.1.tar.gz
    100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.7/3.7 kB • 00:00 • ?
    ```
1. Чтобы установить пакет pip из реестра SourceCraft:

    1. Создайте переменную окружения, содержащую персональный токен (PAT) SourceCraft:

        ```bash
        export PAT_TOKEN="<персональный_токен_PAT>"
        ```
    
    1. Выполните команду:

        ```bash
        pip install \
            --index-url https://iam:${PAT_TOKEN}@pkg.sourcecraft.tech/pypi/<слаг_организации>/<идентификатор_реестра>/simple/ \
            <имя_пакета>
        ```

        Результат:

        ```text
        Looking in indexes: https://iam:****@pkg.sourcecraft.tech/pypi/myorg/cn1bgtp9c21b********/simple/
        Collecting my-package
          Downloading https://pkg.sourcecraft.tech/pypi/myorg/cn1bgtp9c21b********/simple/my-package/0.0.1/-/my_package-0.0.1-py3-none-any.whl (1.6 kB)
        Installing collected packages: my-package
        Successfully installed my-package-0.0.1
        ```

#### Полезные ссылки {#see-also}

* [Взаимосвязь ресурсов SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/concepts/index.md)
* [Создать реестр (registry) в SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/packages-management.md)
* [Подключить реестр (registry) к репозиторию SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/connect-registry.md)
* [Настроить Maven для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-maven.md)
* [Настроить npm для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-npm.md)
* [Настроить NuGet для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-nuget.md)
* [Настроить Docker для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-docker.md)
