A simple template for a Python project that can be installed with pip - includes docs and tutorial
Go to source code:
This project is a quick reference, tutorial and demo for making a Python project installable using the pip install PACKAGE command. For full details, see the linked resources.
Pre-built wheels are faster than using source distributions, but both are supported.
From pip docs
pipcan install from either Source Distributions (sdist) or Wheels, but if both are present on PyPI, pip will prefer a compatible wheel.Wheels are a pre-built distribution format that provides faster installation compared to Source Distributions (sdist), especially when a project contains compiled extensions.
If
pipdoes not find a wheel to install, it will locally build a wheel and cache it for future installs, instead of rebuilding the source distribution in the future.
As an alternative to using setup.py and twine, you can use Poetry to publish your package. This also avoids maintaining package versions in two places at once (requirements.txt and setup.py).
See Libraries on Poetry docs (though โPackagesโ is a better name) and see the Publish command.
pip or python setup.py.pip and a Github URL.Note on publishing:
Here the repo or cloned folder is sample-project with a hyphen.
Inside the repo is sampleproject which may not have a hyphen (otherwise you canโt import it as package) and using an underscore is discouraged. See PEP-8.
sample-project
sampleproject/
foo/
__init__.py
__init__.py
sampleproject.py
tests/
setup.py
LICENSE
README.md
Note that a directory and a script are both considered a โmoduleโ in Python if it can be imported.
See init file tutorial page.
See main file tutorial page.
A main file is a script or an entrypoint to be run directly, but it might be considered a module if you import it from elsewhere. A convention is that this main script matches package name as in the example. You can also make it __main__.py.
See section of tutorial.
from . import echo
from .. import formats
from ..filters import equalizer