In this section I will talk about how create a simple python package
that can be installed using
python setup.py install. These are the
basics sharing your package with other users. In order to get your
package to install with
pip you will need to complete the steps in
this guide and PyPi. The reason is that this guide only shows
how to let someone install your package if they have the package
directory on their machine.
This guide was taken from several resources:
Is anyone else troubled by the fact that so many links are necissary for simple python package development?!
Overview of typical package
README.md CHANGELOG.md LICENSE.md setup.py <package>/__init__.py
The most important file is the
setup.py file. All required and
optional fields are given
from setuptools import setup, find_packages from codecs import open from os import path here = path.abspath(path.dirname(__file__)) # Get the long description from the README file with open(path.join(here, 'README.md'), encoding='utf-8') as f: long_description = f.read() setup( name='<required>', version='<required>', description='<required>', long_description=long_description, long_description_content_type="text/markdown", url='<optional>', author='<optional>', author_email='<optional>', license='<optional>', classifiers=[ # Trove classifiers # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: Implementation :: CPython' ], keywords='<optional>', packages=find_packages(exclude=['docs', 'tests']), # setuptools > 38.6.0 needed for markdown README.md setup_requires=['setuptools>=38.6.0'], )
While setuptools docs detail each option. I still needed some of the keyworks in more plain english. This is not an exhaustive list so make sure to reference the setuptools docs.
- the name of package on pypi and when listed in pip. This is not
the name of the package that you import via python. The name of the
import will always be the name of the package directory for example
- make sure that the version numbers when pushing to pypi are unique. Also best to follow semantic versioning.
- keep it short and describe your package
- make sure that you have created a README.md file in the project directory. Why use a README.md instead of README.rst? It’s simple, Github, Bitbucket, Gitlab, etc. all will display a README.md as the homepage.
- link to git repo url
- give yourself credit!
- nobody should really use this address to contact you about the package
- need help choosing a license? use choosealicense
- one day would be nice to know why they are important. list of available tags.
- will help with searching for package on pypi
- which packages to include in python packaging. using
find_packagesis very helpful.
- list of packages required for setup. Note that versioning uses environment markers.
If you do not include a license it is by default copyrighted and unable to be used by others. This is why it is so important to give your work a license. A great resource for this is choosealicense.com.
A README is the first document someone sees when they visit your project make it an inviting document with an overview of everthing the programmer needs.
A changelog is something that I did not really adopt in my projects until I started forgeting what I had done in the past week. I git log is not designed for this! Some great advice can be found in Keep a CHANGELOG. Their motto is “Don’t let your friends dump git logs into CHANGELOGs™”
At this point you have a simple python package setup! Obviously the readme, changelog, and license are all optional but HIGHLY recommended. Next we will share our package with the whole world through continuous deployment (:doc:`pypi`_).