Configuring PyPI to work with the SourceCraft registry

  1. Create a personal access token (PAT).

  2. In the user’s root directory, create a file named ~/.pypirc with the following content and specify the token in it:

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

    Tip

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

  3. To push the prepared pip package to the SourceCraft registry, run this command:

    Note

    The package must be assembled in a Python virtual environment.

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

    Result:

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

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

      export PAT_TOKEN="<personal_access_token>"
      
    2. Run this command:

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

      Result:

      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