{ "info": { "author": "Ramon Bartl", "author_email": "ramon.bartl@googlemail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# UNDERPY\n\n[![Build Status](https://travis-ci.org/ramonski/underpy.png)](https://travis-ci.org/ramonski/underpy)\n\n```\n _\n _ _ _ __ __| | ___ _ __ _ __ _ _\n | | | | '_ \\ / _` |/ _ \\ '__| '_ \\| | | |\n | |_| | | | | (_| | __/ | | |_) | |_| |\n \\__,_|_| |_|\\__,_|\\___|_| | .__/ \\__, |\n |_| |___/\n\nfunctional helpers for python\n```\n\n\n## Functions\n\n``` python\nalias(col, mapping)\n Returns a collection of dictionaries with the keys renamed according to\n the mapping\n\n >>> libraries = [{\"isbn\": 1, \"ed\": 1}, {\"isbn\": 2, \"ed\": 2}]\n >>> alias(libraries, {\"ed\": \"edition\"})\n [{'edition': 1, 'isbn': 1}, {'edition': 2, 'isbn': 2}]\n\n >>> alias({\"a\": 1}, {\"a\": \"b\"})\n [{'b': 1}]\n\nconvert(value, converter)\n Converts a value with a given converter function.\n\n >>> convert(\"1\", to_int)\n 1\n >>> convert(\"0\", to_int)\n 0\n >>> convert(\"a\", to_int)\n\nfail(error)\n Raises a RuntimeError with the given error Message\n\n >>> fail(\"This failed badly\")\n Traceback (most recent call last):\n ...\n RuntimeError: This failed badly\n\nfalsy(thing)\n checks if a value is False or None\n\n >>> falsy(0)\n False\n >>> falsy({})\n False\n >>> falsy([])\n False\n >>> falsy(None)\n True\n >>> falsy(False)\n True\n\nfirst(lst, n=None)\n get the first element of a list\n\n >>> lst = [1, 2, 3, 4, 5]\n >>> first(lst)\n 1\n >>> first(lst, 3)\n [1, 2, 3]\n\nis_dict(thing)\n checks if an object is a dictionary type\n\n >>> is_dict({})\n True\n >>> is_dict(dict())\n True\n >>> is_dict(\"{}\")\n False\n >>> is_dict([])\n False\n\nis_digit(thing)\n checks if an object is a digit\n\n >>> is_digit(1)\n True\n >>> is_digit(\"1\")\n True\n >>> is_digit(\"a\")\n False\n >>> is_digit([])\n False\n\nis_list(thing)\n checks if an object is a list type\n\n >>> is_list([])\n True\n >>> is_list(list())\n True\n >>> is_list(\"[]\")\n False\n >>> is_list({})\n False\n\nis_string(thing)\n checks if an object is a string/unicode type\n\n >>> is_string(\"\")\n True\n >>> is_string(u\"\")\n True\n >>> is_string(str())\n True\n >>> is_string(unicode())\n True\n >>> is_string(1)\n False\n\nis_tuple(thing)\n checks if an object is a tuple type\n\n >>> is_tuple(())\n True\n >>> is_tuple(tuple())\n True\n >>> is_tuple(\"()\")\n False\n >>> is_tuple([])\n False\n\nomit(dct, *keys)\n Returns a copy of the dictionary filtered to omit the blacklisted keys\n (or list of keys)\n\n >>> omit({\"name\": \"moe\", \"age\": 50, \"userid\": \"moe1\"}, \"userid\", \"age\")\n {'name': 'moe'}\n\npick(dct, *keys)\n Returns a copy of the dictionary filtered to only have values for the\n whitelisted keys (or list of valid keys)\n\n >>> pick({\"name\": \"moe\", \"age\": 50, \"userid\": \"moe1\"}, \"name\", \"age\")\n {'age': 50, 'name': 'moe'}\n\npluck(col, key, default=None)\n Extracts a list of values from a collection of dictionaries\n\n >>> stooges = [{\"name\": \"moe\", \"age\": 40},\n ... {\"name\": \"larry\", \"age\": 50},\n ... {\"name\": \"curly\", \"age\": 60}]\n >>> pluck(stooges, \"name\")\n ['moe', 'larry', 'curly']\n\n It only works with collections\n\n >>> curly = stooges.pop()\n >>> pluck(curly, \"age\")\n Traceback (most recent call last):\n ...\n RuntimeError: First argument must be a list or tuple\n\nrename(dct, mapping)\n Rename the keys of a dictionary with the given mapping\n\n >>> rename({\"a\": 1, \"BBB\": 2}, {\"a\": \"AAA\"})\n {'AAA': 1, 'BBB': 2}\n\nto_int(thing)\n coverts an object to int\n\n >>> to_int(\"0\")\n 0\n >>> to_int(1)\n 1\n >>> to_int(\"1\")\n 1\n >>> to_int(\"a\")\n\nto_list(thing)\n converts an object to a list\n\n >>> to_list(1)\n [1]\n\n >>> to_list([1,2,3])\n [1, 2, 3]\n\n >>> to_list((\"a\", \"b\", \"c\"))\n ['a', 'b', 'c']\n\n >>> to_list(dict(a=1, b=2))\n [{'a': 1, 'b': 2}]\n\nto_string(thing)\n coverts an object to string\n\n >>> to_string(1)\n '1'\n >>> to_string([])\n '[]'\n >>> to_string(u\"a\")\n 'a'\n\nto_iso_date(thing):\n converts an object to a iso date string\n\n >>> to_iso_date(\"\")\n ''\n >>> dt = datetime.date.fromtimestamp(1387452665)\n >>> to_iso_date(dt)\n '2013-12-19'\n\ntruthy(thing)\n checks if a value is True or not None\n\n >>> truthy(0)\n True\n >>> truthy({})\n True\n >>> truthy([])\n True\n >>> truthy(None)\n False\n >>> truthy(False)\n False\n```\n\n\n## Running the tests\n\n```\npython setup.py nosetests --with-doctest\n```\n\n\n## License\n\nMIT", "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/ramonski/underpy", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "underpy", "package_url": "https://pypi.org/project/underpy/", "platform": "any", "project_url": "https://pypi.org/project/underpy/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/ramonski/underpy" }, "release_url": "https://pypi.org/project/underpy/0.1.2/", "requires_dist": null, "requires_python": null, "summary": "Functional helpers for Python", "version": "0.1.2" }, "last_serial": 1046494, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "cd311fa4cd58b3c6dfa9e341e286bad0", "sha256": "25c45143c645e4e8a41a978a15dcb85f4dc83232db81d527029e11a5ff4a1cfc" }, "downloads": -1, "filename": "underpy-0.1.tar.gz", "has_sig": false, "md5_digest": "cd311fa4cd58b3c6dfa9e341e286bad0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4120, "upload_time": "2014-03-06T08:27:25", "url": "https://files.pythonhosted.org/packages/dd/16/119eb390957bb0d7f18158b7af813240b9f9cb4e7cd6abd26f24658f923a/underpy-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "ea0a8374f1c4aa5ec3a6b893766bf6f9", "sha256": "3d8cbbab0a030295bb531ea7096786d6fcfaf20c6d4a2e484ec582045291d422" }, "downloads": -1, "filename": "underpy-0.1.1.tar.gz", "has_sig": false, "md5_digest": "ea0a8374f1c4aa5ec3a6b893766bf6f9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4121, "upload_time": "2014-03-06T08:36:24", "url": "https://files.pythonhosted.org/packages/3f/c4/711b61b10b2b34ac8fde0a774c91d3ed5d6ba5bdc54b832d80286d94ec15/underpy-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "cf3fe276b1984b1838584344f8c73b2b", "sha256": "b4d460eabf3f8a6ddfc378eca47a03a98f3be2eb18a105adb3b1b1cecb29b34f" }, "downloads": -1, "filename": "underpy-0.1.2.tar.gz", "has_sig": false, "md5_digest": "cf3fe276b1984b1838584344f8c73b2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 130708, "upload_time": "2014-03-31T07:49:26", "url": "https://files.pythonhosted.org/packages/5c/4a/23e464fae0ba7134ae4a613e59647697e7bb71af7da693b3999fa71d4379/underpy-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cf3fe276b1984b1838584344f8c73b2b", "sha256": "b4d460eabf3f8a6ddfc378eca47a03a98f3be2eb18a105adb3b1b1cecb29b34f" }, "downloads": -1, "filename": "underpy-0.1.2.tar.gz", "has_sig": false, "md5_digest": "cf3fe276b1984b1838584344f8c73b2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 130708, "upload_time": "2014-03-31T07:49:26", "url": "https://files.pythonhosted.org/packages/5c/4a/23e464fae0ba7134ae4a613e59647697e7bb71af7da693b3999fa71d4379/underpy-0.1.2.tar.gz" } ] }