Python Package How?

Python Package How?

This Can’t Be Done if You Have 2FA Enabled On Your PyPi Account


Do you want to expand your Python knowledge and want to show it to people? Do you want to create a package? Well this tutorial will show you how using `Poetry`.
  • Setup Package
  • Code Package
  • Publish Package
  • Updating Package

Setup Package:

To setup your package you need to first create a PyPI account and verify it. Then create a blank Python Repl. Once in the Repl open the Shell using Ctrl+Shift+S or Cmd+Shift+S. Then type poetry new <name of package> (make sure to replace <name of package> with what you want to call your package. If the name has underscores: _ use a - instead). Once you do that you will notice a folder with the name of your package click on it. You will notice another with the same name click on that. Then click on the __init__.py file.

Code Package:

Now in the __init__.py file, add your code for your package. This can be what ever you would like.

Publish Package:

Now that you are finished Setting Up and Coding your package you want to publish it. Go back to the shell (Ctrl+Shift+S or Cmd+Shift+S) and type cd <name of package> (make sure <name of package> is replaced with the name of your package). Then type poetry update to update the dependencies of your package. Next type poetry build. Finally type poetry publish. When it asks for credentials put in your Username from your PyPI account then the type your Password (The password wont show up for privacy reasons). Boom, you just published your own Python package.

Updating Package:

If you want to change something in your package. You first need to change the __version__ = ‘0.1.0’ in the pyproject.toml file to the next version. Then type cd <name of package> again. Next poetry update, then poetry build, and finally poetry publish (You will have to fill out your credentials again).

If you have any questions ask me below! Hope you find this useful :grinning:!

3 Likes

I’m afraid to say that this is outdated and it does not create a folder called __version__='0.1.0'.

It doesn’t create a folder, I never said it did. In the Python file it’s not blank but has the version number. But if there is something else that is outdated I will change it.

@SalladShooter Well, I followed your instructions and it created a folder called natedhaliwal-package, then a natedhaliwal_package folder inside that. Note the hyphen and underscore. Next, in natedhaliwal_package, there’s 1 file called __init__.py. Fine, so I put the defs in there? The file was blank, with no mention of __version__='0.1.0' anywhere.

Huh, it used to be there, I guess it probably just is now in the .toml file. Let me fix the version thing. Thanks for spotting that.

Edit: I noticed I can’t edit this, since it was four months ago. I could write a new one.