{ "info": { "author": "Maxim Dutkin", "author_email": "max@dutkin.ru", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "# M2Core web framework\n\n### Status\n[![Build Status](https://travis-ci.org/mdutkin/m2core.svg?branch=master)](https://travis-ci.org/mdutkin/m2core.svg?branch=master)\n\nM2Core is a framework build over Tornado web server. It helps you to build an effective REST API in a few minutes.\nWe use a mix of Tornado, SQLAlchemy and Redis. M2Core has lots of helpers to do you ordinary tasks while building handlers\nfor your REST API. Real benefits are achieved when you are making REST services in connection with PostgreSQL. Redis is used\nin order to cache access tokens, roles and role permissions, so each authorization check is made without PostgreSQL participation.\n\n\n### The list of main features:\n\n* **rights management (completely cached in Redis)**\n\n* **handy BaseModel mixin**\n\n* **a bunch of decorators for permissions check, try-catch block and etc.**\n\n* **automatic documentation in JSON per each method of each handler retrieved from docstrings**\n\n* **DB schema in JSON with custom fields (we use it somehow in our React form generators)**\n\n* **helper class for unit testing of REST API**\n\n\n\n## Installation\n\ninstall package in normal way via pip:\n\n```bash\npip install m2core\n```\n\nrequired packages will install automatically\n\n\n\n## Usage\n\nM2Core uses `tornado.options` / `tornado.define` to set up configuration. Here is a list of settings with default values:\n\n**Server options**\n\n| Option name | Description | Type | Default value |\n|--------------------|--------------------------------------------------------------------------------|:-----------:|----------------------------------|\n|debug | Tornado debug mode | bool | False |\n|config_name | Config name | str | config.py |\n|admin_role_name | Admin group name | str | admins |\n|default_role_name | Default user group with login permissions | str | users |\n|default_permission | Default permission | str | authorized |\n|xsrf_cookie | Enable or disable XSRF-cookie protection | str or bool | False |\n|cookie_secret | Tornado cookie secret | str | gfqeg4t023ty724ythweirhgiuwehrtp |\n|server_port | Tornado TCP server bind port | int | 8888 |\n|locale | Server locale for dates, times, currency and etc | str | ru_RU.UTF-8 |\n|json_indent | Number of `space` characters, which are used in json responses after new lines | int | 2 |\n|thread_pool_size | Pool size for background executor | int | 10 |\n|gen_salt | Argument for gen_salt func in bcrypt module | int | 12 |\n\n\n**DB options**\n\n| Option name | Description | Type | Default value |\n|----------------|----------------------------------------|:----:|---------------|\n|debug_orm | SQLAlchemy debug mode | bool | False |\n|pg_host | Database host | str | 127.0.0.1 |\n|pg_port | Database port | int | 5432 |\n|pg_port | Database port | int | 5432 |\n|pg_db | Database name | str | m2core |\n|pg_user | Database user | str | postgres |\n|pg_password | Database password | str | password |\n|pg_pool_size | Pool size for executor | int | 40 |\n|pg_pool_recycle | Pool recycle time in sec, -1 - disable | int | -1 |\n\n\n**Redis options**\n\n| Option name | Description | Type | Default value |\n|-------------|------------------------------|:----:|---------------|\n|redis_host | Redis host | str | 127.0.0.1 |\n|redis_port | Redis port | int | 6379 |\n|redis_db | Redis database number (0-15) | int | 0 |\n\n\nYou can place your settings in root folder and name it `config.py`, or place it wherever you want and pass relative path to this config file via\n`--config_name=my/cool/path/to/config.py` argument. You can read more about tornado.options [here](http://www.tornadoweb.org/en/stable/options.html).\nBy the way, **M2Core** also supports command-line parsing.\n\nHere is an [Example REST API sources](https://github.com/mdutkin/m2core/tree/master/example). In this example I tried to show most important **M2Core** features.\nAll modules are documented, you can read description of each function in sources.\n\nRights management in **M2Core** is quite simple. You implement your handlers with inheritance from `BaseHandler`, then do something like:\n\n```python\nfrom handlers import AdminUsersHandler\n\n\nm2core = M2Core()\nhuman_route = r'/users/:{id:int}'\nm2core.add_endpoint(human_route, AdminUsersHandler)\n# or like that\nm2core.add_endpoint_permissions(human_route, {\n 'get': [options.default_permission, 'get_user_info'],\n 'post': None,\n 'put': [options.default_permission, 'update_user_info'],\n 'delete': [options.default_permission, 'delete_user'],\n})\n```\n\nThis will set certain bunch of permissions per each method of each route you want. You may use the same handler again with different route with other permissions.\nFor further information read docs of `m2core.add_endpoint_permissions`.\n\nI should say a few words about url mask. It supports it's own rules and later generates url for Tornado. Url masks can be like:\n\n| Url mask | Params | Rule description |\n|---------------------------------------------------|:------:|------------------------------------------------------------------------------------------------|\n|/users/:{id} | :id | attribute, any type |\n|/users/:{id:int} | :id | int attribute, any length |\n|/users/:{id:int(2)} | :id | int attribute, length is 2 numbers |\n|/users/:{id:float} | :id | float attribute |\n|/users/:{id:float(3)} | :id | float attribute, length is 3 numbers including `,` |\n|/users/:{id:float(2,5)} | :id | float attribute, length is between 2 and 5 numbers including `,` |\n|/users/:{id:string} | :id | string, any length, without `/` symbol |\n|/users/:{id:string(2)} | :id | string, length is 2 symbols, without `/` symbol |\n|/users/:{id:bool} | :id | bool flag, accepts only `0` or `1` |\n|/users/:{id:int(0,\\[0-100\\])} | :id | int, any length (0), but value must be between `0` and `100` |\n|/users/:{id:float(0,\\[0-100\\])} | :id | float, any length (0), but value must be between `0` and `100` |\n|/users/:{id:string(0,\\[string1;string2;string3\\])} | :id | string, any length (0), but value must be in list of values: ('string1', 'string2', 'string3') |", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mdutkin/m2core", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "m2core", "package_url": "https://pypi.org/project/m2core/", "platform": "", "project_url": "https://pypi.org/project/m2core/", "project_urls": { "Homepage": "https://github.com/mdutkin/m2core" }, "release_url": "https://pypi.org/project/m2core/1.0.10/", "requires_dist": null, "requires_python": "", "summary": "M2Core REST API web framework", "version": "1.0.10" }, "last_serial": 3441761, "releases": { "1.0.10": [ { "comment_text": "", "digests": { "md5": "c01f5b8c0c634e67ef85230b5c9efd66", "sha256": "ee5be7f5bc6266c2f408a944f32f2025d54c904fb428631349f4637b937a446e" }, "downloads": -1, "filename": "m2core-1.0.10.tar.gz", "has_sig": false, "md5_digest": "c01f5b8c0c634e67ef85230b5c9efd66", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30236, "upload_time": "2017-12-25T11:40:17", "url": "https://files.pythonhosted.org/packages/f4/12/67bc36ab49a9502af47e2191e9cf11f0afef8e2c0cde6e9630eee8806fa2/m2core-1.0.10.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "261d79ea1ab24a70f766fecb74e50bb0", "sha256": "701ac7a62b3afa2af4f33d49025ff99608619afa198526f243986de3041d7f34" }, "downloads": -1, "filename": "m2core-1.0.3.tar.gz", "has_sig": false, "md5_digest": "261d79ea1ab24a70f766fecb74e50bb0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28061, "upload_time": "2017-10-16T08:45:43", "url": "https://files.pythonhosted.org/packages/49/9b/6cad285a14f42ee5cfc592180e1c6ebfd024b5ff9b0f00a0f357e422357a/m2core-1.0.3.tar.gz" } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "291e87d372446f3af4f63df34d37a9ac", "sha256": "415257b9cb10b6d7960f19d6eba666558e1070fd0d856a72c5284d1fde47eeba" }, "downloads": -1, "filename": "m2core-1.0.5.tar.gz", "has_sig": false, "md5_digest": "291e87d372446f3af4f63df34d37a9ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30457, "upload_time": "2017-11-07T08:31:28", "url": "https://files.pythonhosted.org/packages/af/2f/588d8487028671f260cf4f351423612bf7bb00b1c41155c19a11ec9454d0/m2core-1.0.5.tar.gz" } ], "1.0.7": [ { "comment_text": "", "digests": { "md5": "e08e8279e261f56ee47d3ad07038a027", "sha256": "cda26ae30aae5f7a53baa79b891a033320fb58e5ff3c0f2cb9ce1dd246c75e15" }, "downloads": -1, "filename": "m2core-1.0.7.tar.gz", "has_sig": false, "md5_digest": "e08e8279e261f56ee47d3ad07038a027", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30671, "upload_time": "2017-11-14T16:27:55", "url": "https://files.pythonhosted.org/packages/9c/e9/5f61d675271ecd080355a1a9c82027ecd93410aeff588329eeeef932aa8b/m2core-1.0.7.tar.gz" } ], "1.0.8": [ { "comment_text": "", "digests": { "md5": "fc9aeb885a5d3a89ff84b6974e941e6a", "sha256": "bcb7bb2d992e520c94ffeb9379926bf6b5dbc4627b568a2fcb1150a352756ca8" }, "downloads": -1, "filename": "m2core-1.0.8.tar.gz", "has_sig": false, "md5_digest": "fc9aeb885a5d3a89ff84b6974e941e6a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30769, "upload_time": "2017-12-04T15:38:48", "url": "https://files.pythonhosted.org/packages/69/7f/065aed4eb485068bfd28a53e4ce8c0d1fb0fca0577a2bfac56a1893b8db5/m2core-1.0.8.tar.gz" } ], "1.0.9": [ { "comment_text": "", "digests": { "md5": "43674062fa0b33e3bdf76706147a9643", "sha256": "cb38bf86a541ca202e7e7747ff9d467748de87e3562e4396ea7de92bd7c87c46" }, "downloads": -1, "filename": "m2core-1.0.9.tar.gz", "has_sig": false, "md5_digest": "43674062fa0b33e3bdf76706147a9643", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30235, "upload_time": "2017-12-21T15:23:42", "url": "https://files.pythonhosted.org/packages/f9/9f/a6c817cb8dca2038dbef7d6e25958f896656b69a8273ffa137d5781c3fe7/m2core-1.0.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c01f5b8c0c634e67ef85230b5c9efd66", "sha256": "ee5be7f5bc6266c2f408a944f32f2025d54c904fb428631349f4637b937a446e" }, "downloads": -1, "filename": "m2core-1.0.10.tar.gz", "has_sig": false, "md5_digest": "c01f5b8c0c634e67ef85230b5c9efd66", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30236, "upload_time": "2017-12-25T11:40:17", "url": "https://files.pythonhosted.org/packages/f4/12/67bc36ab49a9502af47e2191e9cf11f0afef8e2c0cde6e9630eee8806fa2/m2core-1.0.10.tar.gz" } ] }