{ "info": { "author": "Gabriela Surita", "author_email": "gsurita@loggi.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "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" ], "description": "Redis Schematics\n================\n\n*Provides Redis persistence to Schematics models with cutomizable abstraction levels.*\n\n|travis|\n\n.. |travis| image:: https://travis-ci.org/loggi/redis-schematics.svg?branch=master\n :target: https://travis-ci.org/loggi/redis-schematics\n\n\nInstalling\n----------\n\nUsing pip::\n\n pip install redis_schematics\n\n\nUnderstanding Persistence layers\n--------------------------------\n\nThere are several ways to implement complex objects persitence on a key-value-set\ndatabase such as redis. The best way to do it depends on your application constraints.\nWe think that providing a good storage model for your application is to allow you\nto choose which abstraction you want to use. Below you can find a comparison on different\nprovided abstraction layers.\n\n*Currently we only support a SimpleRedisMixin and SimpleRedisModel, but you can\nuse BaseRedisMixin to build your own persistance layers.*\n\n\n**SimpleRedisMixin**\n\nAdd Redis persistance to an object using a simple approach. Each object\ncorrenspond to a single key on redis prefixed with the object namespace,\nwhich correnponds to a serialized object. To use this mixin you just need\nto declare a primary key as on the example below.\n\nYou may use this Mixin when you have frequent matches on primary key and set\noperations, unique expires, hard memory contraints or just wants a 1-1 object-key\napproach. You may not use this Mixin if you need performance on ``filter``, ``all``\nand ``get`` on non primary key operations.\n\n**HashRedisMixin**\n\nAdd Redis persistance to an object using a single hash approach. Each type\ncorrenspond to a single key on redis containing a hash set with every instance\nas an entry on the set which contains a serialized object.\n\nYou may use this Mixin when you have frequent matches on primary key, set and\nall operations, hard memory contraints or wants a single key approach.\nYou may not use this Mixin if you need performance on ``filter`` and ``get`` on\nnon primary key operations.\n\n\nQuickstart\n----------\n\n**Creating models with persistence**\n\nNote: you should include a pk, but don't bother setting it's value manually.\nWe can infer it from an ``id`` field or by setting a tuple of field names using\n``__unique_together__``.\n\n\n.. code-block:: python\n\n from datetime import datetime, timedelta\n\n from redis import StrictRedis\n from redis_schematics import SimpleRedisMixin\n from schematics import models, types\n\n\n class IceCreamModel(models.Model, SimpleRedisMixin):\n pk = types.StringType() # Just include a pk\n id = types.StringType()\n flavour = types.StringType()\n amount_kg = types.IntType()\n best_before = types.DateTimeType()\n\n\n**Setting on Redis**\n\nSaving is simple as ``set()``.\n\n.. code-block:: python\n\n vanilla = IceCreamModel(dict(\n id='vanilla',\n flavour='Sweet Vanilla',\n amount_kg=42,\n best_before=datetime.now() + timedelta(days=2),\n ))\n\n chocolate = IceCreamModel(dict(\n id='chocolate',\n flavour='Delicious Chocolate',\n amount_kg=12,\n best_before=datetime.now() + timedelta(days=3),\n ))\n\n vanilla.set()\n chocolate.set()\n\n**Getting from Redis**\n\nThere are two basic ways to get an element from Redis: by pk or by value.\nYou can use the classmethods ``match_for_pk(pk)`` or ``match_for_values(**Kwargs)``\nor just simply ``match(**kwargs)`` to let us choose which one. Notice that the\nperformance from both methods is a lot different, so you may avoid matching\nfor values on high performance environments. You may also use refresh to reload\nan object from storage if it has been modified.\n\n.. code-block:: python\n\n IceCreamModel.match_for_pk('vanilla')\n IceCreamModel.match_for_values(amount__gte=30)\n\n IceCreamModel.match(id='vanilla') # match on pk\n IceCreamModel.match(best_before__gte=datetime.now()) # match on values\n\n vanilla.refresh()\n\n\n**Fetching all and filtering**\n\nYou can also use ``all()`` to deserialize all and filters. Notice that\nthis invlolves deserializing all stored objects.\n\n.. code-block:: python\n\n IceCreamModel.all()\n IceCreamModel.filter(amount__gte=30)\n\n\n**Deleting and expiring**\n\nTo remove objects, you can set ``__expire__`` or use the ``delete()`` method.\nNotice that expires work differently on single key and multiple keys approaches.\n\n.. code-block:: python\n\n class MyVolatileModel(models.Model, SimpleRedisMixin):\n __expire__ = 3600 # model expire (in seconds)\n pk = types.StringType()\n\n vanilla.delete()\n\n\nJSON\n----\n\nIf you want json serialization, you have at least two options:\n\n1. Patch the default serializer.\n2. Write a custom JSONEncoder.\n\nWe've implemented a handy patch funtion, you need to add this\ncode to somewhere at the top of everything to automagically add\njson serialization capabilities:\n\n.. code:: python\n\n from redis_schematics.patches import patch_json\n patch_json()\n\n.. note::\n\n Eventually ``__json__`` will be added to the stdlib, see\n https://bugs.python.org/issue27362\n\nRoadmap\n-------\n\nWe are still ``0.x``, but we are very close to a stable API. Check `our roadmap `_ for a glance of what's missing.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/loggi/redis-schematics", "keywords": "loggi,schematics,redis", "license": "Apache License (2.0)", "maintainer": "", "maintainer_email": "", "name": "redis-schematics", "package_url": "https://pypi.org/project/redis-schematics/", "platform": "", "project_url": "https://pypi.org/project/redis-schematics/", "project_urls": { "Homepage": "https://github.com/loggi/redis-schematics" }, "release_url": "https://pypi.org/project/redis-schematics/0.2.2/", "requires_dist": null, "requires_python": "", "summary": "Redis storage backend for schematics.", "version": "0.2.2" }, "last_serial": 4935834, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "cf0f6aa586d9c8cd4bb45bcd580e3ffd", "sha256": "0e67b08b49026025f085cab7bfc5dbc1d9dc767ea48b060a5eda24d6d0e20c29" }, "downloads": -1, "filename": "redis_schematics-0.1.0.tar.gz", "has_sig": false, "md5_digest": "cf0f6aa586d9c8cd4bb45bcd580e3ffd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6489, "upload_time": "2017-09-13T02:20:24", "url": "https://files.pythonhosted.org/packages/0c/78/85bfbf2689e1c6914d8ff8b05e7dd11234c3a87b420e0f3a64baf22ae0eb/redis_schematics-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "f4d13c8ee4ead0421109b7930efa0944", "sha256": "acecd1440764856e10ee2abad255e7390f2dc7d237d0a4d9196f982e037502f1" }, "downloads": -1, "filename": "redis_schematics-0.2.0.tar.gz", "has_sig": false, "md5_digest": "f4d13c8ee4ead0421109b7930efa0944", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8992, "upload_time": "2017-09-14T14:34:40", "url": "https://files.pythonhosted.org/packages/77/dc/bfc3ac2a4bbf78a35bbdd837360c7975fd5957714ccaeae84d3f4de58961/redis_schematics-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "80125d3ceb90e0c55cacb63c95fcc611", "sha256": "c778deb304654fbf8a0f17629ae0d6ea5a9e6e91b5ca86aaaf03227142f01eb7" }, "downloads": -1, "filename": "redis_schematics-0.2.1.tar.gz", "has_sig": false, "md5_digest": "80125d3ceb90e0c55cacb63c95fcc611", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9103, "upload_time": "2017-09-14T16:23:05", "url": "https://files.pythonhosted.org/packages/ea/25/563db1991e6cbfe63d8744ace13e14fe4cecb4db30b854c4febd64a2e890/redis_schematics-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "dde6741b720be4b5be1b7353c3e7140d", "sha256": "8bb5a25e8fcfabeef956a5318fa4aac692fb9f32bb54d8d13e5839535b13102a" }, "downloads": -1, "filename": "redis_schematics-0.2.2.tar.gz", "has_sig": false, "md5_digest": "dde6741b720be4b5be1b7353c3e7140d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9165, "upload_time": "2019-03-13T17:53:13", "url": "https://files.pythonhosted.org/packages/f3/b3/6dc718d53fed9fa5718c419a2b03ff198940133120eac190043df17ecb02/redis_schematics-0.2.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dde6741b720be4b5be1b7353c3e7140d", "sha256": "8bb5a25e8fcfabeef956a5318fa4aac692fb9f32bb54d8d13e5839535b13102a" }, "downloads": -1, "filename": "redis_schematics-0.2.2.tar.gz", "has_sig": false, "md5_digest": "dde6741b720be4b5be1b7353c3e7140d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9165, "upload_time": "2019-03-13T17:53:13", "url": "https://files.pythonhosted.org/packages/f3/b3/6dc718d53fed9fa5718c419a2b03ff198940133120eac190043df17ecb02/redis_schematics-0.2.2.tar.gz" } ] }