{ "info": { "author": "Simon Willison", "author_email": "", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "Intended Audience :: Science/Research", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3.6", "Topic :: Database" ], "description": "# csvs-to-sqlite\n\n[![PyPI](https://img.shields.io/pypi/v/csvs-to-sqlite.svg)](https://pypi.python.org/pypi/csvs-to-sqlite)\n[![Travis CI](https://travis-ci.org/simonw/csvs-to-sqlite.svg?branch=master)](https://travis-ci.org/simonw/csvs-to-sqlite)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/csvs-to-sqlite/blob/master/LICENSE)\n\nConvert CSV files into a SQLite database. Browse and publish that SQLite database with [Datasette](https://github.com/simonw/datasette).\n\nBasic usage:\n\n csvs-to-sqlite myfile.csv mydatabase.db\n\nThis will create a new SQLite database called `mydatabase.db` containing a\nsingle table, `myfile`, containing the CSV content.\n\nYou can provide multiple CSV files:\n\n csvs-to-sqlite one.csv two.csv bundle.db\n\nThe `bundle.db` database will contain two tables, `one` and `two`.\n\nThis means you can use wildcards:\n\n csvs-to-sqlite ~/Downloads/*.csv my-downloads.db\n\nIf you pass a path to one or more directories, the script will recursively\nsearch those directories for CSV files and create tables for each one.\n\n csvs-to-sqlite ~/path/to/directory all-my-csvs.db\n\n## Handling TSV (tab-separated values)\n\nYou can use the `-s` option to specify a different delimiter. If you want\nto use a tab character you'll need to apply shell escaping like so:\n\n csvs-to-sqlite my-file.tsv my-file.db -s $'\\t'\n\n## Refactoring columns into separate lookup tables\n\nLet's say you have a CSV file that looks like this:\n\n county,precinct,office,district,party,candidate,votes\n Clark,1,President,,REP,John R. Kasich,5\n Clark,2,President,,REP,John R. Kasich,0\n Clark,3,President,,REP,John R. Kasich,7\n\n([Real example taken from the Open Elections project](https://github.com/openelections/openelections-data-sd/blob/master/2016/20160607__sd__primary__clark__precinct.csv))\n\nYou can now convert selected columns into separate lookup tables using the new\n`--extract-`column option (shortname: `-c`) - for example:\n\n csvs-to-sqlite openelections-data-*/*.csv \\\n -c county:County:name \\\n -c precinct:Precinct:name \\\n -c office -c district -c party -c candidate \\\n openelections.db\n\nThe format is as follows:\n\n column_name:optional_table_name:optional_table_value_column_name\n\nIf you just specify the column name e.g. `-c office`, the following table will\nbe created:\n\n CREATE TABLE \"office\" (\n \"id\" INTEGER PRIMARY KEY,\n \"value\" TEXT\n );\n\nIf you specify all three options, e.g. `-c precinct:Precinct:name` the table\nwill look like this:\n\n CREATE TABLE \"Precinct\" (\n \"id\" INTEGER PRIMARY KEY,\n \"name\" TEXT\n );\n\nThe original tables will be created like this:\n\n CREATE TABLE \"ca__primary__san_francisco__precinct\" (\n \"county\" INTEGER,\n \"precinct\" INTEGER,\n \"office\" INTEGER,\n \"district\" INTEGER,\n \"party\" INTEGER,\n \"candidate\" INTEGER,\n \"votes\" INTEGER,\n FOREIGN KEY (county) REFERENCES County(id),\n FOREIGN KEY (party) REFERENCES party(id),\n FOREIGN KEY (precinct) REFERENCES Precinct(id),\n FOREIGN KEY (office) REFERENCES office(id),\n FOREIGN KEY (candidate) REFERENCES candidate(id)\n );\n\nThey will be populated with IDs that reference the new derived tables.\n\n## Installation\n\n $ pip install csvs-to-sqlite\n\n`csvs-to-sqlite` now requires Python 3. If you are running Python 2 you can install the last version to support Python 2:\n\n $ pip install csvs-to-sqlite==0.9.2\n\n## csvs-to-sqlite --help\n\n Usage: csvs-to-sqlite [OPTIONS] PATHS... DBNAME\n\n PATHS: paths to individual .csv files or to directories containing .csvs\n\n DBNAME: name of the SQLite database file to create\n\n Options:\n -s, --separator TEXT Field separator in input .csv\n -q, --quoting INTEGER Control field quoting behavior per csv.QUOTE_*\n constants. Use one of QUOTE_MINIMAL (0),\n QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or\n QUOTE_NONE (3).\n --skip-errors Skip lines with too many fields instead of\n stopping the import\n --replace-tables Replace tables if they already exist\n -t, --table TEXT Table to use (instead of using CSV filename)\n -c, --extract-column TEXT One or more columns to 'extract' into a\n separate lookup table. If you pass a simple\n column name that column will be replaced with\n integer foreign key references to a new table\n of that name. You can customize the name of the\n table like so:\n state:States:state_name\n This will pull unique values from the 'state'\n column and use them to populate a new 'States'\n table, with an id column primary key and a\n state_name column containing the strings from\n the original column.\n -d, --date TEXT One or more columns to parse into ISO formatted\n dates\n -dt, --datetime TEXT One or more columns to parse into ISO formatted\n datetimes\n -df, --datetime-format TEXT One or more custom date format strings to try\n when parsing dates/datetimes\n -pk, --primary-key TEXT One or more columns to use as the primary key\n -f, --fts TEXT One or more columns to use to populate a full-\n text index\n -i, --index TEXT Add index on this column (or a compound index\n with -i col1,col2)\n --shape TEXT Custom shape for the DB table - format is\n csvcol:dbcol(TYPE),...\n --filename-column TEXT Add a column with this name and populate with\n CSV file name\n --no-index-fks Skip adding index to foreign key columns\n created using --extract-column (default is to\n add them)\n --no-fulltext-fks Skip adding full-text index on values extracted\n using --extract-column (default is to add them)\n --version Show the version and exit.\n --help Show this message and exit.\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/simonw/csvs-to-sqlite", "keywords": "", "license": "Apache License, Version 2.0", "maintainer": "", "maintainer_email": "", "name": "csvs-to-sqlite", "package_url": "https://pypi.org/project/csvs-to-sqlite/", "platform": "", "project_url": "https://pypi.org/project/csvs-to-sqlite/", "project_urls": { "Homepage": "https://github.com/simonw/csvs-to-sqlite" }, "release_url": "https://pypi.org/project/csvs-to-sqlite/1.0/", "requires_dist": [ "click (~=7.0)", "dateparser (~=0.7.1)", "pandas (~=0.25.0)", "py-lru-cache (~=0.1.4)", "six" ], "requires_python": "", "summary": "Convert CSV files into a SQLite database", "version": "1.0" }, "last_serial": 5627928, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "7119a576299e2ab10d3abbbef58f62c3", "sha256": "d36fd27445586cf2ef67e2b9709475a7cacf60ba3b35225f2a094e8e0ce66f10" }, "downloads": -1, "filename": "csvs_to_sqlite-0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7119a576299e2ab10d3abbbef58f62c3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 4206, "upload_time": "2017-11-13T06:36:37", "url": "https://files.pythonhosted.org/packages/88/ae/054d0e459ed0a81d4df4419b62f1b3ffbd2358c42fc505ce149e5116c741/csvs_to_sqlite-0.1-py2.py3-none-any.whl" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "dd57e5742076e491d485cbdb06a845c9", "sha256": "16f923ac7ea47f983d0cbbe352b9be8d040b7c366323a391d074d3c5e5be9249" }, "downloads": -1, "filename": "csvs_to_sqlite-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dd57e5742076e491d485cbdb06a845c9", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 4230, "upload_time": "2017-11-13T16:24:50", "url": "https://files.pythonhosted.org/packages/c4/21/b8c18e5ff59896ce8a0b755182e9a6e8ccfc8b657b5c1bb7eae921ecf9db/csvs_to_sqlite-0.2-py2.py3-none-any.whl" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "dd4b8b97563318da7ab23671fb0972e3", "sha256": "e70e73084b979aecc1829d3e1a46bea61b4437698c44dab9909ed48fc797a14a" }, "downloads": -1, "filename": "csvs_to_sqlite-0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dd4b8b97563318da7ab23671fb0972e3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6339, "upload_time": "2017-11-17T05:31:58", "url": "https://files.pythonhosted.org/packages/36/ca/43b97f0ea65a164088cd8993be50d14427583ffc54d3b6417b8896180e64/csvs_to_sqlite-0.3-py2.py3-none-any.whl" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "825d8e54e61823970a7b00904cc574dc", "sha256": "8418b8ec632700a104b490fa9fcbb21f7a69d37ccf32e6d15555032a088b6e72" }, "downloads": -1, "filename": "csvs_to_sqlite-0.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "825d8e54e61823970a7b00904cc574dc", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6870, "upload_time": "2017-11-19T05:14:19", "url": "https://files.pythonhosted.org/packages/1a/32/27a1dafa4bdee0029435e3b14621bdc81cd9f5e971ca2147a419e2e89709/csvs_to_sqlite-0.5-py2.py3-none-any.whl" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "8e94fc7505f64562a826a08d5c1ef43e", "sha256": "05b42c20468dd21323ab2aacfc47980c6060a62c7efd9d3f77bbb7b280e0fb6b" }, "downloads": -1, "filename": "csvs_to_sqlite-0.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8e94fc7505f64562a826a08d5c1ef43e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7776, "upload_time": "2017-11-24T23:14:38", "url": "https://files.pythonhosted.org/packages/16/20/87ce5f613f74ba3f63f630cf162bbbd21415853ba3f0188ccd685d69d3f5/csvs_to_sqlite-0.6-py2.py3-none-any.whl" } ], "0.6.1": [ { "comment_text": "", "digests": { "md5": "7307955504e51595e0d6db39d0535f4c", "sha256": "5fcac38e2e62df78497e12e7d752ff553fe9e127b76d862e5aab2cb8ef9f2270" }, "downloads": -1, "filename": "csvs_to_sqlite-0.6.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7307955504e51595e0d6db39d0535f4c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7955, "upload_time": "2017-11-25T02:59:12", "url": "https://files.pythonhosted.org/packages/09/73/4ecc05f944ee0d9989632d76346c32f2193f45f50d80e1aedbb464c1ae11/csvs_to_sqlite-0.6.1-py2.py3-none-any.whl" } ], "0.7": [ { "comment_text": "", "digests": { "md5": "c99a3e8e9006e978490b573bbab8b49d", "sha256": "2304ecea3ca83e9d5765f08a37ad4557bf8ff3a7d4d5ba2acfb527f32f9daa87" }, "downloads": -1, "filename": "csvs_to_sqlite-0.7-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c99a3e8e9006e978490b573bbab8b49d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7964, "upload_time": "2017-11-26T03:13:51", "url": "https://files.pythonhosted.org/packages/8b/ab/1a5c91451fc2ff49dceedd83fdfa4d1b8489304da9b2e355f7b7a82d6099/csvs_to_sqlite-0.7-py2.py3-none-any.whl" } ], "0.8": [ { "comment_text": "", "digests": { "md5": "1582e3c3777878071e211059a7712b2f", "sha256": "04e3b8ecde06750f53b648d061e8c141075596eb49c63e7ff16befb98c1e5972" }, "downloads": -1, "filename": "csvs_to_sqlite-0.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1582e3c3777878071e211059a7712b2f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10833, "upload_time": "2018-04-24T15:10:17", "url": "https://files.pythonhosted.org/packages/4e/11/44f8e61f8746d30df93523f5a3844ae093ed2f45849255f80379b9ce9f44/csvs_to_sqlite-0.8-py2.py3-none-any.whl" } ], "0.8.1": [ { "comment_text": "", "digests": { "md5": "b7fcf69868f6e424cb6f701e8a2b5358", "sha256": "b1bd64ff2da5816ac8b6fa5cab7038c4f8fbca1ef2c8d66b562f762f3d040a8a" }, "downloads": -1, "filename": "csvs_to_sqlite-0.8.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b7fcf69868f6e424cb6f701e8a2b5358", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10925, "upload_time": "2018-04-24T15:42:26", "url": "https://files.pythonhosted.org/packages/98/11/9312e49d4c694c3fbce2b5eb7df0ff88cff4ee6ab15b37dfdad59d671599/csvs_to_sqlite-0.8.1-py2.py3-none-any.whl" } ], "0.9": [ { "comment_text": "", "digests": { "md5": "09945bf96a8e8d8b34b6376e9867022d", "sha256": "da86f2ac9aef7e388be8e6d9ec4b9653d97a11a0c144be04dbeaf853fa0fe0d6" }, "downloads": -1, "filename": "csvs_to_sqlite-0.9-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "09945bf96a8e8d8b34b6376e9867022d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15982, "upload_time": "2019-01-17T05:20:15", "url": "https://files.pythonhosted.org/packages/a5/0a/3876aed1318a9bd05b59223ddf683d91eb10c5419012b179b9661fefd18b/csvs_to_sqlite-0.9-py2.py3-none-any.whl" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "5f0bd0c8aa13e686e08dcb1d0c13b5f6", "sha256": "641d0cb61840dbcf337c949ebdc195de71577681a27703785430ec13c3c6cf61" }, "downloads": -1, "filename": "csvs_to_sqlite-0.9.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5f0bd0c8aa13e686e08dcb1d0c13b5f6", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15983, "upload_time": "2019-06-24T15:20:58", "url": "https://files.pythonhosted.org/packages/75/4f/fb744d5f32cc77e78a0ff3fa5d52584303ab91b6cfa3a4b192e20139f373/csvs_to_sqlite-0.9.1-py2.py3-none-any.whl" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "d77696d75454a89f371f082097cef48c", "sha256": "e893fa6636954b30a54e602dbb3a8f1282db673c56c443583055c231aee6c0ce" }, "downloads": -1, "filename": "csvs_to_sqlite-0.9.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d77696d75454a89f371f082097cef48c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15981, "upload_time": "2019-07-03T04:39:42", "url": "https://files.pythonhosted.org/packages/9d/a8/5f277a5680082857045f47794d3d3ce8ac24e19b41f4096682c4030c2a2e/csvs_to_sqlite-0.9.2-py2.py3-none-any.whl" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "c83e2b72b735b9a247fc39c392bb7b6b", "sha256": "25135a5551265023dbe8d4d8c95e79d8ea2205dd19622d48df41bc4745932a3f" }, "downloads": -1, "filename": "csvs_to_sqlite-1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c83e2b72b735b9a247fc39c392bb7b6b", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 16002, "upload_time": "2019-08-03T10:57:40", "url": "https://files.pythonhosted.org/packages/ed/72/ccf4c85f3620de0b7a88279adb4dc6f869771735c3bd2eb8252f1c811b7a/csvs_to_sqlite-1.0-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c83e2b72b735b9a247fc39c392bb7b6b", "sha256": "25135a5551265023dbe8d4d8c95e79d8ea2205dd19622d48df41bc4745932a3f" }, "downloads": -1, "filename": "csvs_to_sqlite-1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c83e2b72b735b9a247fc39c392bb7b6b", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 16002, "upload_time": "2019-08-03T10:57:40", "url": "https://files.pythonhosted.org/packages/ed/72/ccf4c85f3620de0b7a88279adb4dc6f869771735c3bd2eb8252f1c811b7a/csvs_to_sqlite-1.0-py2.py3-none-any.whl" } ] }