Python Package How?
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 Python file. The only thing in it right now is __version__ = ‘0.1.0’
.
Code Package:
Now in the file with __version__ = ‘0.1.0’
, 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’
to the next version (Also do it in the py project.toml
file). 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 !