{ "info": { "author": "Pavel Perestoronin", "author_email": "eigenein@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# `sqlitemap`\n\nDictionary interface to an SQLite database.\n\n[![Build Status](https://travis-ci.com/eigenein/sqlitemap.svg?branch=master)](https://travis-ci.com/eigenein/sqlitemap)\n[![Coverage Status](https://coveralls.io/repos/github/eigenein/sqlitemap/badge.svg?branch=master)](https://coveralls.io/github/eigenein/sqlitemap?branch=master)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/sqlitemap.svg)](https://pypi.org/project/sqlitemap/)\n[![PyPI \u2013 Version](https://img.shields.io/pypi/v/sqlitemap.svg)](https://pypi.org/project/sqlitemap/#history)\n[![PyPI \u2013 Python](https://img.shields.io/pypi/pyversions/sqlitemap.svg)](https://pypi.org/project/sqlitemap/#files)\n[![License](https://img.shields.io/pypi/l/sqlitemap.svg)](https://github.com/eigenein/sqlitemap/blob/master/LICENSE)\n\n## Intro\n\n\u2026One day I needed an embedded key-value store for a pet project, but didn't find a \u00abgood enough\u00bb implementation. So, I made my own one.\n\nIt's a lightweight wrapper over the standard [sqlite3](https://docs.python.org/3/library/sqlite3.html) module. It provides the standard [`MutableMapping`](https://docs.python.org/3/library/typing.html#typing.MutableMapping) interface for an SQLite connection and SQLite table.\n\n## `Connection`\n\nYou create an instance of `Connection` as if it was a normal [`sqlite3.connect`](https://docs.python.org/3/library/sqlite3.html#sqlite3.connect) call:\n\n```python\nfrom sqlitemap import Connection\n\nconnection = Connection(':memory:', ...)\n```\n\nIt implements the [context manager](https://docs.python.org/3/library/stdtypes.html#typecontextmanager) interface, so you use `with` to make a transaction as if it was an [`sqlite3.Connection`](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection). And it implements `MutableMapping[str, Collection]`, except for `__setitem__`. So you can imagine a `Connection` as a dictionary of collections altogether with their [names](https://stackoverflow.com/questions/3694276/what-are-valid-table-names-in-sqlite) and do virtually everything you could do with a normal [`dict`](https://docs.python.org/3.7/library/stdtypes.html#dict):\n\n```python\nfrom sqlitemap import Collection\n\n# Collection is automatically created:\nfoo: Collection = connection['foo']\n\n# You can iterate over collection names:\nnames = list(connection)\n\n# Or even over collections:\ncollections = connection.values()\n\n# Drop collection:\ndel connection['foo']\n\n# Get number of collections:\nlen(connection)\n\n# Special one, to close the connection:\nconnection.close()\n```\n\nInternally, collection is a table with two columns: `key: str` and `value: bytes`. So, you need some serialization to represent objects as byte strings. By default, `sqlitemap` uses the standard [`json`](https://docs.python.org/3/library/json.html) module. It picks up [`ujson`](https://pypi.org/project/ujson/) or [`orjson`](https://pypi.org/project/orjson/), if available. These are also available as `sqlitemap` extras: `sqlitemap[ujson]` and `sqlitemap[orjson]`.\n\nOtherwise, you can specify any custom `Callable[[Any], bytes]` for encoder and `Callable[[bytes], Any]` for decoder:\n\n```python\nconnection = Connection(':memory:', dumps_=custom_dumps, loads_=custom_loads)\n``` \n\n## `Collection`\n\n`Collection` also implements the [context manager](https://docs.python.org/3/library/stdtypes.html#typecontextmanager) interface to make a transaction, and `MutableMapping[str, Any]`:\n\n### Setting an item\n\n```python\nwith raises(KeyError):\n _ = collection['foo']\ncollection['foo'] = 'bar'\nassert collection['foo'] == 'bar'\ncollection['foo'] = 'qux'\nassert collection['foo'] == 'qux'\n```\n\n`key` column is a primary key.\n\n### Retrieving keys\n\n```python\nassert list(collection) == []\ncollection['foo'] = 'bar'\nassert list(collection) == ['foo']\n```\n\n### Retrieving values\n\n```python\nassert collection.values() == []\ncollection['foo'] = 'bar'\nassert collection.values() == ['bar']\n```\n\n### Deleting an item\n\n```python\nwith raises(KeyError):\n del collection['foo']\ncollection['foo'] = 42\ndel collection['foo']\nwith raises(KeyError):\n del collection['foo']\n```\n\n### Using slices\n\n`Collection.__getitem__` and `Collection.__setitem__` also support [slices](https://docs.python.org/3/library/functions.html#slice) as their arguments. Slice `start` is then converted to `key >= start` clause, `stop` to `key < stop` and `step` to `key LIKE step`. All of these are combined with the `AND` operator. `Collection.__getitem__` also applies `ORDER BY key` clause, so it's possible to make some more sophisticated queries:\n\n```python\ncollection['bar'] = 1\ncollection['foo'] = 2\ncollection['quw'] = 3\ncollection['qux'] = 4\ncollection['quy'] = 5\ncollection['quz'] = 6\nassert collection['foo':] == [2, 3, 4, 5, 6]\nassert collection[:'foo'] == [1]\nassert collection[::'qu%'] == [3, 4, 5, 6]\nassert collection['bar':'quz':'qu%'] == [3, 4, 5]\n```\n\nThe same also works with `del collection [...]`. It deletes the rows that would be selected with the corresponding `__getitem__` call:\n\n```python\ncollection['bar'] = 1\ncollection['foo'] = 2\ncollection['quw'] = 3\ncollection['qux'] = 4\ncollection['quy'] = 5\ncollection['quz'] = 6\ndel collection['bar':'quz':'qu%']\nassert list(collection) == ['bar', 'foo', 'quz']\n```\n\n## Controlling transactions\n\n`sqlitemap` does nothing special to control transactions. For that refer to [the standard library documentation](https://docs.python.org/3/library/sqlite3.html#controlling-transactions).\n\n\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/eigenein/sqlitemap", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "sqlitemap", "package_url": "https://pypi.org/project/sqlitemap/", "platform": "", "project_url": "https://pypi.org/project/sqlitemap/", "project_urls": { "Homepage": "https://github.com/eigenein/sqlitemap" }, "release_url": "https://pypi.org/project/sqlitemap/0.2.0/", "requires_dist": [ "flake8 ; extra == 'dev'", "isort ; extra == 'dev'", "pytest ; extra == 'dev'", "pytest-cov ; extra == 'dev'", "coveralls ; extra == 'dev'", "ujson ; extra == 'dev'", "orjson ; extra == 'dev'", "twine ; extra == 'dev'", "mypy ; extra == 'dev'", "orjson ; extra == 'orjson'", "ujson ; extra == 'ujson'" ], "requires_python": "", "summary": "Dictionary interface to an SQLite database", "version": "0.2.0" }, "last_serial": 5080872, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "089a97ea5b12c129fd3bbf2f87613268", "sha256": "55fb7c50761d4e7f50da9b440ee3cc746439434d0942c9ff2111c7529a301c06" }, "downloads": -1, "filename": "sqlitemap-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "089a97ea5b12c129fd3bbf2f87613268", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5173, "upload_time": "2019-03-28T18:49:05", "url": "https://files.pythonhosted.org/packages/b4/56/e5d6c62c5eea4edc97ab4e4cf9d7810e6df3efccb57fd6122ed611d228d5/sqlitemap-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d91196dd513754ef084c99a8e5bc0cde", "sha256": "5b116d5f8e576bb9a3a31d1b8dfda35ae64decee4ee2d2467e8131af9ad10744" }, "downloads": -1, "filename": "sqlitemap-0.1.0.tar.gz", "has_sig": false, "md5_digest": "d91196dd513754ef084c99a8e5bc0cde", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3844, "upload_time": "2019-03-28T18:49:07", "url": "https://files.pythonhosted.org/packages/86/a0/d691b27c5a4a62363ec3226384670b668e863bae0ed9e32ce37f1ab005a6/sqlitemap-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3cd9e87d0724ff56f34e87fddaa6b134", "sha256": "dd63e4908cb2d2a613ca3c99bb5fa88b8a73a8930c52c82b0b2fe256910f4e9f" }, "downloads": -1, "filename": "sqlitemap-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "3cd9e87d0724ff56f34e87fddaa6b134", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7053, "upload_time": "2019-03-31T16:52:49", "url": "https://files.pythonhosted.org/packages/32/5b/1c474f3bb15d3211cd850b6de87e2ec3edba5e671dc79923223fccfd20b6/sqlitemap-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2b8e20752b69fa1b07bffef5a2358589", "sha256": "335cee94f448e7c07f883b987ee635fd503814f8dd2caa6fce5e4e479c227d9c" }, "downloads": -1, "filename": "sqlitemap-0.1.1.tar.gz", "has_sig": false, "md5_digest": "2b8e20752b69fa1b07bffef5a2358589", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5860, "upload_time": "2019-03-31T16:52:51", "url": "https://files.pythonhosted.org/packages/1c/cc/5977b3462a0b184cc845a903aabdd5cf22fa00d5e4545a378ef9886bd211/sqlitemap-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "3982ab28b94fa9f764dcc4735a967f35", "sha256": "eb2d11dfd66786e3dbb8de0fe8ece589b0197c8f2838a6ae06624b583be79e35" }, "downloads": -1, "filename": "sqlitemap-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3982ab28b94fa9f764dcc4735a967f35", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7181, "upload_time": "2019-04-02T20:55:25", "url": "https://files.pythonhosted.org/packages/d6/e5/4499c71ff2f45aa5ff7d84313ab0bac7e4f75c3303dd65a70a0a4037a0c4/sqlitemap-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cd8d066c662dbd6a89ae51432777f31d", "sha256": "456b53b71283910d56ad01ad28272495d51ae7b732d8413b33d36c90bc8c542a" }, "downloads": -1, "filename": "sqlitemap-0.2.0.tar.gz", "has_sig": false, "md5_digest": "cd8d066c662dbd6a89ae51432777f31d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5978, "upload_time": "2019-04-02T20:55:27", "url": "https://files.pythonhosted.org/packages/6b/a3/4123f4e4a184f59f6e9002a2bac162acefed162877da97aecf57e08d76d4/sqlitemap-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3982ab28b94fa9f764dcc4735a967f35", "sha256": "eb2d11dfd66786e3dbb8de0fe8ece589b0197c8f2838a6ae06624b583be79e35" }, "downloads": -1, "filename": "sqlitemap-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3982ab28b94fa9f764dcc4735a967f35", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7181, "upload_time": "2019-04-02T20:55:25", "url": "https://files.pythonhosted.org/packages/d6/e5/4499c71ff2f45aa5ff7d84313ab0bac7e4f75c3303dd65a70a0a4037a0c4/sqlitemap-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cd8d066c662dbd6a89ae51432777f31d", "sha256": "456b53b71283910d56ad01ad28272495d51ae7b732d8413b33d36c90bc8c542a" }, "downloads": -1, "filename": "sqlitemap-0.2.0.tar.gz", "has_sig": false, "md5_digest": "cd8d066c662dbd6a89ae51432777f31d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5978, "upload_time": "2019-04-02T20:55:27", "url": "https://files.pythonhosted.org/packages/6b/a3/4123f4e4a184f59f6e9002a2bac162acefed162877da97aecf57e08d76d4/sqlitemap-0.2.0.tar.gz" } ] }