.. image:: https://travis-ci.org/bast/somepackage.svg?branch=master
.. image:: https://img.shields.io/badge/license-%20MPL--v2.0-blue.svg
Show how to structure a Python project.
Inspired by https://github.com/kennethreitz/samplemod.
Please browse this blog post for a good summary of recommendatios and templates: https://email@example.com/understanding-best-practice-python-tooling-by-comparing-popular-project-templates-6eba49229106
Python 2 or 3?
- Develop your code under Python 3, test it for both Python 2 and Python 3
but consider Python 3 to be the default today.
Split your code into packages, modules, and functions
Classes vs. functions
- Do not overuse classes.
- Prefer immutable data structures.
- Prefer pure functions.
- Give the subdirectory the same name as your package.
- Before you name your package, check that the name is not taken on https://pypi.org
(you may want to upload your package to PyPI one day).
somepackage/__init__.py define what should be visible to the outside.
- Use https://semver.org.
- Test all non-trivial code. I recommend to use https://pytest.org.
- Use Travis CI: https://docs.travis-ci.com/user/languages/python/.
- Package dependencies for developers should be listed in
- Alternatively, consider using http://pipenv.readthedocs.io.
- Package dependencies for users of your code (who will probably install via pip) should be listed in
- Follow PEP8: https://www.python.org/dev/peps/pep-0008/
pycodestyle to automatically check for PEP8.
- Consider using type hints: https://docs.python.org/3/library/typing.html
- Consider using http://mypy-lang.org.
- Consider verifying type annotations at runtime: https://github.com/RussBaz/enforce
Share your package
- Choose a license and add a LICENSE file.
- Share your package on PyPI. For this you can follow https://github.com/bast/pypi-howto.
I used to recommend reStructuredText for READMEs in contrast to Markdown but
PyPI no longer requires reStructuredText. You can use Markdown as noted on
https://pypi.org/help/ under "How can I upload a project description in a
Example shown here: https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py
Suggestions? Corrections? Pull requests?