{ "info": { "author": "Ozzy", "author_email": "cfhamlet@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython" ], "description": "# os-sanic\n\n[![Build Status](https://www.travis-ci.org/cfhamlet/os-sanic.svg?branch=master)](https://www.travis-ci.org/cfhamlet/os-sanic)\n[![codecov](https://codecov.io/gh/cfhamlet/os-sanic/branch/master/graph/badge.svg)](https://codecov.io/gh/cfhamlet/os-sanic)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/os-sanic.svg)](https://pypi.python.org/pypi/os-sanic)\n[![PyPI](https://img.shields.io/pypi/v/os-sanic.svg)](https://pypi.python.org/pypi/os-sanic)\n\nA framework to organize [Sanic](https://github.com/huge-success/sanic) project, make you focus on development.\n\n\n\n## Install\n\n ```\n pip install os-sanic\n ```\n\n## Usage\n\n* Create project\n\n Typically, a project contains management script, config file and a set of reusable apps. \n\n ```\n os-sanic startproject project --with-app example\n ```\n\n This command will create a new project with an example app in current directory with the following structure:\n\n ```\n project/\n \u251c\u2500\u2500 apps\n \u251c\u2500\u2500 __init__.py\n \u2502 \u251c\u2500\u2500 example\n \u2502 \u2502 \u251c\u2500\u2500 __init__.py\n \u2502 \u2502 \u251c\u2500\u2500 app.py\n \u2502 \u2502 \u251c\u2500\u2500 extension.py\n \u2502 \u2502 \u251c\u2500\u2500 handler.py\n \u2502 \u2502 \u251c\u2500\u2500 static\n \u2502 \u2502 \u2502 \u251c\u2500\u2500 README.txt\n \u251c\u2500\u2500 config.py\n \u2514\u2500\u2500 manager.py\n ```\n\n* Create app\n\n App is designed as reusable unit. Each app may has some extensions as pluggins for loading/dumping data, managing db connection when server starting up/down. It should has handlers for processing http/https/websocket requests. Routes(URIs to handlers) are necessary. Besides, [serving static files](https://sanic.readthedocs.io/en/latest/sanic/static_files.html) is also useful. You can check the ``example`` app for more details.\n \n \n ```\n python manage.py startproject first\n ```\n \n This command will create a app named 'first' in the apps directory. You should add the app package string into ``INSTALLED_APPS`` in the ``config.py`` manually to enable it.\n\n* Create app with full feature\n\n The sanic framework offering [Middleware](https://sanic.readthedocs.io/en/latest/sanic/middleware.html) and [Exception](https://sanic.readthedocs.io/en/latest/sanic/exceptions.html), they all can be used. The following command will create a app with middleware and error handlers.\n \n ```\n python manage.py startapp second --full-feature\n ```\n \n But, attention please, the middlewares and exception handler is not just working on \nblueprint scope right now(v18.12). They will affect on the whole project. [issue](https://github.com/huge-success/sanic/issues/37)\n \n* Show the project information\n\n ```\n python manage.py info\n ```\n\n* Start the server\n\n ```\n python manage.py run\n ```\n \n This command will load ``config.py`` and start the server. Use ``--help`` to seed more command line options.\n\n\n## Config\n\n* Server config\n\n The default config file is ``config.py``, parameters define here are used in server scope, can be accessed from the ``config`` member of ``Sanic`` instance, [more details](https://sanic.readthedocs.io/en/latest/sanic/config.html).\n \n* Install apps\n\n You can add app package string into ``INSTALLED_APPS`` in the ``config.py`` to make it work.\n \n ```\n INSTALLED_APPS = ['apps.examples', ]\n ```\n \n More verbose config can be written as follows:\n \n ```\n INSTALLED_APPS = [\n {\n 'name': 'example',\n 'package': 'apps.example',\n 'url_prefix': '/example',\n }\n ]\n ```\n - ``name``: the app name, if not set will use ``package``'s last fragment\n - ``package``: the app's package\n - ``url_prefix``(alias ``prefix``): use this as the app's views prefix otherwise use app name\n - ``config``: app's config file, same as the ``app.py`` file, but will cover the parameters defined in ``app.py``.\n \n* App definition\n\n App is defined in the ``app.py``. ``EXTENSIONS``, ``ROUTES`` and ``STATICS`` are the main components.\n \n - ``EXTENSIONS`` are used as plugin mechanism. Can be used for loadding/dumping data, managing db connection when server staring up/down. ``name`` and ``extension_class`` are necessary, other parameters will pass to extension instance's config.\n \n ```\n EXTENSIONS = [\n {\n 'name': 'Example',\n 'extension_class': '.extension.Example',\n 'key1', 'value1',\n }\n ]\n ```\n \n - ``ROUTES`` are used for specifying handlers for different URIs. All [built-in parameters](https://sanic.readthedocs.io/en/latest/sanic/routing.html) of route definition can be used. \n\n \n ````\n ROUTES = [\n ('/e1', '.handler.ExampleView'),\n ('/e2', '.handler.handle_post', ['post']),\n ('/e3', '.handler.handle_websocket', 'websocket', None, True)\n ]\n ````\n \n \n More verbose style which can pass custom parameters: \n \n\n ```\n ROUTES = [\n {\n 'uri': '/',\n 'handler': '.view.ExampleView',\n 'costom_key': 'custom_value',\n }\n ]\n ```\n\n - ``STATICS`` are used for [serving static files](https://sanic.readthedocs.io/en/latest/sanic/static_files.html). ``file_or_directory`` can be absolute or relative path base on the appliction runtime config path.\n\n ```\n STATICS = [\n {\n 'uri': '/static',\n 'file_or_directory': '.',\n }\n ]\n ```\n\n\n## APIs\n\n* Handler\n\n The handler can be normal function, sanic [``HTTPMethodView``](https://sanic.readthedocs.io/en/latest/sanic/class_based_views.html) class or sanic [``CompositionView``](https://sanic.readthedocs.io/en/latest/sanic/class_based_views.html#using-compositionview) instance. The parameters defined in the ``ROUTES`` will be attached to a config object. If you use ```HTTPMethodView``, the config can be accessed from the View class.\n \n ```\n from sanic.views import HTTPMethodView\n \n class ExampleView(HTTPMethodView):\n \n def get(self, request):\n self.config.key1\n ...\n ```\n\n* Extension Class\n\n The extenion class must inherit from ``os_sanic.extension.Extension``.\n\n The base class's members are ``config``, ``application`` and ``logger``\n\n - ``config``: if you define extra parameters in the ``EXTENSIONS``, they will be attached to this config object\n - ``application``: current application object, can be used for accessing all the project apps\n - ``logger``, the built-in logger object\n\n\n The extension class has two usefull methods invoked by the framework: ``setup``, ``cleanup``. They all can be sync or async.\n\n - ``setup``: called before server start\n - ``cleanup``: called after server stop, if there are multi extensions configured in ``EXTENSIONS``, the cleanup methods execute order will from last extension to the first\n\n* application object\n\n The application object represent the each individual app\n \n - it is a member of extension instance:\n \n ```\n from os_sanic.extension import Extension\n\n class Example(Extension):\n\n def setup(self):\n self.application\n ...\n ```\n \n - it can be accessed in the view class\n \n ```\n from sanic.views import HTTPMethodView\n\n class ExampleView(HTTPMethodView):\n\n def get(self, request):\n self.application\n ...\n ```\n \n - you can get extension instance by:\n \n ```\n application.get_extension('extension_name')\n ```\n\n or get other app's extension\n\n ```\n application.get_extension('app_name/extension_name')\n ```\n\n - get app relative logger\n \n ```\n application.get_logger('logger_name')\n ```\n\n - get sanic instance(it is the same object ``request.app`` in the view)\n \n ```\n application.sanic\n ```\n\n\n## Unit Tests\n\n ```\n tox\n ```\n\n## License\n\nMIT licensed.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/cfhamlet/os-sanic", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "os-sanic", "package_url": "https://pypi.org/project/os-sanic/", "platform": "", "project_url": "https://pypi.org/project/os-sanic/", "project_urls": { "Homepage": "https://github.com/cfhamlet/os-sanic" }, "release_url": "https://pypi.org/project/os-sanic/0.1.7/", "requires_dist": null, "requires_python": ">=3.6", "summary": "A framework to simplify Sanic daemon development.", "version": "0.1.7" }, "last_serial": 4743731, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "f8575b4a80f98d9a4c9181066e0fad43", "sha256": "bfb9cd551eab280a30e3de1f2bdf2636055e4cddd6a5dc1e8ba13a4a5fa67060" }, "downloads": -1, "filename": "os-sanic-0.1.0.tar.gz", "has_sig": false, "md5_digest": "f8575b4a80f98d9a4c9181066e0fad43", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 17132, "upload_time": "2019-01-14T12:20:38", "url": "https://files.pythonhosted.org/packages/3b/68/d9c8f0001ce79ee9f55bd85212608230f6da434cbd03188f9f08d1579fba/os-sanic-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "9110669e512deba1ed04db2b971c5db5", "sha256": "1fd4466231050958f5f7043e6a6c352fd2bde305257530923d3ddca4bac333c1" }, "downloads": -1, "filename": "os-sanic-0.1.1.tar.gz", "has_sig": false, "md5_digest": "9110669e512deba1ed04db2b971c5db5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21122, "upload_time": "2019-01-16T09:28:55", "url": "https://files.pythonhosted.org/packages/b5/ca/77dd51af187dd7a21adaa3dd4f53284c5bc7d29c782e4c15c8cbffd64ff6/os-sanic-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "0878284521b2653beb354d17c1cd6234", "sha256": "6d01832e09560b57f130234f9fb4a99665e8af76829df312e1931e8dacbcab5d" }, "downloads": -1, "filename": "os-sanic-0.1.2.tar.gz", "has_sig": false, "md5_digest": "0878284521b2653beb354d17c1cd6234", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21358, "upload_time": "2019-01-17T13:58:11", "url": "https://files.pythonhosted.org/packages/74/d8/07ab50f3f40c7d56184d26d97780d046660e0c8a7de6459c3520f06ff5f2/os-sanic-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "dd149d986cd5b92007ded73e159699d6", "sha256": "aec32a7299f8beb3d46ae5010a846bec388e6680a3313e1c8ed9eb16ad38caeb" }, "downloads": -1, "filename": "os-sanic-0.1.3.tar.gz", "has_sig": false, "md5_digest": "dd149d986cd5b92007ded73e159699d6", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21267, "upload_time": "2019-01-18T09:51:04", "url": "https://files.pythonhosted.org/packages/0a/7d/438a4397dc21e032eb8a3b89155ec31ead7a23ac4c0e10756cd483ff8e79/os-sanic-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "c6570027bad6ffe9e58c3e4eb5419fd3", "sha256": "8232b343ee25b448920a4f757fe261cf570226a48d1a5b82223bf5d6a46ecb5a" }, "downloads": -1, "filename": "os-sanic-0.1.4.tar.gz", "has_sig": false, "md5_digest": "c6570027bad6ffe9e58c3e4eb5419fd3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21469, "upload_time": "2019-01-20T12:44:15", "url": "https://files.pythonhosted.org/packages/34/a6/5195e6d96b492059d901d482f0cf1457e721d81d7ccbd4c652c5a7c8ce95/os-sanic-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "f4690d3fd211af50d43a684312b26912", "sha256": "c8022799cea2de76bde5a3a106fe5896a12753102bc4b2069915d92995774bd3" }, "downloads": -1, "filename": "os-sanic-0.1.5.tar.gz", "has_sig": false, "md5_digest": "f4690d3fd211af50d43a684312b26912", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21119, "upload_time": "2019-01-21T13:44:27", "url": "https://files.pythonhosted.org/packages/ad/16/50f7fd13328f6d384222ad6cda4634683ee7d69270183093ab987af92285/os-sanic-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "04a22ca8791325dce11f068eb43b249a", "sha256": "c5290d1a9dc790ab640caa924ba6e6c6394d666018ae4a7bf5b3cfcc59309063" }, "downloads": -1, "filename": "os-sanic-0.1.6.tar.gz", "has_sig": false, "md5_digest": "04a22ca8791325dce11f068eb43b249a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21139, "upload_time": "2019-01-22T03:37:09", "url": "https://files.pythonhosted.org/packages/43/ba/08692b42f60713a9f1daebeb3d807b2895a40b2a5531fba02428b2ac7329/os-sanic-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "bc8dd4dcccf4fb9c7802d4a47026f50e", "sha256": "9b20fad37c11a5806627eadb3f83c377a64cca2a7795cacc3b233147cf614354" }, "downloads": -1, "filename": "os-sanic-0.1.7.tar.gz", "has_sig": false, "md5_digest": "bc8dd4dcccf4fb9c7802d4a47026f50e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 24094, "upload_time": "2019-01-26T13:56:25", "url": "https://files.pythonhosted.org/packages/ff/48/8df2879ecb53eae49b080eae38225e5fe4e344405e472468254d60404485/os-sanic-0.1.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bc8dd4dcccf4fb9c7802d4a47026f50e", "sha256": "9b20fad37c11a5806627eadb3f83c377a64cca2a7795cacc3b233147cf614354" }, "downloads": -1, "filename": "os-sanic-0.1.7.tar.gz", "has_sig": false, "md5_digest": "bc8dd4dcccf4fb9c7802d4a47026f50e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 24094, "upload_time": "2019-01-26T13:56:25", "url": "https://files.pythonhosted.org/packages/ff/48/8df2879ecb53eae49b080eae38225e5fe4e344405e472468254d60404485/os-sanic-0.1.7.tar.gz" } ] }