This tutorial shows you how to publish Python packages built with Poetry to a private PyPI repository on RepoForge.io.

Prerequisites

  • A RepoForge.io account
  • Your RepoForge repository URL (found under Show me how to publish packages)
  • An access token with Python write permissions

Installing Poetry

Install Poetry using the official installer:

curl -sSL https://install.python-poetry.org | python3 -

Verify the installation:

poetry --version

Creating a Package in Poetry

Now that poetry is installed you can create a poetry project like this:

poetry new private-package

This will create a subfolder called private-package, containing a package skeleton.

And that’s it! We have created an empty Python package. We’re going to leave it blank for the sake of this simple tutorial.

Pointing Poetry at Your Private Repository

We can now configure Poetry to publish our private-package package to our RepoForge private repository by using the below command, replacing the URL with our unique RepoForge repo URL:

poetry config repositories.repoforge https://api.repoforge.io/abcdef

Next, configure your RepoForge access token. Use __token__ as the username and your access token as the password:

poetry config http-basic.repoforge __token__ your-access-token

Publishing the Package to Our Private Repository

First, build your package:

poetry build

Then publish to RepoForge:

poetry publish -r repoforge

If all goes well, your private Python package will be uploaded successfully. You can confirm this by refreshing your RepoForge UI:

Installing a Private Package with Poetry

Now that we have published our Python package to a private repository, we can install it in other poetry projects. To do this, you’ll need to add this section to your pyproject.toml (inserting your private repository URL):

[[tool.poetry.source]]
name = "RepoForge"
url = "https://api.repoforge.io/abcdef"

You can now do the following to install python packages locally:

poetry add private-package --source repoforge

Your private Python package is now published and can be installed in any Poetry project with the source configured.