Magic of Python packages
There is always some magic when you learn python and install packages with pip install
command. But have
you ever wondered how python packages are born?
At first, there is almost any package for your need in the PYPI repository. PYPI is a PYthon Package Index.
That is a default repository for python modules. When you install a module with pip install
command,
it downloads the required package and its dependencies from pypi.org. Of course that could be overwritten
with your private repository instance, if you have one. 🙂 While you accumulate more and more experience
with writing python code you may face some extra needs for python packages. You check pypi and voila! Wait...
No. There is no package for your specific purpose. It has not been developed yet. Okay, you have an idea of how to
make the package. And then you did it. Nice. It's time to share your awesome code and make other developers happy
because there is no need to develop the package again. How to start?
Well, there is a great python packaging guide. I would recommend to go through it. It will help you to through the basics of packaging process. The guide includes the following steps:
- Preparing your package repository folder structure for packaging;
- Creating configuration files for packaging and distribution (license and readme);
- Generating distribution archives;
- Downloading the archives to a python index repo;
- And finally, installing the newly added package.
Yes, your friends will be able to install your package with pip install <your_cool_package_name>
now. You may worry about
making mistakes while uploading distribution archives to PYPI. Stop it 🙂 There is a test PYPI
instance to master interaction with pypi repository. It is here.
Don't place any valuable info there because the testing PYPI instance is periodically cleaned.
Huh. It seems that now some magic smoke disappeared and you understand more clearly of how things are done in python. Enjoy!