Awesome Open Source
Awesome Open Source

=========================== cookiecutter-flask-pythonic

.. image:: :target:

Forked from cookiecutter_ template for a Python package. Forked from audreyr/cookiecutter-pypackage_ + tony/cookiecutter-pypackage-pythonic_.

It is inspired by flask_ and werkzeug's project style patterns. It is used on the tmuxp, cihai-python_ and vcspull_ projects. The app object is based on early versions pypa/warehouse, when it used werkzeug (see warehouse's old app object_).

  • Free software: BSD license
  • Vanilla testing setup with unittest and python test
  • Travis-CI_: Ready for Travis Continuous Integration testing
  • Tox_ testing: Setup to easily test for Python 2.6, 2.7, 3.3
  • Sphinx_ docs: Documentation ready for generation with, for example, ReadTheDocs_. Note: You can install sphinx docs requirements with $ pip install -r docs/requirements.txt.

.. _warehouse's old app object:

Additions and changes

  • (feature) app factory can be configured with ini, yaml or json (pypa/warehouse, cihai style) and by specifying options via CLI. Flask-Script only supports -c config_file. Application factory can be wired to support option args and config file (pypa/warehouse, cihai)
  • (feature / removal) - use flask testing client_ for tests, remove dependency on flask-testing_.
  • (feature) config file declaratively pulls blueprints from python paths add them in the app factory.
  • (coverage) unittests against flask api, blueprint example module.

.. _pypa/warehouse: .. _cihai: .. _flask testing client: .. _flask-testing:


- `flask`_/`werkzeug`_-style testsuites. See `werkzeug testsuite`_ on
- Use ```` to run all tests, or pass in arguments to test a
  particular ``TestSuite``, ``TestCase`` or ``Test``:

  .. code-block:: bash

      $ ./
      $ ./ yourpackage
      $ ./ repo_name.repo_name  # package_name.TestSuite
      $ ./ yourpackage.testsuite.test_something
      $ ./ testsuite.test_something
      $ ./ test_something
      $ ./ test_something test_something_docstring

- ```` downloads ``unittest2`` for python 2.6.

Python 2.7+3.3
  • .. code-block:: python

    from __future__ import absolute_import, division, print_function, \
        with_statement, unicode_literals
  • repo_name/ module (derived from flask, werkzeug and jinja2.) Why a compatibility module? See Armin Ronacher's post Porting to Python 3 Redux_.

.. _Porting to Python 3 Redux:


- ``repo_name/`` + ``repo_name/``: Metadata in
  ``repo_name/`` e.g. ``__title__``, ``__author__`` can be
  accessed via:

  .. code-block:: python

      >>> about = {}
      >>> with open("repo_name/") as fp:
      >>>     exec(, about)
      >>> print(about['__title__'])
      Your project name

  Keeps ```` and ``doc/`` in sync with package metadata.
  pypi and readthedocs distributions build off the latest package data.

  This method avoids cost of tokenizing and importing python file and
  avoids encountering potential import errors that may arise. It simply
  opens a vanilla python file and evals it.

  Derived from `pypa/warehouse`_.

- Relative imports in ``repo_name/``.
- Relative imports in ``repo_name/testsuite/``.
- Relative imports in ``repo_name/testsuite/{{ cookiecutter.package_name }}.py``.

.. _pypa/warehouse:


- ``README.rst`` reStructuredText table for project information.
- vim modelines for ``rst`` in ``TODO`` and ``CHANGELOG``.
- ``docs/requirements.txt``, which can be targetted to install `sphinx
  changelog`_ package on `ReadTheDocs`. It will also trigger `-r
- `sphinx changelog`_ module, (imitation of `sqlalchemy`_, see `sqlalchemy
- Add ``TODO`` and ``docs/roadmap.rst``.
- Rename ``CHANGELOG.rst`` -> ``CHANGELOG``.
- Add ``docs/api.rst`` for documentation of API code. Initial class
  imported with docstring example.
- Automatically generate header spacing based on length of
  ``cookiecutter`` variables.

Example data
  • Example TestCase.
  • Example Class w/ docstrings.

.. _flask: .. _werkzeug: .. _werkzeug testsuite: .. _sqlalchemy: .. _sqlalchemy changelog: .. _sphinx changelog: .. _cookiecutter: .. _cookiecutter-pypackage: .. _How can I get the version defined in setuptools in my package?:


Install cookiecutter_:

.. code-block:: bash

$ sudo pip install cookiecutter

Generate a Python package project:

.. code-block:: bash

$ cookiecutter


  • Create a repo and put it there.
  • Add the repo to your Travis-CI_ account.
  • Add the repo to your ReadTheDocs_ account + turn on the ReadTheDocs service hook.
  • Release your package the standard Python way. Here's a release checklist:

Not Exactly What You Want?

Don't worry, you have options:

Similar Cookiecutter Templates

* `audreyr/cookiecutter-pypackage`_: Forked from
* `tony/cookiecutter-pypackage-pythonic`_: This package's fork. Includes
  python 2 + 3, sphinx, unit tests, and more.
* `sloria/cookiecutter-flask`_: A flask template with Bootstrap 3, asset
  bundling + minification, starter templates and user accounts.
* 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

.. _tony/cookiecutter-pypackage-pythonic:
.. _sloria/cookiecutter-flask:


.. code-block:: shell

   $ pip install -r dev-requirements.txt
   $ sniffer
   # edit any file in {{cookiecutter.repo_name}}
   # todo: add for one-time runs

Fork This / Create Your Own

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.

Or Submit a Pull Request

I also accept pull requests on this, if they're small, atomic, and if they
make my own packaging experience better.

.. _Travis-CI:
.. _Tox:
.. _Sphinx:
.. _ReadTheDocs:
.. _`Nekroze/cookiecutter-pypackage`:
.. _`audreyr/cookiecutter-pypackage`:
.. _`network`:
.. _`family tree`:
.. _tmuxp:
.. _vcspull:
.. _cihai-python:

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (55,531
template (546
flask (540
cookiecutter (51