Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time


Cookiecutter template for a Python library. Travis-CI Build Status AppVeyor Build Status Requirements Status



This is an "all inclusive" sort of template.

  • Choice of various licenses.
  • Tox for managing test environments for Python 2.7, 3.7+, PyPy etc.
  • Pytest or Nose for testing Python 2.7, 3.7+, PyPy etc.
  • Optional support for creating a tests matrix out of dependencies and python versions.
  • Travis-CI and AppVeyor for continuous testing.
  • Coveralls or Codecov for coverage tracking (using Tox).
  • Documentation with Sphinx, ready for ReadTheDocs.
  • Configurations for:
  • Support for C extensions (including coverage measurement for the C code). See c_extension_support.
  • Packaging and code quality checks. This template comes with a tox environment (check) that will:
    • Check if your README.rst is valid.
    • Check if the has any issues.
    • Run flake8 (a combo of PEP8, pyflakes and McCabe checks) or pylama


Projects using this template have these minimal dependencies:

  • Cookiecutter - just for creating the project
  • Tox - for running the tests
  • Setuptools - for building the package, wheels etc. Now-days Setuptools is widely available, it shouldn't pose a problem :)

To get quickly started on a new system, just install setuptools and then install pip. That's the bare minimum to required install Tox and Cookiecutter. To install them, just run this in your shell or command prompt:

pip install tox cookiecutter

Usage and options

This template is more involved than the regular cookiecutter-pypackage.

First generate your project:

cookiecutter gh:ionelmc/cookiecutter-pylibrary

You will be asked for these fields:


Fields that work together usually use the same prefix. If you answer "no" on the first one then the rest won't have any effect so just ignore them. Maybe in the future cookiecutter will allow option hiding or something like a wizard.

Field Default Description
"Ionel Cristian Maries"

Main author of this library or application (used in AUTHORS.rst and

Can be set in your ~/.cookiecutterrc config file.


Contact email of the author (used in AUTHORS.rst and

Can be set in your ~/.cookiecutterrc config file.


Website of the author (used in AUTHORS.rst).

Can be set in your ~/.cookiecutterrc config file.


GitHub user name of this project (used for GitHub link).

Can be set in your ~/.cookiecutterrc config file.

Verbose project name, used in headings (docs, readme, etc).
Use "no" for no hosting (various links will disappear). You can also use "" and such but various things will be broken (like Travis configuration).
Repository name on GitHub (and project's root directory name).
Python package name (whatever you would import).
PyPI distribution name (what you would pip install).
"An example package [...]"
One line description of the project (used in README.rst and
Release date of the project (ISO 8601 format) default to today (used in CHANGELOG.rst).
Copyright year (used in Sphinx
Release version (see .bumpversion.cfg and in Sphinx

Support C extensions (will slightly change the outputted Available options:

  • "yes" - to generate a Python C extension
  • "cffi" - to generate CFFI bindings against a C library
  • "cython" - to generate a Cython extension
Make C extensions optional (will allow your package to install even if extensions can't be compiled)

Enables wheel publishing to by using tox-wheel and manylinux1.

You should only use this with c_extension_support. If your project produces universal wheels this won't work well.

Enable the test matrix generator script. If you don't have a huge number of test environments then probably you don't need this.

Enable this to have a separate env for measuring coverage. Indicated if you want to run doctests or collect tests from src with pytest.

Note that test_matrix_separate_coverage == 'no' only works if you also have test_matrix_configurator == 'no'.

Whether to use pytest-runner for python test. Note that this will also add to setup_requires if a test-runner is needed.

Enables the use of setuptools-scm. You can continue using bumpversion with this enabled.

Recommended if you use c_extension_test_pypi == 'yes' as it will publish unique wheels for each commit.


Collect tests that are inside the package (in other works, tests that are installed with the package).

The outside of package tests directory will still exist and be collected.

linter "flake8" Linter to use for tox -e check. Available options: flake8 or pylama
pre_commit "no" Enable basic pre-commit configuration.

Option to enable a CLI (a bin/executable file). Available options:

  • plain - a very simple command.
  • argparse - a command implemented with argparse.
  • click - a command implemented with click - which you can use to build more complex commands.
  • no - no CLI at all.
Name of the CLI bin/executable file (set the console script name in
"BSD license"

License to use. Available options:

  • BSD license
  • MIT license
  • ISC license
  • Apache Software License 2.0

What license to pick?

Enable pushing coverage data to Coveralls and add badge in README.rst.

Enable pushing coverage data to Codecov and add badge in README.rst.

Note: Doesn't support pushing C extension coverage yet.

Add a Scrutinizer badge in README.rst.

Add a Codacy badge in README.rst.

Note: After importing the project in Codacy, find the hexadecimal project ID from settings and replace it in badge URL

Add a CodeClimate badge in README.rst.
Have Sphinx documentation.

What Sphinx theme to use.

Suggested alternative: sphinx-py3doc-enhanced-theme for a responsive theme based on the Python 3 documentation.


Set to "yes" if you want to enable doctesting in the docs environment. Works best with test_matrix_separate_coverage == 'no'.

Read more about doctest support in Sphinx.

Leave as default if your documentation will be hosted on readthedocs. If your documentation will be hosted elsewhere (such as GitHub Pages or GitLab Pages), enter the top-level URL.
By default, this will insert links to your project's page on Note that if your package is not (yet) on PyPI, this will cause tox -e docs to fail. If you choose "no", then these links will not be created.
If you specifically want to be sure your package will never be accidentally uploaded to PyPI, you can pick "yes".
If you want the Travis-CI badge and configuration.

Enables OSX support in the Travis-CI configuration. To keep things simple and easy to understand only Brew Python 2 and 3 will be used.

You probably want to enable this if you use c_extension_test_pypi == 'yes'.

If you want the AppVeyor badge and configuration.
If you want the badge and configuration.

The testing (tox.ini and .travis.yml) configuration is generated from templates. For your convenience there's an initial bootstrap tox.ini, to get the initial generation going just run:


You can later regenerate tox.ini and .travis.yml by running (if you enabled the test_matrix_configurator option):

tox -e bootstrap

After this you can create the initial repository (make sure you create an empty Github project):

git init .
git add .
git commit -m "Initial skel."
git remote add origin
git push -u origin master


Developing the project

To run all the tests, just run:


To see all the tox environments:

tox -l

To only build the docs:

tox -e docs

To build and verify that the built package is proper and other code QA checks:

tox -e check

Releasing the project

Before releasing your package on PyPI you should have all the tox environments passing.

Version management

This template provides a basic bumpversion configuration. It's as simple as running:

  • bumpversion patch to increase version from 1.0.0 to 1.0.1.
  • bumpversion minor to increase version from 1.0.0 to 1.1.0.
  • bumpversion major to increase version from 1.0.0 to 2.0.0.

You should read Semantic Versioning 2.0.0 before bumping versions.

Building and uploading

Before building dists make sure you got a clean build area:

rm -rf build
rm -rf src/*.egg-info


Dirty build or egg-info dirs can cause problems: missing or stale files in the resulting dist or strange and confusing errors. Avoid having them around.

Then you should check that you got no packaging issues:

tox -e check

And then you can build the sdist, and if possible, the bdist_wheel too:

python clean --all sdist bdist_wheel

To make a release of the project on PyPI, assuming you got some distributions in dist/, the most simple usage is:

twine upload --skip-existing dist/*.whl dist/*.gz dist/*.zip

In ZSH you can use this to upload everything in dist/ that ain't a linux-specific wheel (you may need setopt extended_glob):

twine upload --skip-existing dist/*.(whl|gz|zip)~dist/*linux*.whl

For making and uploading manylinux1 wheels you can use this contraption:

docker run --rm -itv $(pwd):/code bash -c 'set -eux; cd code; rm -rf wheelhouse; for variant in /opt/python/*; do rm -rf dist build *.egg-info && $variant/bin/python clean --all bdist_wheel; auditwheel repair dist/*.whl; done; rm -rf dist build *.egg-info'
twine upload --skip-existing wheelhouse/*.whl
docker run --rm -itv $(pwd):/code bash -c 'set -eux; cd code; rm -rf wheelhouse; for variant in /opt/python/*; do rm -rf dist build *.egg-info && $variant/bin/python clean --all bdist_wheel; auditwheel repair dist/*.whl; done; rm -rf dist build *.egg-info'
twine upload --skip-existing wheelhouse/*.whl


twine is a tool that you can use to securely upload your releases to PyPI. You can still use the old python register sdist bdist_wheel upload but it's not very secure - your PyPI password will be sent over plaintext.



Questions & answers

There's no Makefile?

Sorry, no Makefile yet. The Tox environments stand for whatever you'd have in a Makefile.

Why does tox.ini have a passenv = *?

Tox 2.0 changes the way it runs subprocesses - it no longer passes all the environment variables by default. This causes all sorts of problems if you want to run/use any of these with Tox: SSH Agents, Browsers (for Selenium), Appengine SDK, VC Compiler and so on.

cookiecutter-pylibrary errs on the side of convenience here. You can always remove passenv = * if you like the strictness.

Why is the version stored in several files (pkg/,, docs/

We cannot use a metadata/version file [1] because this template is to be used with both distributions of packages (dirs with and modules (simple .py files that go straight in site-packages). There's no good place for that extra file if you're distributing modules.

But this isn't so bad - bumpversion manages the version string quite neatly.

[1]Example, an file.

Not Exactly What You Want?

No way, this is the best. 😜

If you have criticism or suggestions please open up an Issue or Pull Request.