# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['dataknead', 'dataknead.loaders']

package_data = \
{'': ['*']}

install_requires = \
['openpyxl>=3.0.3,<4.0.0',
 'pandas>=0.24.2,<0.25.0',
 'pyyaml>=5.1,<6.0',
 'xlrd>=1.2,<2.0',
 'xlwt>=1.3,<2.0',
 'xmltodict>=0.12.0,<0.13.0']

entry_points = \
{'console_scripts': ['knead = dataknead.console:run']}

setup_kwargs = {
    'name': 'dataknead',
    'version': '0.3.1',
    'description': 'A fluid Python library and command line utility for processing and converting between data formats like JSON and CSV.',
    'long_description': '# dataknead\n\nA fluid Python library and command line utility for processing and converting between common data formats like JSON and CSV.\n\nHave you ever sighed when writing code like this?\n\n```python\nimport csv\nimport json\n\nwith open("names.json") as f:\n    data = json.loads(f.read())\n\ndata = [row["name"] for row in data if "John" in row["name"]]\n\nwith open("names.csv", "w") as f:\n    writer = csv.writer(f)\n    writer.writerow(["name"])\n    [writer.writerow([row]) for row in data]\n```\n\nNow you can write it like this:\n\n```python\nfrom dataknead import Knead\nKnead("names.json").filter(lambda r:"John" in r["name"]).write("names.csv")\n```\n\nOr what about simply converting `json` to `csv`? With `dataknead` you get the `knead` command line utility which makes things easy:\n\n```bash\nknead names.json names.csv\n```\n\n`dataknead` has inbuilt loaders for CSV, Excel, JSON and XML and you can easily write your own.\n\n## Installation\nInstall `dataknead` from [PyPi](https://pypi.python.org/pypi/dataknead)\n\n```shell\npip install dataknead\n```\n\nThen import\n\n```python\nfrom dataknead import Knead\n```\n\n## Basic example and tutorial\n\nLet\'s say you have a small CSV file with cities and their population called `cities.csv`.\n\n```csv\ncity,country,population\nAmsterdam,nl,850000\nRotterdam,nl,635000\nVenice,it,265000\n```\n\nAnd you want to load this csv file and transform it to a json file.\n\n```python\nfrom dataknead import Knead\n\nKnead("cities.csv").write("cities.json")\n```\n\nYou\'ll now have a json file called `cities.json` that looks like this:\n\n```json\n[\n    {\n        "city" : "Amsterdam",\n        "country" : "nl",\n        "population" : 850000\n    },\n    ...\n]\n```\n\nMaybe you just want the city names and write them to a CSV filed called `city-names.csv`.\n\n```python\nfrom dataknead import Knead\n\nKnead("cities.csv").map("city").write("city-names.csv")\n```\n\nThat will give you this list\n```csv\nAmsterdam\nRotterdam\nVenice\n```\n\nNow you want to extract only the cities that are located in Italy, and write that back to a new csv file called `cities-italy.csv`:\n\n```python\nfrom dataknead import Knead\n\nKnead("cities.csv").filter(lambda r:r["country"] == "it").write("cities-italy.csv")\n````\n\nThis gives you this:\n\n```csv\ncity,country,population\nVenice,it,265000\n```\n\nNice huh?\n\n## Advanced example\nCheck out [the advanced example](https://github.com/hay/dataknead/blob/master/tests/advanced_example.py). This also shows you how to do more complex data manipulation using external libraries like [jq](https://stedolan.github.io/jq/).\n\n## Philosophy\n`dataknead` is intended for easy conversion between common data formats and basic manipulation. It\'s not a replacement for more complex libraries like `pandas` or `numpy`, but instead can be a useful addition to those libraries.\n\nThe API is as minimal as possible and [fluent](https://en.wikipedia.org/wiki/Fluent_interface).\n\nI try to use as many existing and well-tested libraries as possible. For example, the XML loader uses the excellent [`xmltodict`](https://github.com/martinblech/xmltodict) module.\n\n## Command line utility (`knead`)\n\n`dataknead` includes the `knead` command line utility you can use for simple conversion of data formats.\n\n    knead cities.csv cities.json\n\nWill transform a filed called `cities.csv` to a file called `cities.json` and is equivalent to this piece of Python code\n\n    Knead("cities.csv").write("cities.json")\n\n`knead` can also be used as a quick way of viewing the contents of a file, just give it an input file\n\n    knead cities.csv\n\nThis is equivalant to\n\n    print(Knead("cities.csv").data())\n\nYou can also specify the input and output formats, when those are not available in the file extension, or if you want to overwrite them. This is useful in combination with the `--stdin` option, which allows you to take data from stdin and directly transform output from a HTTP API to something else.\n\nFor example, this API request gives you back a JSON summary of the article for Amsterdam on the English Wikipedia.\n\n    curl https://en.wikipedia.org/api/rest_v1/page/summary/Amsterdam\n\nPiping that into dataknead using --stdin and -if json gives you a nicely formatted file\n\n    curl https://en.wikipedia.org/api/rest_v1/page/summary/Amsterdam | knead --stdin -if json\n\n## API\n\n### *class* `dataknead.Knead(`*inp, parse_as = None, read_as = None, is_data = False*`)`\nIf `inp` is a string, a filepath is implied and the extension is used to get the correct loader.\n```python\nKnead("cities.csv")\n```\n\nTo overwrite this behaviour (for a file that doesn\'t have the correct extension), use the `read_as` argument.\n```python\nKnead("cities", read_as="csv")\n```\n\nIf `inp` is not a string, data is implied.\n```python\nKnead([1,2,3])\n```\n\nTo force a string to be used as data instead of a file path, set `is_data` to `True`.\n```python\nKnead("http://www.github.com", is_data = True)\n```\n\nTo force parsing of a string to data (e.g., from a JSON HTTP request), set `parse_as` to the correct format.\n```python\nKnead(\'{"error" : 404}\', parse_as="json")\n```\n\nSome loaders might come with extra arguments. E.g. the `csv` loader has an option to force using a header, if it isn\'t detected automatically\n\n```python\nKnead("cities.csv", has_header = True)\n```\n\n### `add_loader(*loader*)`\nAdd a new loader to the `Knead` instance. Read the section on [extending dataknead](#extending-dataknead) on how to write your own loader.\n\n```python\nKnead.add_loader(YamlLoader)\n```\n\n### `apply(`*fn*`)`\nRuns all data through a function.\n```python\nprint(Knead(["a", "b", "c"]).apply(lambda x:"".join(x))) # \'abc\'\n```\n\n### `data(`*check_instance = None*`)`\nReturns the parsed data.\n```python\ndata = Knead("cities.csv").data()\n```\n\nTo raise an exception for an invalid instance, pass that to `check_instance`.\n```python\ndata = Knead("cities.csv").data(check_instance = dict)\n```\n\n### `filter(`*fn*`)`\nRun a function over the data and only keep the elements that return `True` in that functon.\n```python\nKnead("cities.csv").filter(lambda city:city["country"] == "it").write("cities-italy.csv")\n\n# Or do this\ndef is_italian(city):\n    return city["country"]  == "it"\n\nKnead("cities.csv").filter(is_italian).write("cities-italy.csv")\n```\n\n### `keys()`\nReturns the keys of the data.\n\n### `map(`*fn* | *str* | *tuple*`)`\nRun a function over all elements in the data.\n```python\nKnead("cities.csv").map(lambda city:city["city"].upper()).write("cities-uppercased.json")\n```\n\nTo return one key in every item, you can pass a string as a shortcut:\n```python\nKnead("cities.csv").map("city").write("city-names.csv")\n\n# Is the same as\n\nKnead("cities.csv").map(lambda c:c["city"]).write("city-names.csv")\n```\n\nTo return multiple keys with values, you can use a tuple:\n```python\nKnead("cities.csv").map(("city", "country")).write("city-country-names.csv")\n\n# Is the same as\n\nKnead("cities.csv").map(lambda c:{ "city" : c["city"], "country" : c["country"] }).write("city-country-names.csv")\n\n# Or\n\ndef mapcity(city):\n    return {\n        "city" : city["city"],\n        "country" : city["country"]\n    }\n\nKnead("cities.csv").map(mapcity).write("city-country-names.csv")\n\n```\n\n### `values()`\nReturns values of the data.\n\n### `write(`*path, write_as = None*`)`\nWrites the data to a file. Type is implied by file extension.\n```python\nKnead("cities.csv").write("cities.json")\n```\n\nTo force the type to something else, pass the format to `write_as`.\n```python\nKnead("cities.csv").map("city").write("cities.txt", write_as="csv")\n```\n\nSome of the loaders have extra options you can pass to `write`:\n```Python\nKnead("cities.csv").write("cities.json", indent = 4)\nKnead("cities.csv").map("city").write("ciites.csv", fieldnames=["city"])\n```\n\n## Extending dataknead\nYou can write your own loaders to read and write other formats than the default ones. For an example take a look at the [YAML example](https://github.com/hay/dataknead/blob/master/tests/yaml_example.py).\n\n## Remarks\n* Note that `dataknead` is Python 3-only.\n\n## Credits\nWritten by [Hay Kranen](https://www.haykranen.nl).\n\n## License\nLicensed under the [MIT license](https://opensource.org/licenses/MIT).\n\n## Development information\nIf you want to work on `dataknead` follow these steps\n\nClone the repo\n\n    git clone https://github.com/hay/dataknead\n\nAnd use [Poetry](https://python-poetry.org/) to install dependencies\n\n    poetry install\n\nOr alternatively\n\n    pip install pandas pyyaml xlrd xlwt xmltodict\n\nYou might need to install a couple of dependencies beforehand\n\n    pip install wheel\n\nAnd (depending on your OS) some other deps too. For Debian / Ubuntu try\n\n    apt install build-essential autoconf libtool automake\n\n## Release history\n\n### 0.3\n* Breaking change: removed the `query` method: the focus of `dataknead` is on conversion. Using `apply` you can easily use a tool like `jq` to query.\n\n### 0.2\n* Adding tuple shortcut to `map` (#2)\n* Adding support for `txt` files ((#4)\n* Adding support for loader constructor argument passing, and adding a `has_header` option to `CsvLoader` (#5)\n\n### 0.1\nInitial release',
    'author': 'Hay Kranen',
    'author_email': 'huskyr@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/hay/dataknead',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'entry_points': entry_points,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
