{ "info": { "author": "James Liu", "author_email": "contact@jamessliu.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# aiolmdb [![Travis](https://travis-ci.org/james7132/aiolmdb.svg?branch=master)](https://travis-ci.org/james7132/aiolmdb) [![PyPI](https://img.shields.io/pypi/v/aiolmdb.svg)](https://pypi.org/project/aiolmdb/)\n\nAn asyncio wrapper around LMDB.\n\naiolmdb is alpha quality software, expect the API or architecture to change\nsignifigantly over time.\n\n## Usage\n\n**Opening a aiolmdb enviroement**\n\n```python\nimport aiolmdb\n\n# Open a aiolmdb enviroment\n#\n# Takes the same arguments that lmdb.open does.\nenviroment = aiolmdb.open(\"/tmp/path/to/enviorment\", ...)\n```\n\n**Opening a aiolmdb database**\n\nUnlike pylmdb, aiolmdb does not return a database handle on `open_db`, but\nrather a full Python object.\n\n```python\n# Open a database\nrecords = enviroment.open_db(\"records\")\n\n# Get the default (\"\" named database) within an enviroment\ndefault = enviroment.get_default_database()\n```\n\n**Querying an aiolmdb database**\n\nAll queries against databases return coroutines and are run asynchronously.\n\n```python\n# Get a value(s) from the database\nresult = await db.get(b'key') # Normal fetch, returned b'value'\nresult = await.db.get(b'key', default=b'') # Defaults to b'' if no key is found\nresult = await db.get_multi([b'0', b'1']) # Gets multiple keys at once\n\n# Write a value into the database\nawait db.put(b'key', b'value')\nawait db.put_multi([(b'k1', b'v1'), (b'k2', b'v2')]) # Puts multiple key-values\nat once, atomically.\n\n# Delete a key from the database\nawait db.delete(b'key')\nawait db.delete_multi([b'k1', b'k2', b'k3'])\n\n# Drop the database\nawait db.drop()\n\n# Run any arbitrary transactions\ndef transaction_action(txn):\n return txn.id()\nawait db.run(transaction_action)\n```\n\n**Using coders**\n\nApplications do not operate directly on bytearrays, and require converting\nruntime objects to and from serialized bytearrays. To avoid spending additional\ntime on the main loop running this conversion code, aiolmdb supports adding\ndatabase level coders to run this serialization/deserialization logic in the\nexecutor instead of in the main loop. By default, every aiolmdb database uses\nthe `IdentityCoder` which supports directly writing bytes like objects. Other\ncoders can be used for both the key and value to change the types of objects\naccepted by the API.\n\n```python\n# Opening a database with specific coders\ndb = env.open_db(\"records\", key_coder=UInt16Coder(), value_coder=JSONCoder())\nawait db.put(65535, {\"key\": \"value\"}) # Takes the approriate maching keys\nawait db.get(65535) # Returns {\"key\": \"value\"}\n\n# Alter the coder for an existing database, useful for altering the enviroment\n# default database.\ndb.key_coder = StringCoder()\ndb.value_coder = JSONCoder()\n\n# Supported Coders\nIdentityCoder() # Raw bytes coder\nStringCoder() # String coder\nUInt16Coder() # 16-bit unsigned integer coder\nUInt32Coder() # 32-bit unsigned integer coder\nUInt64Coder() # 64-bit unsigned integer coder\nJSONCoder() # JSON coder, works with any JSON serializable object\nPicleCoder() # Pickle coder, works with any picklable object compression\n\n# Create a new JSONCoder, gzipped with compression level 9\n# Runs the encoded JSON through zlib before writing to database, and\ndecompresses\nzlib_json_coder = JSONCoder().compressed(level=9)\ncompressed_db = env.open_db(\"records\", value_coder=zlib_json_coder)\n\n# Write your own custom coder\nfrom aiolmdb.coders import Coder\n\nclass CustomCoder(Coder):\n\n def serialize(self, obj):\n # Custom serialization logic\n #\n # These objects need to have locally immutable state: the objects must not\n # change how it represents its state for the duration of all concurrent\n # transactions dealing with the object.\n #\n # must return a bytes-like object\n return buffer\n\n def deserialize(self, buffer):\n # Custom deserialization logic\n #\n # aiolmdb uses LMDB transactions with `buffers=True`. this returns a\n # direct reference to the memory region. This buffer must NOT be modified in\n # any way. The lifetime of the buffer is also only valid during the scope of\n # the transaction that fetched it. To use the buffer outside of the context\n # of the serializer, it must be copied, and references to the buffer must\n # not be used elsewhere.\n #\n # Returns the deserialized object\n return deserialized_object\n```\n\n## Caveats and Gotchas\n\n * Write transactions (put, delete, pop, replace) still block while executed in\n the executor. Thus running multiple simultaneous write transactions will\n block all other transactions until they complete, one-by-one. Long running\n write transactions are strongly discouraged.\n * Due to design limitations, atomic transactions across multiple databases is\n currently not easy to do, nor is the code very pythonic.\n\n## TODOs\n\n * Support cursors and range queries", "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/james7132/aiolmdb", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "aiolmdb", "package_url": "https://pypi.org/project/aiolmdb/", "platform": "", "project_url": "https://pypi.org/project/aiolmdb/", "project_urls": { "Homepage": "https://github.com/james7132/aiolmdb" }, "release_url": "https://pypi.org/project/aiolmdb/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "An asyncio wrapper around Lighting Memory Mapped Database (LMDB)", "version": "0.1.1" }, "last_serial": 4423526, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "aea4f563830ea921de766bb2171abf3d", "sha256": "3bb6dffe0b172c3a9d9e905ab122c1d36224e50f3f7dd417d007c7a732ad167e" }, "downloads": -1, "filename": "aiolmdb-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "aea4f563830ea921de766bb2171abf3d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13482, "upload_time": "2018-10-28T05:11:55", "url": "https://files.pythonhosted.org/packages/c8/e8/54b5a499212e28f623ccfe2b74e7332f61bb8bd4e5015ae1906984136fe5/aiolmdb-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8f86d29cfc4c77fa4741242cc3921979", "sha256": "473673c357c2c1ee78898585016dd1f87d49eed145e21fd34505ddf92eb8ed36" }, "downloads": -1, "filename": "aiolmdb-0.1.0.tar.gz", "has_sig": false, "md5_digest": "8f86d29cfc4c77fa4741242cc3921979", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11404, "upload_time": "2018-10-28T05:11:56", "url": "https://files.pythonhosted.org/packages/16/35/b5c8e2695a48268e79b7e3fa09de4e9dcbc2b425e1228a815228bd9c065f/aiolmdb-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "de594ff0b07e1a2c7230c710c6b19ba2", "sha256": "9449639175d303ea580f7bf679181981f71c406220805e6a0bc55241b06de68e" }, "downloads": -1, "filename": "aiolmdb-0.1.1.tar.gz", "has_sig": false, "md5_digest": "de594ff0b07e1a2c7230c710c6b19ba2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13174, "upload_time": "2018-10-28T05:30:09", "url": "https://files.pythonhosted.org/packages/78/11/94dcf880354805b29000c43e95892a42559f6e873c604ec86f49a09ca438/aiolmdb-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "de594ff0b07e1a2c7230c710c6b19ba2", "sha256": "9449639175d303ea580f7bf679181981f71c406220805e6a0bc55241b06de68e" }, "downloads": -1, "filename": "aiolmdb-0.1.1.tar.gz", "has_sig": false, "md5_digest": "de594ff0b07e1a2c7230c710c6b19ba2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13174, "upload_time": "2018-10-28T05:30:09", "url": "https://files.pythonhosted.org/packages/78/11/94dcf880354805b29000c43e95892a42559f6e873c604ec86f49a09ca438/aiolmdb-0.1.1.tar.gz" } ] }