{ "info": { "author": "Jack Maney", "author_email": "jackmaney@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2 :: Only", "Topic :: Utilities" ], "description": "When importing CSV files to databases, I sometimes find it tedious to create the table in a database first. This is a very basic app (and a work in progress) that grabs the rows of a CSV file (sampling, if specified), uses the sample to guess at the data types of the columns, and uses these guesses to output a SQL `CREATE TABLE` statement. Think of it as a version of `CREATE TABLE some_table AS SELECT * FROM `.\n\nFor the moment, this is aimed towards PostgreSQL (although that will change) and for now, a very limited number of data types will be supported, namely `text`, `boolean`, `smallint`, `int`, `bigint`, `numeric`, `date`, and `timestamp` (which are the types that I find myself using the most often).\n\nTo install, you can use pip:\n\n```\nsudo pip install csv-to-table\n```\n\nor you can grab the code (via either a `git clone` or just downloading a zip file of the repository) and then doing a\n\n```\npython setup.py install\n```\n\nHere's the flowchart of the type guessing (it's also available in the `images` folder of this repo):\n\n![flowchart](https://github.com/jackmaney/csv-to-table/blob/master/images/type_guessing_flowchart.png?raw=true)\n\nHere's a quick example:\n\nInput:\n\n```\n$cat test.csv\na,b,c,d,e\n32,\"2013-12-28 22:16:57\",0,\"True\",\"Here's some text, and some more\"\n\"17.1\",\"2012-06-29 05:11:00\", -3,\"False\",\"Yep, more text\"\n```\n\nCode:\n\n```\nfrom typeguesser import TypeGuesser\n\ntg = TypeGuesser(\"test.csv\", header=True)\n\ntg.guessTypes()\n\nprint tg.getCreateStatement()\n```\n\nOutput:\n\n```\n$ python test.py\nCREATE TABLE test (\n a numeric,\n b timestamp,\n c smallint,\n d boolean,\n e text\n);\n```\n\nOr, equivalently, you can use the included script `csv-to-table.py`:\n\n```\n$ ./csv-to-table.py -h\nusage: csv_to_table.py [-h] [--header] [--lowercase_header] [--sample SAMPLE]\n[--quotechar QUOTECHAR] [--delimiter DELIMITER]\n[--table_name TABLE_NAME] [--columns COLUMNS]\nfile\n\npositional arguments:\nfile The name (and path) of the target CSV file\n\noptional arguments:\n-h, --help show this help message and exit\n--header Indicate whether or not the file has a header\n--lowercase_header Indicate whether or not to lowercase inferred column\nnames.\n--sample SAMPLE Sampling probability (between 0 and 1). If set, this\ngives the sampling probability for rows of the given\nCSV file\n--quotechar QUOTECHAR\nThe quote character to use for the CSV file (default\n '\"')\n --delimiter DELIMITER\n The delimiter to use for the CSV file (default ',')\n --table_name TABLE_NAME\n The name of the table desired in the output\n --columns COLUMNS A comma-delimited list of column names that you wish\n to use\n\n```\n\nSo, in particular:\n\n```\n$ ./csv-to-table.py --header test.csv\nCREATE TABLE test (\n\ta numeric,\n\tb timestamp,\n\tc smallint,\n\td boolean,\n\te text\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/jackmaney/csv_to_table.py.git", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "csv_to_table", "package_url": "https://pypi.org/project/csv_to_table/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/csv_to_table/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/jackmaney/csv_to_table.py.git" }, "release_url": "https://pypi.org/project/csv_to_table/0.0.3/", "requires_dist": null, "requires_python": null, "summary": "Generates a CREATE TABLE statement from a CSV file by guessing at column types", "version": "0.0.3" }, "last_serial": 1331189, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "504525f52ef5137c1337b61e3accaec3", "sha256": "6eb4e8a567698ac080696561b177eec34beb644953d7aac9535564b4f02ed1a4" }, "downloads": -1, "filename": "csv_to_table-0.0.1.tar.gz", "has_sig": false, "md5_digest": "504525f52ef5137c1337b61e3accaec3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5272, "upload_time": "2014-02-08T04:08:42", "url": "https://files.pythonhosted.org/packages/f5/4d/7d24679256bba71230128e0f4a083f08753904f3b226380c350935f74bb1/csv_to_table-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "3f7e3d9cb32e9125973d711df47089c2", "sha256": "3d344db223e46da423ef34e21693b5b3561029643185838e3150afbd72050f7e" }, "downloads": -1, "filename": "csv_to_table-0.0.2.tar.gz", "has_sig": false, "md5_digest": "3f7e3d9cb32e9125973d711df47089c2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5487, "upload_time": "2014-02-12T00:34:12", "url": "https://files.pythonhosted.org/packages/e0/1f/b0182a7a413a80e3f9f6893c7fddbb69b2b137b73620af31d72b9aef172a/csv_to_table-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "c576220999a2050a8857b12448eba52a", "sha256": "d260e322057830f382ee3846751721ea6993c1e4de6f49e6125819bf54d3cfaa" }, "downloads": -1, "filename": "csv_to_table-0.0.3.tar.gz", "has_sig": false, "md5_digest": "c576220999a2050a8857b12448eba52a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5729, "upload_time": "2014-12-04T17:33:05", "url": "https://files.pythonhosted.org/packages/ea/6f/482c003d9566b21b73d1276039c9929e0b1990d64e2e48d0f461c336a152/csv_to_table-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c576220999a2050a8857b12448eba52a", "sha256": "d260e322057830f382ee3846751721ea6993c1e4de6f49e6125819bf54d3cfaa" }, "downloads": -1, "filename": "csv_to_table-0.0.3.tar.gz", "has_sig": false, "md5_digest": "c576220999a2050a8857b12448eba52a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5729, "upload_time": "2014-12-04T17:33:05", "url": "https://files.pythonhosted.org/packages/ea/6f/482c003d9566b21b73d1276039c9929e0b1990d64e2e48d0f461c336a152/csv_to_table-0.0.3.tar.gz" } ] }