{ "info": { "author": "Noi Sek", "author_email": "noi.t.sek@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Flask", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "|Build Status| |Coverage Status|\r\n\r\n``Flask-MicroServices``\r\n=======================\r\n\r\nFlask-MicroServices is a simple, lightweight attempt at bringing self\r\ncontained module hierarchy to Flask. Better project organization through\r\nseparation of concerns, isolating the different sections of your app\r\ninto separate modules, or 'microservices'.\r\n\r\nAn opinionated, but minimal approach to higher maintainability with\r\nFlask.\r\n\r\nFeatures\r\n~~~~~~~~\r\n\r\n- Django style route definitions\r\n- Simple, modular, microservices inspired architecture\r\n- Dynamic, overridable resolution of Static / Template directories\r\n\r\nProblems this plugin solves:\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n- Allow Blueprint defined template folders to override parent\r\n templates, rather than the other way around\r\n- Allow Blueprint defined static folders to resolve from and override\r\n ``/static``, rather than having to define individual\r\n ``/static_module_name`` folders\r\n- Enable modular, but centralized definition of routes with a cleaner\r\n syntax so that you aren't forced to hunt for ``@app.route()``\r\n decorators or use the arcane blueprint syntax in complex projects\r\n- Allow you to drop in / drop out sections of functionality at will\r\n just by passing the name of the module for portability, testing, and\r\n modularity\r\n\r\nFlask-MicroServices is not exceptionally complex. In fact, it is quite\r\nsmall-- 200-ish lines of code, but it can bring a high level of\r\nreasonability to the way you write your Flask applications.\r\n\r\nUsage\r\n~~~~~\r\n\r\nCheck out the example project at `./example `__, or read below\r\nfor a minimal example use-case.\r\n\r\n- `Project Layout <#project-layout>`__\r\n- ```__init__.py`` <#approot-init>`__\r\n- ``modules/``\r\n\r\n - ``home/``\r\n - ``static/``\r\n\r\n - ```file.txt`` <#module-static-file>`__\r\n\r\n - ``templates/``\r\n\r\n - ```main.html`` <#module-template>`__\r\n\r\n - ```__init__.py`` <#module-init>`__\r\n - ```urls.py`` <#module-urls>`__\r\n - ```views.py`` <#module-views>`__\r\n\r\nProject Layout\r\n^^^^^^^^^^^^^^\r\n\r\nApproot Init\r\n''''''''''''\r\n\r\n``project_root/appname/__init__.py``\r\n\r\nYou don't necessarily *have* to define your app within ``__init__.py``,\r\nbut this is how we will initialize our app for the purpose of this\r\nexample.\r\n\r\n.. code:: python\r\n\r\n from flask_microservices import MicroServicesApp\r\n\r\n app = MicroServicesApp(__name__)\r\n\r\n enabled_modules = [\r\n # Normally, we'd define more modules to enable:\r\n\r\n # 'home',\r\n # 'forum',\r\n # 'settings',\r\n\r\n # We will enable just one, for now:\r\n\r\n 'admin'\r\n ]\r\n\r\n # By default, this will assume your modules directory is \"./modules\" if a second argument is not provided.\r\n app.register_urls(enabled_modules)\r\n app.run()\r\n\r\nModule Init\r\n^^^^^^^^^^^\r\n\r\n``project_root/appname/admin/__init__.py``\r\n\r\nThis is the heart of every module, and is required for the app to be\r\nable to enable it.\r\n\r\n.. code:: python\r\n\r\n from flask_microservices import Router\r\n from . import urls\r\n\r\n MODULE_NAME = 'admin'\r\n IMPORT_NAME = __name__\r\n\r\n # These blueprints are what is collected when you run app.register_urls()\r\n blueprint = Router.create_blueprint(MODULE_NAME, IMPORT_NAME)\r\n blueprint.register_urls(urls.urlpatterns)\r\n\r\nModule Urls\r\n^^^^^^^^^^^\r\n\r\n``project_root/appname/admin/urls.py``\r\n\r\nYour URL definitions for each module go here. Routes defined here follow\r\nall the normal patterns of\r\n```@app.route()`` `__,\r\nwith the exception of ``endpoint`` being renamed to ``name``, and the\r\norder of ``view_func`` and ``name`` being reversed.\r\n\r\nWhen a name is provided here, as with a normal blueprint it will become\r\nnamespaced. A value of ``name='home'`` will become resolveable with\r\n``url_for('admin.home')``.\r\n\r\n.. code:: python\r\n\r\n from flask_microservices import url\r\n from . import views\r\n\r\n urlpatterns = [\r\n url('/admin/', view_func=views.admin_panel, name='home'),\r\n\r\n ## Example URLs:\r\n\r\n ### Minimal:\r\n # url('/admin/simple/', view_func=views.admin_simple)\r\n\r\n ### Advanced\r\n # url('/admin/roles/add/', view_func=views.admin_panel_roles_add, name='role_add', methods=['GET', 'POST']),\r\n # url('/admin/roles/edit/', view_func=views.admin_panel_roles_edit, name='role_edit', methods=['GET', 'POST']),\r\n ]\r\n\r\nModule Views\r\n^^^^^^^^^^^^\r\n\r\n``project_root/appname/admin/views.py``\r\n\r\nThis is where your views are defined. As your project scales farther,\r\nyou may want to separate your logic into files such as ``a.py``,\r\n``b.py``, and import them into your ``views.py`` with\r\n``from . import a, b`` in order to make them visible to ``urls.py``.\r\n\r\n.. code:: python\r\n\r\n from flask import render_template\r\n from ExampleApp.ExampleWrappers import admin_access_required\r\n\r\n @admin_access_required\r\n def admin_panel():\r\n return render_template('admin/main.html')\r\n\r\nModule Template\r\n^^^^^^^^^^^^^^^\r\n\r\n``project_root/appname/admin/templates/admin/main.html``\r\n\r\nTemplates folder resolves as normal. The ``MicroServicesApp`` instance\r\nwill check all module template directories before trying to resolve from\r\nthe root template folder. An important caveat to this approach is to\r\nremember that when two modules both possess conflicting templates, they\r\nwill be resolved in the order that they were defined in the\r\n``enabled_modules`` value that you passed to ``app.register_urls()``.\r\n\r\n.. code:: html\r\n\r\n \r\n

Holy cow!

\r\n

If the router was unable to find this file, then it would try your root level templates folder at `project_root/appname/templates/admin/main.html` before failing.

\r\n \r\n\r\nModule Static File\r\n^^^^^^^^^^^^^^^^^^\r\n\r\n``project_root/appname/admin/static/file.txt``\r\n\r\nStatic folder resolves as normal. The ``MicroServicesApp`` instance will\r\nbehave with respect to static files in an identical manner to how it\r\nhandles template files. See `above <#module-views>`__ for caveats.\r\n\r\n::\r\n\r\n I am a file! If I could not be found, the Router would attempt to find `project_root/appname/static/file.txt` before 404'ing.\r\n\r\n.. |Build Status| image:: https://travis-ci.org/NoiSek/Flask-MicroServices.svg?branch=master\r\n :target: https://travis-ci.org/NoiSek/Flask-MicroServices\r\n.. |Coverage Status| image:: https://coveralls.io/repos/github/NoiSek/Flask-MicroServices/badge.svg?branch=master\r\n :target: https://coveralls.io/github/NoiSek/Flask-MicroServices?branch=master", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/noisek/Flask-MicroServices", "keywords": "Flask,Django,Routes,Routing,URLs,Templates,Templating,Microservices", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "Flask-MicroServices", "package_url": "https://pypi.org/project/Flask-MicroServices/", "platform": "any", "project_url": "https://pypi.org/project/Flask-MicroServices/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/noisek/Flask-MicroServices" }, "release_url": "https://pypi.org/project/Flask-MicroServices/0.34.5/", "requires_dist": null, "requires_python": null, "summary": "Self contained modules and Django style URL routing for Flask.", "version": "0.34.5" }, "last_serial": 2600999, "releases": { "0.34.5": [ { "comment_text": "", "digests": { "md5": "16f3bcd844c3184622d42aab9c212f25", "sha256": "9531c16d0110c4b53dd3c97f4f7bfab4d127583419ea242187eb536fa2c0c682" }, "downloads": -1, "filename": "Flask_MicroServices-0.34.5-py3-none-any.whl", "has_sig": false, "md5_digest": "16f3bcd844c3184622d42aab9c212f25", "packagetype": "bdist_wheel", "python_version": "any", "requires_python": null, "size": 11230, "upload_time": "2017-01-27T01:11:16", "url": "https://files.pythonhosted.org/packages/59/74/2588926c62d1cc91118117ab72f31a7b31c5d61c14c29e0d8cbbab609977/Flask_MicroServices-0.34.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d167f582884a3e03e5c28275a7a90b42", "sha256": "60da815a4d1c4bd692855247729e2083815934d734f6e9862431a006029c931b" }, "downloads": -1, "filename": "Flask-MicroServices-0.34.5.zip", "has_sig": false, "md5_digest": "d167f582884a3e03e5c28275a7a90b42", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35266, "upload_time": "2017-01-27T00:59:00", "url": "https://files.pythonhosted.org/packages/d1/85/9e2c6ac5ce5f28adf42839665f5c3670e6317fb3313d318fcb384046fc4f/Flask-MicroServices-0.34.5.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "16f3bcd844c3184622d42aab9c212f25", "sha256": "9531c16d0110c4b53dd3c97f4f7bfab4d127583419ea242187eb536fa2c0c682" }, "downloads": -1, "filename": "Flask_MicroServices-0.34.5-py3-none-any.whl", "has_sig": false, "md5_digest": "16f3bcd844c3184622d42aab9c212f25", "packagetype": "bdist_wheel", "python_version": "any", "requires_python": null, "size": 11230, "upload_time": "2017-01-27T01:11:16", "url": "https://files.pythonhosted.org/packages/59/74/2588926c62d1cc91118117ab72f31a7b31c5d61c14c29e0d8cbbab609977/Flask_MicroServices-0.34.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d167f582884a3e03e5c28275a7a90b42", "sha256": "60da815a4d1c4bd692855247729e2083815934d734f6e9862431a006029c931b" }, "downloads": -1, "filename": "Flask-MicroServices-0.34.5.zip", "has_sig": false, "md5_digest": "d167f582884a3e03e5c28275a7a90b42", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35266, "upload_time": "2017-01-27T00:59:00", "url": "https://files.pythonhosted.org/packages/d1/85/9e2c6ac5ce5f28adf42839665f5c3670e6317fb3313d318fcb384046fc4f/Flask-MicroServices-0.34.5.zip" } ] }