{ "info": { "author": "Jessica B. Hamrick", "author_email": "jhamrick@berkeley.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: SQL", "Topic :: Database :: Front-Ends", "Topic :: Utilities" ], "description": "# dbtools\nA simple interface to SQLite databases.\n\n* [Documentation](http://jhamrick.github.io/dbtools/)\n* [GitHub](https://github.com/jhamrick/dbtools/)\n* [PyPI](https://pypi.python.org/pypi/dbtools)\n\n## Overview\n\nThis module handles simple interfacing with a SQLite database.\nInspired by [ipython-sql](https://pypi.python.org/pypi/ipython-sql),\n`dbtools` returns\n[pandas DataFrame](http://pandas.pydata.org/pandas-docs/stable/dsintro.html#dataframe)\nobjects from `SELECT` queries, and can handle basic forms of other SQL\nstatements (`CREATE`, `INSERT`, `UPDATE`, `DELETE`, and `DROP`).\n\nThe goal is *not* to replicate the full functionality of\n[SQLAlchemy](http://www.sqlalchemy.org/) or really to be used for\nobject-relational mapping at all. This is meant to be used more for\nscientific data collection (e.g., behavioral experiments) as\nconvenient access to a robust form of storage.\n\n## Installation\n\nThe easiest way to get `dbtools` is with `pip`:\n\n```bash\npip install dbtools\n```\n\nAlternately, you can clone the repository and install from source:\n\n```bash\ngit clone git@github.com:jhamrick/dbtools.git\ncd dbtools\npython setup.py install\n```\n\nThere is also a `Makefile` in the root of the repository which is just\na convenience wrapper around `setup.py`. So, `make install` is\nequivalent to `python setup.py install`. You can use whichever one you\nprefer.\n\n## Examples\n\n### Create and load\n\n```python\n>>> from dbtools import Table\n>>> tbl = Table.create(\"data.db\", \"People\",\n... [('id', int),\n... ('name', str),\n... ('age', int),\n... ('height', float)],\n... primary_key='id',\n... autoincrement=True)\n>>> tbl\nPeople(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, height REAL)\n>>> type(tbl)\n\n```\n\nIf a table already exists, we can just directly create a Table object:\n\n```python\n>>> tbl = Table(\"data.db\", \"People\")\n>>> tbl\nPeople(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, height REAL)\n>>> tbl.columns\n(u'id', u'name', u'age', u'height')\n>>> tbl.primary_key\nu'id'\n>>> tbl.autoincrement\nTrue\n```\n\n### Insert\n\nInserting with a list (excluding `id`, because it autoincrements):\n\n```python\n>>> tbl.insert([\"Alyssa P. Hacker\", 25, 66.24])\n>>> tbl.select()\n name age height\nid\n1 Alyssa P. Hacker 25 66.24\n>>> type(tbl.select())\n\n```\n\nInserting with a dictionary:\n\n```python\n>>> tbl.insert({\n... 'name': 'Ben Bitdiddle',\n... 'age': 24,\n... 'height': 70.1})\n>>> tbl.select()\n name age height\nid\n1 Alyssa P. Hacker 25 66.24\n2 Ben Bitdiddle 24 70.10\n```\n\nYou can insert as many things as you want as a time -- just pass them\nin as a list of lists and/or dictionaries.\n\n### Select\n\nThe previous two examples already used an instance of selection with\n`tbl.select()`, which is the equivalent of doing `FROM People SELECT\n*`. You can use slicing to select rows (but only if the primary key\ncolumn is an integer and autoincrements). Note that because SQLite\ndatabases are one-indexed, indexing the zeroth element returns an\nempty `DataFrame`.\n\n```python\n>>> tbl[1]\n name age height\nid\n1 Alyssa P. Hacker 25 66.24\n>>> tbl[2:]\n name age height\nid\n2 Ben Bitdiddle 24 70.1\n```\n\nIf you pass in a string or sequence of strings, it will treat them as\ncolumn names and select those columns:\n\n```python\n>>> tbl['name', 'height']\n name height\nid\n1 Alyssa P. Hacker 66.24\n2 Ben Bitdiddle 70.10\n```\n\nMore advanced selection can be done through the `select` method by\nspecifying the `where` keyword argument (and you can use the `?`\nsyntax from the `sqlite3` library for untrusted inputs):\n\n```python\n>>> tbl.select(where='age>24')\n name age height\nid\n1 Alyssa P. Hacker 25 66.24\n>>> tbl.select(columns=['name', 'height'], where=('age>?', 24))\n name height\nid\n1 Alyssa P. Hacker 66.24\n```\n\n### Update\n\nUpdating data in the table works by taking a dictionary (with the keys\nbeing columns, and values being new data) and (optionally) a `where`\nkeyword argument like in the `select` method to specify what data\nshould be updated.\n\n```python\n>>> tbl.update({'age': 26}, where='id=1')\n>>> tbl.select()\n name age height\nid\n1 Alyssa P. Hacker 26 66.24\n2 Ben Bitdiddle 24 70.10\n```\n\n### Delete\n\nDeleting a row or rows requires specifying a `where` keyword argument\nlike in `select` and `update` (if it is not given, all rows are\ndeleted).\n\n```python\n>>> tbl.delete(where='height<70')\n>>> tbl.select()\n name age height\nid\n2 Ben Bitdiddle 24 70.1\n```\n\n### Drop\n\nFinally, the `drop` method is used to drop (delete) an entire table\nfrom its database. Of course, this means it can't be accessed\nafterwards because it no longer exists.\n\n```python\n>>> tbl.drop()\n>>> tbl.select()\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"dbtools/table.py\", line 339, in select\n cur.execute(*cmd)\nsqlite3.OperationalError: no such table: People\n```\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jhamrick/dbtools", "keywords": "sqlite pandas dataframe", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "dbtools", "package_url": "https://pypi.org/project/dbtools/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/dbtools/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/jhamrick/dbtools" }, "release_url": "https://pypi.org/project/dbtools/0.4.0/", "requires_dist": null, "requires_python": null, "summary": "Lightweight SQLite interface", "version": "0.4.0" }, "last_serial": 929007, "releases": { "0.01": [], "0.02": [ { "comment_text": "", "digests": { "md5": "72176b52c045aa8f85afb9cbde2cdcae", "sha256": "190fa567e999465778d9a7bbfd551da014988854ad48869e933014a9a24f9004" }, "downloads": -1, "filename": "dbtools-0.02.tar.gz", "has_sig": false, "md5_digest": "72176b52c045aa8f85afb9cbde2cdcae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6473, "upload_time": "2013-04-16T05:58:23", "url": "https://files.pythonhosted.org/packages/e6/8b/18362240f999a996c4b1d35f16386196e6a9803c0e270d86c4e82329e047/dbtools-0.02.tar.gz" } ], "0.03": [ { "comment_text": "", "digests": { "md5": "ef05f6508ad5b6c56cb32f53b1108de2", "sha256": "658ae6bf50f7c0c24cda68e7c963243946d6070d8a876fa2a971acaabdfe7bb4" }, "downloads": -1, "filename": "dbtools-0.03.tar.gz", "has_sig": false, "md5_digest": "ef05f6508ad5b6c56cb32f53b1108de2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12272, "upload_time": "2013-04-18T05:51:58", "url": "https://files.pythonhosted.org/packages/44/c3/9753d6141e11daa1a72519788b11aa9cbf4b32a718b2b528d676a0ceccb9/dbtools-0.03.tar.gz" } ], "0.03.1": [ { "comment_text": "", "digests": { "md5": "f7a1afd86fa8fe1a914e5168658b8524", "sha256": "2a8083939858d8e88ebad0632e2bd399b816a94053bbdbdf34ba28bf1872e703" }, "downloads": -1, "filename": "dbtools-0.03.1.tar.gz", "has_sig": false, "md5_digest": "f7a1afd86fa8fe1a914e5168658b8524", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13208, "upload_time": "2013-04-18T06:10:44", "url": "https://files.pythonhosted.org/packages/50/60/76331444a8aeaadcd26cbedbf10f358505dfad9571982f39d5a025bf9240/dbtools-0.03.1.tar.gz" } ], "0.03.2": [ { "comment_text": "", "digests": { "md5": "04c9f9aaa6ad8f5922a5dbf509a5c54d", "sha256": "5a99aa7423f615bb42f15447ebc3c4a775d5423795caece5eac321d5bda300f1" }, "downloads": -1, "filename": "dbtools-0.03.2.tar.gz", "has_sig": false, "md5_digest": "04c9f9aaa6ad8f5922a5dbf509a5c54d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13660, "upload_time": "2013-07-02T22:31:19", "url": "https://files.pythonhosted.org/packages/e0/ab/25622e562da005e4c183b36100730b2c22c0af361171f940d74431d3b78a/dbtools-0.03.2.tar.gz" } ], "0.03.3": [ { "comment_text": "", "digests": { "md5": "a04df2d6266490e2728ea834cc7f9616", "sha256": "fb93ba5097e68cc2a841711e2aca3b27004755bfb165778a0cfca41fc295508d" }, "downloads": -1, "filename": "dbtools-0.03.3.tar.gz", "has_sig": false, "md5_digest": "a04df2d6266490e2728ea834cc7f9616", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13726, "upload_time": "2013-07-02T22:52:08", "url": "https://files.pythonhosted.org/packages/4e/f8/7ccda0055ec266d836542095c65d3bbbdce85c4078a095950017778d40ef/dbtools-0.03.3.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "e9d23ba63ed50cf5b3af0a80de1861ce", "sha256": "af2e1f44cd93af6a63c19fcf9c5b041fc8727ba6e7966539080ebc913c845a63" }, "downloads": -1, "filename": "dbtools-0.4.0.tar.gz", "has_sig": false, "md5_digest": "e9d23ba63ed50cf5b3af0a80de1861ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13941, "upload_time": "2013-11-25T20:37:13", "url": "https://files.pythonhosted.org/packages/5b/4b/9cff5438a7c21ebeae24abb75ed62b9961c98dd1e75099c5e993f35f4aeb/dbtools-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e9d23ba63ed50cf5b3af0a80de1861ce", "sha256": "af2e1f44cd93af6a63c19fcf9c5b041fc8727ba6e7966539080ebc913c845a63" }, "downloads": -1, "filename": "dbtools-0.4.0.tar.gz", "has_sig": false, "md5_digest": "e9d23ba63ed50cf5b3af0a80de1861ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13941, "upload_time": "2013-11-25T20:37:13", "url": "https://files.pythonhosted.org/packages/5b/4b/9cff5438a7c21ebeae24abb75ed62b9961c98dd1e75099c5e993f35f4aeb/dbtools-0.4.0.tar.gz" } ] }