├── .gitignore ├── README.md ├── cookiecutter.json └── {{cookiecutter.app_name}} ├── .gitignore ├── LICENSE ├── Makefile ├── Procfile ├── README.md ├── app.py ├── bin └── nosetests ├── docs ├── Makefile └── source │ ├── _static │ └── .gitkeep │ ├── _templates │ └── .gitkeep │ ├── _themes │ └── .gitkeep │ ├── authentication.rst │ ├── conf.py │ ├── getting_started.rst │ └── index.rst ├── setup.py └── {{cookiecutter.package_namespace}} ├── __init__.py └── {{cookiecutter.app_name}} ├── __init__.py ├── models ├── __init__.py └── user.py ├── modules └── __init__.py ├── settings.py ├── tests ├── __init__.py └── unit_tests.py ├── users.py └── utils └── __init__.py /.gitignore: -------------------------------------------------------------------------------- 1 | env/* 2 | .idea/ 3 | *.pyc 4 | venv/* 5 | coverage/* 6 | .DS_Store 7 | .coverage 8 | *.py[cod] 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Packages 14 | *.egg 15 | *.egg-info 16 | dist 17 | build 18 | eggs 19 | parts 20 | sdist 21 | develop-eggs 22 | .installed.cfg 23 | 24 | # Installer logs 25 | pip-log.txt 26 | 27 | # Unit test / coverage reports 28 | .coverage 29 | .tox 30 | nosetests.xml 31 | 32 | # Translations 33 | *.mo 34 | 35 | # Mr Developer 36 | .mr.developer.cfg 37 | .project 38 | .pydevproject 39 | 40 | docs/build 41 | pyramid.log 42 | pyramid.pid 43 | # vagrant 44 | .vagrant 45 | Vagrantfile 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cookiecutter-flaskrestful 2 | ========================= 3 | 4 | A FlaskRESTful template using cookiecutter to quickly create RESTful web API service. 5 | 6 | Using this template 7 | ------------------- 8 | To use this template, you need to have cookiecutter installed 9 | 10 | $ pip install cookiecutter 11 | $ cookiecutter https://github.com/sendgridlabs/cookiecutter-flaskrestful.git 12 | 13 | Start the service 14 | ----------------- 15 | Once generated, you can start service with 16 | 17 | $ python app.py 18 | 19 | License 20 | ------- 21 | MIT license included 22 | -------------------------------------------------------------------------------- /cookiecutter.json: -------------------------------------------------------------------------------- 1 | { 2 | "app_name": "myapi", 3 | "repo_name": "myapi", 4 | "year": 2013, 5 | "company_name": "SendGrid", 6 | "package_namespace": "sg", 7 | "project_short_description": "Short description of your project." 8 | } 9 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | var 14 | sdist 15 | develop-eggs 16 | .installed.cfg 17 | lib 18 | lib64 19 | 20 | # Installer logs 21 | pip-log.txt 22 | 23 | # Unit test / coverage reports 24 | .coverage 25 | .tox 26 | nosetests.xml 27 | 28 | # Translations 29 | *.mo 30 | 31 | # Mr Developer 32 | .mr.developer.cfg 33 | .project 34 | .pydevproject 35 | 36 | # Complexity 37 | output/*.html 38 | output/*/index.html 39 | 40 | # Sphinx 41 | docs/_build 42 | 43 | .webassets-cache 44 | 45 | # Virtualenvs 46 | env 47 | env* 48 | .env -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © {{ cookiecutter.year }} {{ cookiecutter.company_name }} 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/Makefile: -------------------------------------------------------------------------------- 1 | PATH:=bin/:${PATH} 2 | .PHONY: all clean cover doc test 3 | 4 | help: 5 | @echo "Available commands:" 6 | @echo " clean remove temp files and static generated docs" 7 | @echo " cover generate test coverage" 8 | @echo " doc generate internal doc" 9 | @echo " test run all tests" 10 | 11 | clean: 12 | find ./ -type f -name '*.pyc' -exec rm -f {} \; 13 | rm -rf cover .coverage 14 | rm -rf docs/build 15 | 16 | cover: 17 | ENV=test ./bin/nosetests -s -v --with-coverage --cover-html --cover-html-dir ./coverage 18 | 19 | test: 20 | ENV=test ./bin/nosetests -s --nologcapture 21 | 22 | all: clean 23 | 24 | doc: clean 25 | sphinx-build -b html docs/source docs/build/html 26 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn {{cookiecutter.project_name}}.main:app -b 0.0.0.0:$PORT -w 3 2 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/README.md: -------------------------------------------------------------------------------- 1 | {{ cookiecutter.app_name }} 2 | =========================== 3 | 4 | {{ cookiecutter.project_short_description}} 5 | 6 | 7 | Installation 8 | --- 9 | 10 | # install pip: 11 | $ sudo easy_install pip 12 | 13 | # install virtualenv: 14 | $ sudo easy_install virtualenv 15 | 16 | # inside your repo, create env and activate it: 17 | $ virtualenv env/ && . env/bin/activate 18 | 19 | # install required packages 20 | $ pip install -e . 21 | 22 | 23 | Documentation 24 | --- 25 | # generate new static doc 26 | $ make doc 27 | 28 | 29 | Testing 30 | --- 31 | # run all tests 32 | $ make test 33 | 34 | # check for tests coverage 35 | $ make cover 36 | 37 | Start Service 38 | --- 39 | 40 | # it will start on http://localhost:5000 41 | $ ENV=dev python app.py 42 | 43 | Example Usage 44 | --- 45 | 46 | $ curl 'localhost:5000/v1/users/' 47 | 48 | Deployment 49 | --- 50 | Provide deployment instruction here 51 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/app.py: -------------------------------------------------------------------------------- 1 | import werkzeug 2 | import gevent 3 | import os 4 | from flask import Flask 5 | from flask.ext.restful import Api 6 | from {{cookiecutter.package_namespace}}.{{cookiecutter.app_name}}.users import User, Users 7 | 8 | app = Flask(__name__) 9 | api = Api(app, prefix='/v1', catch_all_404s=True) 10 | 11 | # routing 12 | api.add_resource(Users, '/users') 13 | api.add_resource(User, '/users/') 14 | 15 | if __name__ == '__main__': 16 | app.run(debug=True) 17 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/bin/nosetests: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | This file was taken from nosetests and modified to include patch gevent before 4 | anything is done. This is mainly because of the threading module since both 5 | nose and coverage use threads and gevent needs to patch them before use. The 6 | other change was to remove nose specific versions. 7 | 8 | """ 9 | from gevent import monkey 10 | monkey.patch_all() 11 | __requires__ = 'nose' 12 | import sys 13 | from pkg_resources import load_entry_point 14 | 15 | sys.exit(load_entry_point('nose', 'console_scripts', 'nosetests')()) -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/StatsRESTAPI.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/StatsRESTAPI.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/StatsRESTAPI" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/StatsRESTAPI" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/source/_static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sendgridlabs/cookiecutter-flaskrestful/00e23ea7a9efd465e926fc774cca4191ffdf1918/{{cookiecutter.app_name}}/docs/source/_static/.gitkeep -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/source/_templates/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sendgridlabs/cookiecutter-flaskrestful/00e23ea7a9efd465e926fc774cca4191ffdf1918/{{cookiecutter.app_name}}/docs/source/_templates/.gitkeep -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/source/_themes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sendgridlabs/cookiecutter-flaskrestful/00e23ea7a9efd465e926fc774cca4191ffdf1918/{{cookiecutter.app_name}}/docs/source/_themes/.gitkeep -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/source/authentication.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Authentication 3 | ============== 4 | 5 | HTTP Basic Auth 6 | =============== 7 | 8 | All endpoints are protected by Basic Auth 9 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import sys 4 | 5 | ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) 6 | sys.path.append(ROOT_PATH) 7 | import sphinx_bootstrap_theme 8 | 9 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 10 | 'sphinxcontrib.httpdomain', 'sphinx.ext.extlinks', 11 | 'sphinx.ext.viewcode', 'sphinxcontrib.autohttp.flask'] 12 | 13 | # nitpicky = True 14 | autoclass_content = "both" 15 | source_suffix = '.rst' 16 | master_doc = 'index' 17 | project = u'{{cookiecutter.project_short_description}}' 18 | copyright = u'{{cookiecutter.year}}, {{cookiecutter.company_name}}' 19 | version = 'v1' 20 | pygments_style = 'sphinx' 21 | exclude_patterns = [] 22 | add_function_parentheses = True 23 | add_module_names = True 24 | 25 | html_domain_indices = False 26 | html_use_index = False 27 | html_theme = 'bootstrap' 28 | html_theme_path = sphinx_bootstrap_theme.get_html_theme_path() 29 | templates_path = ['_templates'] 30 | html_static_path = ['_static'] 31 | html_last_updated_fmt = '%b %d, %Y' 32 | html_show_sourcelink = False 33 | html_show_sphinx = False 34 | html_show_copyright = False 35 | html_title = "%s %s" % (project, version) 36 | html_logo = "" 37 | html_favicon = "" 38 | 39 | html_sidebars = { 40 | 'index': None, 41 | '**': ['localtoc.html', 'searchbox.html'] 42 | } 43 | 44 | html_theme_options = { 45 | # Navigation bar title. (Default: ``project`` value) 46 | # 'navbar_title': "Demo", 47 | 48 | # Tab name for entire site. (Default: "Site") 49 | 'navbar_site_name': "Endpoints", 50 | 51 | # A list of tuples containing pages or urls to link to. 52 | # Valid tuples should be in the following forms: 53 | # (name, page) # a link to a page 54 | # (name, "/aa/bb", 1) # a link to an arbitrary relative url 55 | # (name, "http://example.com", True) # arbitrary absolute url 56 | # Note the "1" or "True" value above as the third argument to indicate 57 | # an arbitrary url. 58 | 'navbar_links': [ 59 | ("Home", "index"), 60 | ("Getting Started", "getting_started") 61 | ], 62 | 63 | # Render the next and previous page links in navbar. (Default: true) 64 | 'navbar_sidebarrel': False, 65 | 66 | # Render the current pages TOC in the navbar. (Default: true) 67 | 'navbar_pagenav': False, 68 | 69 | # Global TOC depth for "site" navbar tab. (Default: 1) 70 | # Switching to -1 shows all levels. 71 | 'globaltoc_depth': -1, 72 | 73 | # Include hidden TOCs in Site navbar? 74 | # 75 | # Note: If this is "false", you cannot have mixed ``:hidden:`` and 76 | # non-hidden ``toctree`` directives in the same page, or else the build 77 | # will break. 78 | # 79 | # Values: "true" (default) or "false" 80 | 'globaltoc_includehidden': "false", 81 | 82 | # HTML navbar class (Default: "navbar") to attach to
element. 83 | # For black navbar, do "navbar navbar-inverse" 84 | 'navbar_class': "navbar navbar-inverse", 85 | 86 | # Fix navigation bar to top of page? 87 | # Values: "true" (default) or "false" 88 | 'navbar_fixed_top': "true", 89 | 90 | # Location of link to source. 91 | # Options are "nav" (default), "footer" or anything else to exclude. 92 | 'source_link_position': None, 93 | 94 | # Bootswatch (http://bootswatch.com/) theme. 95 | # 96 | # Options are nothing with "" (default) or the name of a valid theme 97 | # such as "amelia" or "cosmo". 98 | # 99 | # Note that this is served off CDN, so won't be available offline. 100 | 'bootswatch_theme': "flatly", 101 | 102 | # Choose Bootstrap version. 103 | # Values: "3" (default) or "2" (in quotes) 104 | 'bootstrap_version': "3", 105 | } 106 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/source/getting_started.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Getting Started 3 | =============== 4 | 5 | Fetch a resource 6 | ---------------- 7 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/docs/source/index.rst: -------------------------------------------------------------------------------- 1 | {{cookiecutter.app_name}} REST API Doc 2 | --------------------------------------- 3 | 4 | .. toctree:: 5 | getting_started 6 | authentication 7 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | required_packages = [ 4 | 'Cython==0.19.1', 5 | 'gevent==1.0dev', 6 | 'setuptools==1.1.6', 7 | 'Flask==0.10.1', 8 | 'Flask-RESTful==0.2.3', 9 | 'WTForms==1.0.5', 10 | 'boto==2.10.0', 11 | 'Fabric==1.6.1', 12 | 'Pygments==1.6', 13 | 'Sphinx==1.2b1', 14 | 'WTForms==1.0.4', 15 | 'Werkzeug==0.9.1', 16 | 'airbrake-flask==0.0.3', 17 | 'anyjson==0.3.3', 18 | 'coverage==3.6', 19 | 'docutils==0.10', 20 | 'gunicorn==17.5', 21 | 'livereload==1.0.0', 22 | 'mock==1.0.1', 23 | 'nose==1.3.0', 24 | 'python-memcached==1.53', 25 | 'requests==1.2.3', 26 | 'six==1.3.0', 27 | 'sphinx-bootstrap-theme==0.3.1', 28 | 'sphinxcontrib-httpdomain==1.1.9' 29 | ] 30 | 31 | setup( 32 | name='{{cookiecutter.package_namespace}}.{{cookiecutter.app_name}}', 33 | description='{{cookiecutter.project_short_description}}', 34 | version='0.0.1', 35 | packages=['{{cookiecutter.package_namespace}}', 36 | '{{cookiecutter.package_namespace}}.{{cookiecutter.app_name}}'], 37 | namespace_packages=['{{cookiecutter.package_namespace}}'], 38 | install_requires=required_packages, 39 | dependency_links=[('https://github.com/surfly/gevent/tarball/master#' 40 | 'egg=gevent-1.0dev')], 41 | extras_require={ 42 | 'test': [ 43 | 'nose==1.3.0', 44 | 'ddbmock==1.0.3', 45 | ] 46 | } 47 | ) 48 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) 2 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sendgridlabs/cookiecutter-flaskrestful/00e23ea7a9efd465e926fc774cca4191ffdf1918/{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/__init__.py -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sendgridlabs/cookiecutter-flaskrestful/00e23ea7a9efd465e926fc774cca4191ffdf1918/{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/models/__init__.py -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/models/user.py: -------------------------------------------------------------------------------- 1 | """ 2 | {{cookiecutter.project_name}} models. 3 | """ 4 | from flask.ext.sqlalchemy import SQLAlchemy 5 | 6 | db = SQLAlchemy() 7 | 8 | 9 | class User(db.Model): 10 | __tablename__ = 'users' 11 | 12 | id = db.Column(db.Integer, primary_key=True) 13 | username = db.Column(db.String, unique=True, nullable=False) 14 | email = db.Column(db.String, unique=False, nullable=False) 15 | password = db.Column(db.String, nullable=False) 16 | 17 | def __init__(self, username=None, email=None, password=None): 18 | self.username = username 19 | self.email = email 20 | self.password = password 21 | 22 | def __repr__(self): 23 | return ''.format(username=self.username) 24 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sendgridlabs/cookiecutter-flaskrestful/00e23ea7a9efd465e926fc774cca4191ffdf1918/{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/modules/__init__.py -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | class Config(object): 5 | SECRET_KEY = 'xxxxx' 6 | APP_DIR = os.path.abspath(os.path.dirname(__file__)) 7 | PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) 8 | 9 | 10 | class ProdConfig(Config): 11 | DEBUG = False 12 | SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' 13 | SQLALCHEMY_ECHO = False 14 | 15 | 16 | class DevConfig(Config): 17 | DEBUG = True 18 | DB_NAME = "test.db" 19 | # Put the db file in project root 20 | DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME) 21 | SQLALCHEMY_DATABASE_URI = "sqlite:///{0}".format(DB_PATH) 22 | SQLALCHEMY_ECHO = True 23 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sendgridlabs/cookiecutter-flaskrestful/00e23ea7a9efd465e926fc774cca4191ffdf1918/{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/tests/__init__.py -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/tests/unit_tests.py: -------------------------------------------------------------------------------- 1 | import json 2 | import unittest 3 | from nose.tools import assert_equal 4 | from {{cookiecutter.repo_name}}.main import create_app 5 | 6 | class Test{{cookiecutter.repo_name | capitalize}}(unittest.TestCase): 7 | 8 | def setUp(self): 9 | app = create_app("{{cookiecutter.repo_name}}.settings.DevConfig", 'dev') 10 | app.config['TESTING'] = True 11 | self.app = app.test_client() 12 | 13 | def test_add(self): 14 | '''An example test.''' 15 | assert_equal(1 + 1, 2) 16 | 17 | 18 | def json_response(response, code=200): 19 | '''Checks that the status code is OK and returns the json as a dict.''' 20 | assert_equal(response.status_code, code) 21 | return json.loads(response.data) 22 | 23 | if __name__ == '__main__': 24 | unittest.main() 25 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/users.py: -------------------------------------------------------------------------------- 1 | """ 2 | /v1/users/ endpoint 3 | """ 4 | from flask import request 5 | from flask.ext.restful import Resource 6 | 7 | 8 | class BaseUser(Resource): 9 | db = 'some shared functionality' 10 | 11 | 12 | class Users(BaseUser): 13 | def get(self): 14 | 15 | return 'get ok!' 16 | 17 | def post(self): 18 | data = request.json 19 | 20 | return data 21 | 22 | 23 | class User(BaseUser): 24 | def get(self, user_id): 25 | 26 | return {"a user ": user_id} 27 | -------------------------------------------------------------------------------- /{{cookiecutter.app_name}}/{{cookiecutter.package_namespace}}/{{cookiecutter.app_name}}/utils/__init__.py: -------------------------------------------------------------------------------- 1 | '''Helper utilities and decorators.''' 2 | from flask import session, flash 3 | from functools import wraps 4 | 5 | 6 | def flash_errors(form): 7 | '''Flash all errors for a form.''' 8 | for field, errors in form.errors.items(): 9 | for error in errors: 10 | flash("Error in the {0} field - {1}" 11 | .format(getattr(form, field).label.text, error), 'warning') 12 | 13 | 14 | def auth_required(test): 15 | '''Decorator that makes a view require authentication.''' 16 | 17 | @wraps(test) 18 | def wrap(*args, **kwargs): 19 | if 'auth_key' in session: 20 | return test(*args, **kwargs) 21 | else: 22 | raise Exception("authorization failed") 23 | 24 | return wrap 25 | --------------------------------------------------------------------------------