» Make grep CLI App in Python » 3. Publish » 3.2 Publish to PyPI

Publish to PyPI

1. Create an account on PyPI

Create an account here: https://pypi.org/account/register/

Verify your email and Add API token here: https://pypi.org/manage/account/

2FA(Two-factor authentication) setup needs an authenticator app in your phone: try Microsoft Authenticator, Google Authenticator or your favorite one.

2. Build Distribution Archives

make build

# Or
python3 setup.py sdist bdist_wheel

3. Install twine

If you don't have twine installed, you can install it using:

pip3 install twine

4. Upload to PyPI Test Server (Optional)

It's a good practice to test your package on the PyPI Test Server before publishing to the official PyPI. Use the following command:

twine upload --repository-url https://test.pypi.org/legacy/ dist/*

Install your package from the test server to ensure everything works as expected:

pip3 install --index-url https://test.pypi.org/simple/ <your-package-name>

5. Upload to PyPI

Once you are confident, you can upload your package to the official PyPI:

make publish

# Or
twine upload dist/*

To use an API token:

  • Set your username to __token__
  • Set your password to the token value, including the pypi- prefix

If everything is good, you should see something like this:

Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: __token__
Enter your password: 
Uploading lr_grepy-0.1.0-py3-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.0/7.0 kB • 00:01 • ?
Uploading lr-grepy-0.1.0.tar.gz
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.2/6.2 kB • 00:00 • ?

View at:
https://pypi.org/project/lr-grepy/0.1.0/

6. Verify on PyPI

PyPI

Visit PyPI and check if your package is listed.

7. Use it as a real package

pip3 install lr-grepy

grepy time logs/*log

Congratulations🎉! You've made a great CLI app in Python now.

Complete code: https://github.com/Literank/lr_grepy

Keep Going! Keep Learning!

PrevNext