---
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/en/llms.txt

# Configuring PyPI to work with the SourceCraft registry

1. [Create](https://sourcecraft.dev/portal/docs/en/sourcecraft/security/pat.md#create) a personal access token (PAT).
1. In the user’s root directory, create a file named `~/.pypirc` with the following content and specify the token in it:

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

    [sourcecraft]
    repository = https://pkg.sourcecraft.tech/pypi/<organization_slug>/<registry_ID>/legacy/
    username = iam
    password = <personal_access_token>
    ```

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

    You can find the organization slug and registry ID on the registry page in the SourceCraft UI.

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

1. To push the [prepared](https://packaging.python.org/en/latest/tutorials/packaging-projects/) [pip](https://en.wikipedia.org/wiki/Pip_(package_manager)) package to the SourceCraft registry, run this command:

    {% note info %}

    The package must be [assembled](https://packaging.python.org/en/latest/tutorials/packaging-projects/) in a Python [virtual environment](https://docs.python.org/3/library/venv.html).

    {% endnote %}

    ```bash
    python3 -m twine upload <path_to_package> \
      --repository sourcecraft
    ```

    Result:

    ```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. To install a pip package from the SourceCraft registry:

    1. Create an environment variable containing the SourceCraft personal access token (PAT):

        ```bash
        export PAT_TOKEN="<personal_access_token>"
        ```
    
    1. Run this command:

        ```bash
        pip install \
            --index-url https://iam:${PAT_TOKEN}@pkg.sourcecraft.tech/pypi/<organization_slug>/<registry_ID>/simple/ \
            <package_name>
        ```

        Result:

        ```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
        ```

#### Useful links {#see-also}

* [SourceCraft resource relationships](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/index.md)
* [Creating a registry in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/packages-management.md)
* [Connecting a registry to a SourceCraft repository](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/connect-registry.md)
* [Configuring Maven to work with a SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-maven.md)
* [Configuring npm to work with a SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-npm.md)
* [Configuring NuGet to work with a SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-nuget.md)
* [Configuring Docker to work with a SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-docker.md)
