Cookiecutter template for a Python package with some modern twists:
- Primarily uses
setup.cfg
for storing packaging metadata instead of relying on
setup.py
too much. - Relies on src layout for the package.
- Support
setuptools_scm
versioning for development. - Uses pre-commit hooks to enforce code-style.
- Uses markdown for the
README.md
etc. instead of reStructured Text. - Allows project name, repo name and package name to be different (for
e.g. having something like "Scikit Learn",
scikit-learn
andsklearn
respectively). - Adds optional support for either an
argparse
based command-line tool, or aClick
based one (only the latter was available in the original template). - By default
python_requires>=3.6
is preferred, since new packages should be able to use f-strings.
TLDR: you get this:
$ tree --dirsfirst -a pypack/
pypack/
├── docs
│ └── ...
├── .github
│ ├── workflows
│ │ └── tests.yml
│ └── ISSUE_TEMPLATE.md
├── src
│ └── pypack
│ ├── cli.py
│ ├── __init__.py
│ └── pypack.py
├── tests
│ └── ...
├── CONTRIBUTING.md
├── .editorconfig
├── .git
├── .gitignore
├── HISTORY.md
├── LICENSE
├── Makefile
├── .pre-commit-config.yaml
├── pyproject.toml
├── README.md
├── setup.cfg
├── setup.py
├── THANKS.md
├── tox.ini
└── .travis.yml
- GitHub repo: https://github.com/ashwinvis/cookiecutter-pypack/
- Documentation: https://cookiecutter-pypackage.readthedocs.io/
- Free software: BSD license
- Testing setup with
unittest
andpython setup.py test
orpy.test
- Travis-CI: Ready for Travis Continuous Integration testing
- Tox testing: Setup to easily test for Python 3.6+
- Sphinx docs: Documentation ready for generation with, for example, ReadTheDocs
- Auto-release to PyPI when you push a new tag to master (optional)
- Command line interface using Click (optional)
Install the latest Cookiecutter if you haven't installed it yet (this requires Cookiecutter 1.4.0 or higher):
pip install -U cookiecutter
Generate a Python package project:
cookiecutter gh:ashwinvis/cookiecutter-pypack
Then:
- Create a repo and put it there.
- Add the repo to your Travis-CI account.
- Install the package into a virtualenv. (
pip install -e '.[dev]'
ormake develop
) - Register your project with PyPI.
- Run the Travis CLI command
travis encrypt --add deploy.password
to encrypt your PyPI password in Travis config and activate automated deployment on PyPI when you push a new tag to master branch. - Add the repo to your ReadTheDocs account
- turn on the ReadTheDocs service hook.
- Release your package by pushing a new tag to master.
- Add a
requirements.txt
file that specifies the packages you will need for your project and their versions. For more info see the pip docs for requirements files. - Activate your project on pyup.io.
For more details, see the cookiecutter-pypackage tutorial.
Don't worry, you have options:
- ionelmc/cookiecutter-pylibrary: Another template which uses the
src/
layout - audreyfeldroy/cookiecutter-pypackage: The original cookiecutter template.
- Also see the network and family tree for this repo. (If you find anything that should be listed here, please add it and send a pull request!)
If you have differences in your preferred setup, I encourage you to fork this to create your own version. Or create your own; it doesn't strictly have to be a fork.
- Once you have your own version working, add it to the Similar Cookiecutter Templates list above with a brief description.
- It's up to you whether or not to rename your fork/own version. Do whatever you think sounds good.
I also accept pull requests on this, if they're small, atomic, and if they make my own packaging experience better.