Creating Python Packages¶
Introduction¶
As an Individual developer or a member of team you we end up writing code which can be re-used. Packages are great way to share these functions and classes. Maintainability is another reason we need to use packages.
Steps¶
Following steps are laid out assuming you’re trying to create a`spam` package. To create a package you need to, create:
README.md containing package notes
setup.py which contains package information
- package {E.g. spam} this is a package directory within project directory. Ensure
Same name also appears for name field in setup.py
__init__.py file exists in spam directory {i.e. you package directory}
Have all your python code within this package directory
- Create package using python setup.py sdist bdist_wheel, this will create
sdist will create source distribution
bdist_wheel will create binary distribution
To install package you can use wheel file pip install ../spam/dist/spam-0.0.1-py3-none-any.whl
Once you do this, following is what your directory structure would look like:

Reference: From a python project to an open source package: an A to Z guide