{ "info": { "author": "Resilient Vitality", "author_email": "zprobst@resilientvitality.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# PolyMicro\n\n[![Build Status](https://travis-ci.org/resilient-vitality/PolyMicro.svg?branch=master)](https://travis-ci.org/resilient-vitality/PolyMicro)\n[![Requirements Status](https://requires.io/github/resilient-vitality/PolyMicro/requirements.svg?branch=master)](https://requires.io/github/resilient-vitality/PolyMicro/requirements/?branch=master)\n[![codecov](https://codecov.io/gh/resilient-vitality/PolyMicro/branch/master/graph/badge.svg)](https://codecov.io/gh/resilient-vitality/PolyMicro)\n\nPolyMicro is a Model Based Rest API system written around `PynamoDB` and `Marshmallow` for \nrequest and response marshalling and designed to work interchangeably with various different \ndeployments.\n\n## Installation\nInstallation is simple. \n```\npip install polymicro\n```\n\nSee our example below for how easy it is to get up and runnning with polymicro.\n\n## Road Map\nIn the future we would like to bring the following features to PolyMicro.\n\n* Swappable Data Backends (For instance, supporting SQL Alchemy, etc.)\n* Configurable Response Types (Serializing to things other than json)\n\n\n## Example\nIt is as simple as one... two.... three.... (four).\n\n#### Step 1: Create your PolyMicro app\n```python\nfrom flask import Flask\nfrom polymicro import PolyMicro\n\ndef get_request_user(self):\n # Get the user however you want. If there is no user for the request, return None\n return 'abc123'\n\napp = Flask(__name__)\npm = PolyMicro(app, req_user_func=get_request_user)\n```\n\nThis step revolves around setting the basics of the application. You need to create a flask app as \nyou would do in any other flask application. Then we are going to create a function that tells \nPolyMicro how to get user information from the given request and pass that into the creation of our polymicro app.\n\n\n#### Step 2: Create your PynamoDB Model\n```python\nfrom datetime import datetime\nfrom uuid import uuid4\nfrom pynamodb.models import Model\nfrom pynamodb.attributes import UnicodeAttribute, BooleanAttribute, UTCDateTimeAttribute\n\nclass Todo(Model):\n class Meta:\n table_name = 'todos'\n\n owner = UnicodeAttribute(hash_key=True)\n uuid = UnicodeAttribute(range_key=True, default=lambda: str(uuid4()))\n creation_date_time = UTCDateTimeAttribute(default=datetime.utcnow)\n\n text = UnicodeAttribute()\n done = BooleanAttribute(default=False)\n due_date_time = UTCDateTimeAttribute(null=True)\n```\nPynamoDB is a tool to write models in DynamoDB similar to an ORM. We use it to define information.\n\n#### Step 3: Define Permissions (Optional)\n```python\nfrom polymicro.permissions import Permission\n\nclass TodoPermission(Permission):\n def has_object_permission(self, user, method: str, instance):\n return instance.owner == user.uuid\n\n def has_permission(self, user, method: str):\n return 'administrator' in user.permissions or 'therapist' in user.permissions\n```\n\nPermissions are simple sets of rules from which you can define weather or not a user can access a particular \nresource and object. Return false if the permission proves the user cannot use the object or the method and true\notherwise.\n\n#### Step 4: Define the Resource\n```python\nfrom polymicro import ModelResource, Create, List, Retrieve, Update, Delete\n\nclass TodoResource(ModelResource, Create, List, Retrieve, Update, Delete):\n model = Todo\n route = 'todo'\n permissions = (TodoPermission)\n dump_only = ('creation_date_time', 'owner', 'uuid')\n required = ('text', )\n\n def list(self, user, pagination_key=None, limit=25):\n return Todo.query(user.uuid, last_evaluated_key=pagination_key, limit=limit)\n\n def create(self, req: dict, user):\n req['owner'] = user.uuid\n return super().create(req, user)\n \nTodoResource(pm)\n```\n\nWe can define resources by composition. So first, define a class that extends from `ModelResource`. This class\nwill form the base of the functionality that we will want to implement. Next, extending from the `Create`, `List`,\n`Retrieve`, `Update`, and `Delete` class will implement standard versions of those functions. You can also override the \nfunction.\n\nThese functions can return several different things.\n\n*One of these*:\n* A single or collection of your model.\n* Anything that is JSON serializable \n\nAnd optionally these:\n* A HTTP status code as an integer.\n* A string -> string dictionary representing extra headers.\n* For the list operation, a 4th item that allows for a pagination key to be returned in the response for pagination.\n\nBelow are some examples:\n\n```python\n# Returning all three.\ndef retrieve(self, instance, user):\n return instance, 418, {'Extra': 'Something-Super-Secret'}\n\n# Returning instance and status code\ndef retrieve(self, instance, user):\n return instance, 418\n \n# Return just the single instance.\ndef retrieve(self, instance, user):\n return instance\n \n# The list operation allows for a 4th item that allows for a pagination key that can be returned back later.\ndef list(self, user, pagination_key=None, limit=25):\n items = Todo.query(user.uuid, last_evaluated_key=pagination_key, limit=limit)\n return items, 418, {}, 'some-key'\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/resilient-vitality/PolyMicro", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "polymicro", "package_url": "https://pypi.org/project/polymicro/", "platform": "", "project_url": "https://pypi.org/project/polymicro/", "project_urls": { "Homepage": "https://github.com/resilient-vitality/PolyMicro" }, "release_url": "https://pypi.org/project/polymicro/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "PolyMicro is a Model Based Rest API system written around PynamoDD and Marshmallow for flask", "version": "0.2.0" }, "last_serial": 5763020, "releases": { "0.0.1a1": [ { "comment_text": "", "digests": { "md5": "84bb40c6f474b14e3a1d20b5928300f6", "sha256": "6c8c55f74a46f15ba89739dbad14de452a5477f935cf8595b957acaddcf62154" }, "downloads": -1, "filename": "polymicro-0.0.1a1.tar.gz", "has_sig": false, "md5_digest": "84bb40c6f474b14e3a1d20b5928300f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6663, "upload_time": "2019-06-09T15:50:44", "url": "https://files.pythonhosted.org/packages/2d/25/34c3d18067a50a8a4915e6b88aa7bf97643ec18dd228e75269938f140822/polymicro-0.0.1a1.tar.gz" } ], "0.0.1a2": [ { "comment_text": "", "digests": { "md5": "dd591d6a630c268154427470162b1fb6", "sha256": "d63e580f5b92d4baa0bd8313ed1ed911ab2f62751384148e6efd2d240092b9a0" }, "downloads": -1, "filename": "polymicro-0.0.1a2.tar.gz", "has_sig": false, "md5_digest": "dd591d6a630c268154427470162b1fb6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7030, "upload_time": "2019-06-09T21:58:10", "url": "https://files.pythonhosted.org/packages/f1/78/5ce4c52a497955ec07329fdb97f1176f65b7008d7cf4485708c589cb7f0f/polymicro-0.0.1a2.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "23e905d9b53cc11e3cb13c25a9b05865", "sha256": "5640496ac718ead5aa8368264f5f1d51ebcdc9ba10d440da555945d1dbfb266d" }, "downloads": -1, "filename": "polymicro-0.0.2.tar.gz", "has_sig": false, "md5_digest": "23e905d9b53cc11e3cb13c25a9b05865", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6631, "upload_time": "2019-06-09T22:24:59", "url": "https://files.pythonhosted.org/packages/a1/19/b37ef7cb527739b06ea0d8dcf714b7d2a4d734b71769be260419feef3b6f/polymicro-0.0.2.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "0afed024a1dc2df954d74cdf198943e2", "sha256": "fbf1c6719efb1adaa8c0cc49c65c12efe50fe4b963e10badc5c730022c31f4bd" }, "downloads": -1, "filename": "polymicro-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0afed024a1dc2df954d74cdf198943e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8033, "upload_time": "2019-07-08T15:22:20", "url": "https://files.pythonhosted.org/packages/a5/e9/a69bd76608c7e99a58a8b6aff29ea88de37e53c098c170aeaa75c0ed21b8/polymicro-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "04e1c8353393e13f8eca0f912b787df6", "sha256": "57861fb71e0842eebb9d5af4fea7febfb48859695c6791fe133846fc21cd4536" }, "downloads": -1, "filename": "polymicro-0.2.0.tar.gz", "has_sig": false, "md5_digest": "04e1c8353393e13f8eca0f912b787df6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7306, "upload_time": "2019-08-31T03:00:26", "url": "https://files.pythonhosted.org/packages/7e/74/8a932519567bc3dee7e708f8aed0ff6f7a0d53fb48033aadf5c51f3decab/polymicro-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "04e1c8353393e13f8eca0f912b787df6", "sha256": "57861fb71e0842eebb9d5af4fea7febfb48859695c6791fe133846fc21cd4536" }, "downloads": -1, "filename": "polymicro-0.2.0.tar.gz", "has_sig": false, "md5_digest": "04e1c8353393e13f8eca0f912b787df6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7306, "upload_time": "2019-08-31T03:00:26", "url": "https://files.pythonhosted.org/packages/7e/74/8a932519567bc3dee7e708f8aed0ff6f7a0d53fb48033aadf5c51f3decab/polymicro-0.2.0.tar.gz" } ] }