{ "info": { "author": "Sergiy Kuzmenko", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: Public Domain", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development :: Interpreters" ], "description": "[![Build Status](https://semaphoreci.com/api/v1/shelldweller-39/etlite/branches/master/badge.svg)](https://semaphoreci.com/shelldweller-39/etlite)\n\n# ETlite\n\nExtract/Transform Light - a simple library for reading delimited files.\n\n## Example\n\nGiven CSV file:\n\n```\nArea id,Male,Female,Area\nA12345,34,45,0.25\nA12346,108,99,0.32\n```\n\nDefine a list of transformation:\n\n```python\ntransformations = [\n # Map existing fields into dictionary.\n # For nested dictionaries use dot.delimited.keys.\n # Optional \"via\" parameter takes a callable returning transformed value.\n { \"from\": \"Area id\", \"to\": \"id\" },\n { \"from\": \"Male\", \"to\": \"population.male\", \"via\": int },\n { \"from\": \"Female\", \"to\": \"population.female\", \"via\": int },\n { \"from\": \"Area\", \"to\": \"area\", \"via\": float },\n\n # You can also add computed values, not present in the original data source.\n # Computer values take transformed dictionary as argument\n # and they do not require \"from\" parameter:\n {\n \"to\": \"population.total\",\n \"via\": lambda x: x['population']['male'] + x['population']['female']\n },\n # Note that transformations are executed in the order they were defined.\n # This transformation uses population.total value computed in the previous step:\n {\n \"to\": 'population.density',\n \"via\": lambda x: round(x['population']['total'] / x['area']),\n }\n]\n```\n\nRead the file:\n\n```python\nfrom etlite import delim_reader\n\nwith open(\"mydatafile.csv\") as csvfile:\n reader = delim_reader(csvfile, transformations)\n data = [row for row in reader]\n```\n\nThis produces a list of dictionaries:\n\n```python\n[\n {\n 'id': 'A12345',\n 'area': 0.25,\n 'population': {\n 'male': 34,\n 'female': 45,\n 'total': 79,\n 'density': 316\n }\n },\n {\n 'id': 'A12346',\n 'area': 0.32,\n 'population': {\n 'male': 108,\n 'female': 99,\n 'total': 207,\n 'density': 647\n }\n }\n]\n```\n\n## `delim_reader` options\n\nETlite is just a thin wrapper on top of Python built-in [CSV module](https://docs.python.org/3/library/csv.html). Thus you can pass to `delim_reader` same options as you would pass to `csv.reader`. For example:\n\n```python\nreader = delim_reader(csvfile, transformations, delimiter=\"\\t\")\n```\n\n## Exception handling\n\nIf desired transtormation cannot be performed, ETLite will raise `TransformationError`. If you do not want to abort data loading, you can pass an error handler to `delim_reader`.\n\nError handler must be a function. It will be passed an instance of `TransformationError`. *Note: `on_error` must be pased as keywod argument.*\n\n```python\nfrom etlite import delim_reader\n\ntransformations = [\n # ...\n]\n\ndef error_handler(err):\n # err is an instance of TransformationError\n print(err) # prints error message\n print(err.record) # prints raw record, prior to transformation\n\n\nwith open('my-data.csv') as stream:\n reader = delim_reader(stream, transformations, on_error=error_handler)\n for row in reader:\n do_something(row)\n```\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/shelldweller/etlite", "keywords": "", "license": "Public Domain", "maintainer": "", "maintainer_email": "", "name": "etlite", "package_url": "https://pypi.org/project/etlite/", "platform": "any", "project_url": "https://pypi.org/project/etlite/", "project_urls": { "Homepage": "https://github.com/shelldweller/etlite" }, "release_url": "https://pypi.org/project/etlite/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "Extract/Transform Light - a simple library for reading delimited files.", "version": "0.1.1" }, "last_serial": 4398426, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "94faed0dbf38f92e62b17a8be3b94e3c", "sha256": "007cefc7eb58615933a0f92a0dfbae1352eb3bcc94d6c29fc3efed0a5d3c14b8" }, "downloads": -1, "filename": "etlite-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "94faed0dbf38f92e62b17a8be3b94e3c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3601, "upload_time": "2018-10-21T01:41:21", "url": "https://files.pythonhosted.org/packages/18/e4/096d5f097a4968f6fd263afe1e313c73ca1245031681a78164b995009582/etlite-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c4fc51dc16e4ab5723b29963b0a819b8", "sha256": "c90213acb439d8324cc585bf8247b9cffae33c3d2068a6bc9441558c2aff3a0a" }, "downloads": -1, "filename": "etlite-0.1.1.tar.gz", "has_sig": false, "md5_digest": "c4fc51dc16e4ab5723b29963b0a819b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3228, "upload_time": "2018-10-21T01:41:23", "url": "https://files.pythonhosted.org/packages/5c/c7/7c84d8ba557bd89a2606a7ace646eaf6173c353487f9ce33cb378aa7d943/etlite-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "94faed0dbf38f92e62b17a8be3b94e3c", "sha256": "007cefc7eb58615933a0f92a0dfbae1352eb3bcc94d6c29fc3efed0a5d3c14b8" }, "downloads": -1, "filename": "etlite-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "94faed0dbf38f92e62b17a8be3b94e3c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3601, "upload_time": "2018-10-21T01:41:21", "url": "https://files.pythonhosted.org/packages/18/e4/096d5f097a4968f6fd263afe1e313c73ca1245031681a78164b995009582/etlite-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c4fc51dc16e4ab5723b29963b0a819b8", "sha256": "c90213acb439d8324cc585bf8247b9cffae33c3d2068a6bc9441558c2aff3a0a" }, "downloads": -1, "filename": "etlite-0.1.1.tar.gz", "has_sig": false, "md5_digest": "c4fc51dc16e4ab5723b29963b0a819b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3228, "upload_time": "2018-10-21T01:41:23", "url": "https://files.pythonhosted.org/packages/5c/c7/7c84d8ba557bd89a2606a7ace646eaf6173c353487f9ce33cb378aa7d943/etlite-0.1.1.tar.gz" } ] }