Member-only story
Create and publish your own Python package
A short and simple guide on how to pip install your custom made package
You are probably familiar with requests, Pandas, Numpy and many other packages that you can install with pip. Now it’s time to create your own package! In this article we’ll go through the required steps to package and publish your Python code for the whole world to pip install. First we’ll look at packaging your code, then how we can publish it to make it accessible.
(Would you rather share your code with just a select few people like coworkers? It’s also possible to allow people to pip install a package from a private repository. This even works when including your package in a Docker container!)
Goal and preparation
For this article, I’ve created a few truly essential functions that I’d like to share with the world. Let’s create a package called “mikes_toolbox” that people can use by simply pip install mikes_toolbox
.
First we’ll sketch an overview of how the installation process works: if someone calls pip install mikes_toolbox
the code has to come from somewhere. Pip searches for a package with that name on PyPi; the Python Package Index. You can think of this as a YouTube for Python packages. First we’ll package our code and then upload it to PyPi so that others can find our package, download it and install it.
Packaging
First we’ll package our code. We’ll create a project directory called ‘toolbox_project’ that contains the following directories and files:
toolbox_project
mikes_toolbox
__init__.py
functions.py
decorators.py
LICENSE.txt
README.md
setup.cfg
setup.py
The content of the project folder consists of two parts: the mikes_toolbox folder and 4 additional files. The folder is our actual package that contains our source code. The 4 additional files contain information on how to install the package and some additional information.