{ "info": { "author": "Shawn Brown", "author_email": "shawnbrown@users.noreply.github.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: Jython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Utilities" ], "description": "get-reader\n==========\n\n![devstatus] [![build-img]][build-url] ![pyversions] ![license]\n\nThis module provides a `get_reader()` function that returns reader\nobjects similar to those returned by `csv.reader()`. This package:\n\n* reads data from a variety of sources (CSV, Excel, pandas, etc.)\n* provides a single interface across Python versions (including\n seamless Unicode-aware CSV support for Python 2)\n* optionally manages file handling and reduces boilerplate code\n* has no hard dependencies\n* runs on Python 2.6, 2.7, 3.2 through 3.8, PyPy, PyPy3, and Jython\n* is freely available under the Apache License, version 2\n* can serve as a light-weight requirement for other projects or can\n be easily vendored directly into a codebase\n\n\n**Open a UTF-8 encoded CSV:**\n\n```python\nfrom get_reader import get_reader\n\nreader = get_reader('myfile.csv')\n\nfor row in reader:\n print(', '.join(row))\n```\n\nIn the above example, file handling is managed automatically by the\nreader object. The file is automatically closed when the iterator is\nexhausted or when the object is deleted. It also handles Unicode in\nPython 2 without changes.\n\n\n**Open a Latin-1 (ISO-8859-1) encoded CSV file:**\n\n```python\nreader = get_reader('myfile.csv', encoding='latin-1')\n\nfor row in reader:\n print(', '.join(row))\n```\n\n\n**Use the reader as a context manager:**\n\n```python\nwith get_reader('myfile.csv') as reader:\n for row in reader:\n print(', '.join(row))\n```\n\n\n**Access other data sources:**\n\n```python\n# From a pandas DataFrame, Series, Index, or MultiIndex.\ndf = pd.DataFrame([...])\nreader = get_reader(df) # requires pandas\n\n# From a database connection.\nconnection = ...\nreader = get_reader(connection, 'SELECT col1, col2 FROM mytable;')\n\n# From an Excel file--must install with 'excel' option.\nreader = get_reader('myfile.xlsx')\n\n# From a DBF file--must install with 'dbf' option.\nreader = get_reader('myfile.dbf')\n\n# From a squint Select, Query, or Result.\nselect = ...\nreader = get_reader(select({'col1': 'col2'}).sum())\n```\n\n\n**Call constructors directly to override auto-detect behavior:**\n\n```python\n# Specify tab-delimited data from a text file.\nreader = get_reader.from_csv('myfile.dat', delimiter='\\t')\n```\n\n\n## Install\n\nThe `get_reader` module has no hard dependencies; is tested on\nPython 2.6, 2.7, 3.2 through 3.8, PyPy, PyPy3, and Jython; and\nis freely available under the Apache License, version 2.\n\nYou can install `get_reader` using `pip`:\n\n```shell\npip install get_reader\n```\n\nTo install optional support for MS Excel and DBF files (dBase,\nFoxpro, etc.), use the following:\n\n```shell\npip install get_reader[excel,dbf]\n```\n\n**Python 2 Support Statement**\n\nWhile official support for Python 2 ends on January 1, 2020, this\nproject will continue to support older versions as long as the\nexisting ecosystem provides the ability to run automated tests\non those older versions.\n\n\n## Reference\n\n### get\\_reader(*obj*, \\**args*, \\*\\**kwds*)\n\nReturn a `Reader` object which will iterate over records in\nthe given *obj*\u2014like a `csv.reader()`. The given *obj* may\nbe one of the following:\n\n* CSV file (string path or file object)\n* iterable of dictionary rows\n* database connection (should be DBAPI2 compatible)\n* pandas DataFrame, Series, Index, or MultiIndex\n* squint Select, Query, or Result\n\nIf optional extras are installed, *obj* may also be:\n\n* MS Excel file path\n* DBF file path\n\nWhen *obj* is a file path, the `Reader` contains a file object\nthat is handled internally. When given a file-like *obj* (rather\nthan a path), users are responsible for properly closing this\nfile themselves.\n\nThe given *obj* is checked against supported types and\nautomatically passed to the appropriate constructor if a match is\nfound. If *obj* is a string, it is treated as a file path whose\nextension determines its content type. Any \\**args* and \\*\\**kwds*\nare passed along to the matching constructor:\n\n```python\nfrom get_reader import get_reader\n\n# CSV file.\nreader = get_reader('myfile.csv')\n\n# Database connection.\nconnection = ...\nreader = get_reader(connection, 'SELECT col1, col2 FROM mytable;')\n\n# Pandas DataFrame.\ndf = pd.DataFrame([...])\nreader = get_reader(df)\n\n# Excel file.\nreader = get_reader('myfile.xlsx', worksheet='Sheet2')\n```\n\nIf the *obj* type cannot be determined automatically, users can\ncall the constructor methods directly.\n\n\n#### Constructor Methods\n\n**get\\_reader.from\\_csv**(*csvfile*, *encoding*='utf-8', *dialect*='excel', \\*\\**kwds*)\n\nReturn a reader object which will iterate over lines in the\ngiven *csvfile*. The *csvfile* can be a string (treated as a\nfile path) or any object which supports the iterator protocol\nand returns a string each time its `__next__()` method is\ncalled\u2014file objects and list objects are both suitable. If\n*csvfile* is a file object, it should be opened with `newline=''`.\n\n```python\nfrom get_reader import get_reader\n\nreader = get_reader.from_csv('myfile.tab', delimiter='\\t')\n```\n\nUsing explicit file handling:\n\n```python\nfrom get_reader import get_reader\n\nwith open('myfile.csv') as csvfile:\n reader = get_reader.from_csv(fh)\n```\n\n\n**get\\_reader.from\\_dicts**(*records*, *fieldnames*=None)\n\nReturn a reader object which will iterate over the given\ndictionary *records*. This can be thought of as converting a\n`csv.DictReader()` into a plain, non-dictionary `csv.reader()`.\n\n```python\nfrom get_reader import get_reader\n\ndictrows = [\n {'A': 1, 'B': 'x'},\n {'A': 2, 'B': 'y'},\n]\n\nreader = get_reader.from_dicts(dictrows)\n```\n\nThis method assumes that record contents are consistent. If the first\nrecord is a dictionary, it is assumed that all following records will\nbe dictionaries with matching keys.\n\n\n**get\\_reader.from\\_sql**(*connection*, *table\\_or\\_query*)\n\nReturn a reader object which will iterate over the records\nfrom a given database table or over the records returned from\na SQL query. The *connection* should be a DBAPI2 compatible\ndatabase connection and *table\\_or\\_query* must be a string\nwith a table name or a SQL query.\n\nRead records from a specified table:\n\n```python\nfrom get_reader import get_reader\n\nconnection = ...\nreader = get_reader.from_sql(connection, 'mytable')\n```\n\nRead records from the results of a SQL query:\n\n```python\nreader = get_reader.from_sql(connection, 'SELECT col1, col2 FROM mytable;')\n```\n\n\n**get\\_reader.from\\_excel**(*path*, *worksheet*=0)\n\nReturn a reader object which will iterate over lines in the given\nExcel worksheet. The *path* must specify an XLSX or XLS file and\n*worksheet* must specify the index or name of the worksheet to\nload (defaults to the first worksheet).\n\nLoad first worksheet:\n\n```python\nfrom get_reader import get_reader\n\nreader = get_reader.from_excel('mydata.xlsx')\n```\n\nSpecific worksheets can be loaded by name (a string) or index\n(an integer):\n\n```python\nreader = get_reader.from_excel('mydata.xlsx', 'Sheet 2')\n```\n\n\n**get\\_reader.from\\_pandas**(*obj*, *index*=True)\n\nReturn a reader object which will iterate over records in\na pandas `DataFrame`, `Series`, `Index` or `MultiIndex`.\n\n```python\nimport pandas as pd\nfrom get_reader import get_reader\n\ndf = pd.DataFrame(...)\nreader = get_reader.from_pandas(df)\n```\n\n\n**get\\_reader.from\\_dbf**(*filename*, *encoding*=None, \\*\\**kwds*)\n\nReturn a reader object which will iterate over lines in the given\nDBF file (from dBase, FoxPro, etc.).\n\n```python\nfrom get_reader import get_reader\n\nreader = get_reader.from_dbf('myfile.dbf')\n```\n\n\n**get\\_reader.from\\_squint**(*obj*, *fieldnames*=None)\n\nReturn a reader object which will iterate over the records returned\nfrom a squint `Select`, `Query`, or `Result`. If the *fieldnames*\nargument is not provided, this function tries to construct names\nusing the values from the underlying object.\n\n```python\nimport squint\nfrom get_reader import get_reader\n\nselect = squint.Select(...)\nreader = get_reader.from_squint(select)\n```\n\n\n### *class* Reader(*iterable*, *closefunc=\\*)\n\nAn iterator which will produce rows from the given *iterable*. The\ngiven *iterable* should produce non-string sequences. An optional\n*closefunc* may be provided to close associated resources (files,\ndatabase cursors, etc.) once the reader is no longer needed\u2014it will\nbe automatically called when:\n\n* the iterable is exhausted\n* exiting a `with` statement (if used as a context manager)\n* the Reader is garbage collected\n\n\n**Reader.close**()\n\nCloses any associated resources (calls *closefunc* early):\n\n```python\nfrom get_reader import Reader\n\nreader = Reader(..., closefunc=...)\nreader.close() # <- Explicitly close resources.\n```\n\nIf the resources have already been closed, this method passes\nwithout error.\n\n\n### *class* ReaderLike()\n\nAn abstract class that can be used for type checking. Objects\nwill test as `ReaderLike` if they are instances of `Reader` or\n`csv.reader()` or if they are non-exhaustible iterables that\nproduce non-string sequences:\n\n```python\n>>> from get_reader import ReaderLike\n>>> isinstance(csv.reader(csvfile), ReaderLike)\nTrue\n\n>>> isinstance(get_reader(csvfile), ReaderLike)\nTrue\n\n>>> list_of_lists = [['col1', 'col2'], ['a', 'b']]\n>>> isinstance(list_of_lists, ReaderLike)\nTrue\n\n>>> list_of_strings = ['col1,col2', 'a,b']\n>>> isinstance(list_of_strings, ReaderLike)\nFalse\n\n>>> list_of_sets = [{'col1', 'col2'}, {'a', 'b'}]\n>>> isinstance(list_of_sets, ReaderLike)\nFalse\n```\n\n------------------------------------\n\nFreely licensed under the Apache License, Version 2.0\n\n(C) Copyright 2018 \u2013 2019 Shawn Brown.\n\n\n[devstatus]: https://img.shields.io/pypi/status/get_reader.svg\n[build-img]: https://api.travis-ci.org/shawnbrown/get_reader.svg?branch=master\n[build-url]: https://travis-ci.org/shawnbrown/get_reader\n[pyversions]: https://img.shields.io/pypi/pyversions/get_reader.svg\n[license]: https://img.shields.io/badge/license-Apache%202-blue.svg\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/shawnbrown/get_reader", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "get-reader", "package_url": "https://pypi.org/project/get-reader/", "platform": "", "project_url": "https://pypi.org/project/get-reader/", "project_urls": { "Homepage": "https://github.com/shawnbrown/get_reader" }, "release_url": "https://pypi.org/project/get-reader/0.0.2/", "requires_dist": [ "dbfread ; extra == 'dbf'", "xlrd ; extra == 'excel'" ], "requires_python": ">=2.6.*, !=3.0.*, !=3.1.*", "summary": "get_reader() returns csv.reader-like objects for Python 2 and 3", "version": "0.0.2" }, "last_serial": 5870076, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d39e697094b0f63cddbc745d902e9b92", "sha256": "a708b9b2c1d729b68e869ce4d6c224c9fd79fd53bd278d1b855df479a17e456f" }, "downloads": -1, "filename": "get_reader-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d39e697094b0f63cddbc745d902e9b92", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.6.*, !=3.0.*, !=3.1.*", "size": 7400, "upload_time": "2019-08-12T02:55:18", "url": "https://files.pythonhosted.org/packages/3d/07/1c62b2ff475adde08bf0cad5a7c9a96cedd6d45c8210e4cf921bf52cbf99/get_reader-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0fef08eca9eb05e2159e7a2db18541f9", "sha256": "44b74b3dc90b88d89c8a49ade1f8f2b5f928db52a0818208e520b5e79912af98" }, "downloads": -1, "filename": "get_reader-0.0.1.tar.gz", "has_sig": false, "md5_digest": "0fef08eca9eb05e2159e7a2db18541f9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6.*, !=3.0.*, !=3.1.*", "size": 11257, "upload_time": "2019-08-12T02:55:20", "url": "https://files.pythonhosted.org/packages/64/7e/859f0ed361036a446aab5d5de97fe47c89ae2f14110ca61d61e3adf186d0/get_reader-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "2e5126893d7200fb4b1c73ad18f3c4c1", "sha256": "4514098811cd94d3ecf4fa10717760adde7b4cd20d46f353e068dba23e0621cd" }, "downloads": -1, "filename": "get_reader-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2e5126893d7200fb4b1c73ad18f3c4c1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.6.*, !=3.0.*, !=3.1.*", "size": 10468, "upload_time": "2019-09-22T19:18:23", "url": "https://files.pythonhosted.org/packages/4f/79/c25fd4090e4ffef2cf7328c519d47f8714f0375209c2c4ba3269d4f7abbf/get_reader-0.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6f51c139713b2ef99b54909778ec95bc", "sha256": "3d281ca045fd06369fa917f453dcba5ab0ce3d63ca626b31c60d526c1d4fc6c0" }, "downloads": -1, "filename": "get_reader-0.0.2.tar.gz", "has_sig": false, "md5_digest": "6f51c139713b2ef99b54909778ec95bc", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6.*, !=3.0.*, !=3.1.*", "size": 11699, "upload_time": "2019-09-22T19:18:25", "url": "https://files.pythonhosted.org/packages/0a/e7/7e548f6a6af805fb044dbeed03a3ba9b905cf9e44640875c168035909df3/get_reader-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2e5126893d7200fb4b1c73ad18f3c4c1", "sha256": "4514098811cd94d3ecf4fa10717760adde7b4cd20d46f353e068dba23e0621cd" }, "downloads": -1, "filename": "get_reader-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2e5126893d7200fb4b1c73ad18f3c4c1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.6.*, !=3.0.*, !=3.1.*", "size": 10468, "upload_time": "2019-09-22T19:18:23", "url": "https://files.pythonhosted.org/packages/4f/79/c25fd4090e4ffef2cf7328c519d47f8714f0375209c2c4ba3269d4f7abbf/get_reader-0.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6f51c139713b2ef99b54909778ec95bc", "sha256": "3d281ca045fd06369fa917f453dcba5ab0ce3d63ca626b31c60d526c1d4fc6c0" }, "downloads": -1, "filename": "get_reader-0.0.2.tar.gz", "has_sig": false, "md5_digest": "6f51c139713b2ef99b54909778ec95bc", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6.*, !=3.0.*, !=3.1.*", "size": 11699, "upload_time": "2019-09-22T19:18:25", "url": "https://files.pythonhosted.org/packages/0a/e7/7e548f6a6af805fb044dbeed03a3ba9b905cf9e44640875c168035909df3/get_reader-0.0.2.tar.gz" } ] }