DEV Community

Qichao
Qichao

Posted on

The easiest way to upload your own pip package to pypi.org

Python's package choice is a selling point of it. Yet the package management pip can be quite tricky for starters with issues like env, version number, etc.

To publish a package using pip to pypi.org is not easier at all, due to the complicated and unintuitive process.

The good news is, we have now have a wonderful template to work with and the powerful GitHub Action to help.

Use a template

First, you should download this repo:
https://github.com/chaosprint/setup.py

Some things to do:

  • change the name of mypackage to YOUR-PACKAGE-NAME
  • Edit the core.py to fit your need
  • Edit the setup.py based on the comment inside

Use GitHub

Now create a new GitHub repo.
Upload your package and double check the license, readme, version number, author, etc.

Create a new action

After you upload your code, click Action on your repository.

Choose Publish Python Package.

Change the __token__ to your username on pypi.org (you should have registered one).

Then, commit it.

Create a secret in your repo settings

Settings -> Secrets -> New repository secret

key: PYPI_API_TOKEN
value: YOUR_PASSWORD_FOR_PYPI

Finally

Create a release. Then the project will be built and uploaded to pypi automatically.

Top comments (0)