{ "info": { "author": "Will Medlar", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6", "Topic :: Database :: Database Engines/Servers" ], "description": "# BitField for [motorengine](https://github.com/heynemann/motorengine)\nCustom field type for storing and retrieving bit-packed flags as enums.\n\nInspiration from [`enum.IntFlag` documentation](https://docs.python.org/3.6/library/enum.html#intflag).\n\n## Installation\n`motorengine-bitfield` requires a minimum Python version of 3.6.2.\n\nAdd the code directly to your project or install from pip with:\n```shell\npip install motorengine-bitfield\n```\n\n## Examples\n```python\nfrom bitfield import BitField\n\n# create an enum to use in our example\nclass UserFlags(enum.IntFlag):\n IS_ACTIVE = enum.auto() # least-significant bit\n IS_ADMIN = enum.auto()\n HAS_LOGGED_IN = enum.auto()\n HAS_SEEN_INTRO = enum.auto()\n SUBSCRIBED_TO_NEWSLETTER = enum.auto() # most-significant bit\n\n# use the enum in our Document mapping\nclass User(motorengine.Document):\n name = StringField()\n email = StringField()\n flags = BitField(UserFlags)\n\n# let's test one out!\nuser = User(\n name='Bit Field',\n email='example@bitfield.py',\n flags=(UserFlags.IS_ACTIVE | UserFlags.SUBSCRIBED_TO_NEWSLETTER),\n)\n\n# enum instances are serialized into an integer\nuser.to_son()\n# {'name': 'Bit Field', 'email': 'example@bitfield.py', 'flags': 17}\nuser = loop.run_until_complete(\n user.save()\n)\n\n# and deserialized into the original enum\nretrieved_user = loop.run_until_complete(\n User.objects.get(user._id)\n)\nretrieved_user.flags\n# \nbool(user.flags & UserFlags.IS_ADMIN)\n# False\n\n# a BitField value also be created with plain integers\nint_user = loop.run_until_complete(\n User.objects.create(flags=(2**5 - 1))\n)\nloop.run_until_complete(User.objects.get(int_user._id)).flags\n# \n\n# or from strings of binary\nstr_user = loop.run_until_complete(\n User.objects.create(flags='01101'))\n)\nloop.run_until_complete(User.objects.get(str_user._id)).flags\n# \n```\n\n## Development\nTests are written with pytest and can be run with `python setup.py test`.\n\nPull requests always welcome!\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/wmedlar/motorengine-bitfield", "keywords": "motorengine bit-packing enum", "license": "GPLv3", "maintainer": "", "maintainer_email": "", "name": "motorengine-bitfield", "package_url": "https://pypi.org/project/motorengine-bitfield/", "platform": "any", "project_url": "https://pypi.org/project/motorengine-bitfield/", "project_urls": { "Homepage": "https://gitlab.com/wmedlar/motorengine-bitfield" }, "release_url": "https://pypi.org/project/motorengine-bitfield/1.0.0/", "requires_dist": [ "motorengine (<1,>=0.9)" ], "requires_python": ">=3.6", "summary": "Custom field type for storing and retrieving bit-packed flags as enums.", "version": "1.0.0" }, "last_serial": 2972092, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "4cc1400a92d33f737d3b32e37d764d78", "sha256": "6cea85bb297ff9e95946b41644b67e6be3fd2d4fdaa1bddc9cf62d25717c8475" }, "downloads": -1, "filename": "motorengine_bitfield-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4cc1400a92d33f737d3b32e37d764d78", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5619, "upload_time": "2017-06-23T04:11:46", "url": "https://files.pythonhosted.org/packages/b7/63/63ae8051d491cafd913603928b377cd518063836c69b3b1ad0362f5ae0da/motorengine_bitfield-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "79ecf1dff06b244a564b42b4d4d26f77", "sha256": "79b47c01dcff8cc7803ade2181a62a9f208ab753466635c0f59d58637e5f4459" }, "downloads": -1, "filename": "motorengine-bitfield-1.0.0.tar.gz", "has_sig": false, "md5_digest": "79ecf1dff06b244a564b42b4d4d26f77", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 16809, "upload_time": "2017-06-23T04:11:48", "url": "https://files.pythonhosted.org/packages/ae/09/e6e65ec100e81b82faf53da36d24250d25531d94b0f9c3d50e1505dd548f/motorengine-bitfield-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4cc1400a92d33f737d3b32e37d764d78", "sha256": "6cea85bb297ff9e95946b41644b67e6be3fd2d4fdaa1bddc9cf62d25717c8475" }, "downloads": -1, "filename": "motorengine_bitfield-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4cc1400a92d33f737d3b32e37d764d78", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5619, "upload_time": "2017-06-23T04:11:46", "url": "https://files.pythonhosted.org/packages/b7/63/63ae8051d491cafd913603928b377cd518063836c69b3b1ad0362f5ae0da/motorengine_bitfield-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "79ecf1dff06b244a564b42b4d4d26f77", "sha256": "79b47c01dcff8cc7803ade2181a62a9f208ab753466635c0f59d58637e5f4459" }, "downloads": -1, "filename": "motorengine-bitfield-1.0.0.tar.gz", "has_sig": false, "md5_digest": "79ecf1dff06b244a564b42b4d4d26f77", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 16809, "upload_time": "2017-06-23T04:11:48", "url": "https://files.pythonhosted.org/packages/ae/09/e6e65ec100e81b82faf53da36d24250d25531d94b0f9c3d50e1505dd548f/motorengine-bitfield-1.0.0.tar.gz" } ] }