{ "info": { "author": "Antonio Lima", "author_email": "anto87@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Tubo\n====\n\nTubo is a library that provides a simple pipeline system for Python.\n\nUnix pipe system is an excellent example of the concept of **separation of responsibility**. Each utility does a single thing well. This increases readability, maintainability of code and code reuse. Tubo wants to bring this abstraction to Python.\n\nInstallation\n------------\n\n.. code-block:: bash\n\n pip install tubo\n\nUsage\n-----\n\nYou have a source of iterable items and you want to perform various operations on them. In a Unix-like system you would write something like this:\n\n.. code-block:: bash\n\n cat foo.txt | op1 | op2 | op3\n\nUsing Tubo, instead, you would use Python and you would write something like this:\n\n.. code-block:: pycon\n\n >>> output = tubo.pipeline(file('foo.txt'), op1, op2, op3)\n\nAnd the output would be available for you, to print it or to further transform it as you prefer. The advantage is that you can write the operations in Python, giving you a lot of flexibility.\n\nCreate a pipeline\n-----------------\n\nThe central part of Tubo is the method `tubo.pipeline`. It accepts an arbitrary number of arguments, the first being a *data source* and the following being *operations* on iterable data, defined using python generators.\n\n**Each operation should `yield` something, so that the following operation can work.**\n\nExample: capitalize words that contain a `i` letter.\n\n.. code-block:: python\n\n text = ['italy', 'germany', 'brazil', 'france', 'england',\n 'argentina', 'peru', 'united states', 'australia',\n 'sweden', 'china', 'poland', 'portugal']\n\n def capitalize(lines):\n for line in lines:\n for word in line.split(\",\"):\n yield word.capitalize()\n\n def filter_wordwith_i(words):\n for word in words:\n if 'i' in word:\n yield word\n\n output = tubo.pipeline(\n text,\n filter_wordwith_i,\n capitalize,\n )\n\nAt this point, output is an iterable, and we can do anything we want with it. We can print it or further transform it.\n\nMerge two or more iterables\n---------------------------\n\nSometimes, you need to write functions that take two or more inputs, and process them. In this case, you need to write an operation that accepts a **list of iterables**.\n\nExample: interleave lines from two or more files (such as the utility `paste`)\n\n.. code-block:: python\n\n def interleave(listoflines):\n for lines in itertools.izip(*listoflines):\n yield ''.join(lines)\n\n output = tubo.pipeline(\n (file('file1.txt'), file('file2.txt')),\n interleave\n )\n\nConsume iterators at C-speed\n----------------------------\n\nOnce you have your pipeline, it's time to consume it.\n\n.. code-block:: python\n\n tubo.consume(output)\n\n # Equivalent to:\n # \n # for element in output:\n # pass \n\nThis consumes the iterator at C-speed, and uses `this recipe `_.\n\n\nExamples\n--------\n\nReverse text of unique lines, append the number of lines\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n def uniq(lines):\n seen = set()\n for line in lines:\n if line not in seen:\n seen.add(line)\n yield line\n\n def reverse_string(lines):\n for line in lines:\n yield ''.join(reversed(line))\n\n def append_nlines(lines):\n for nlines, line in enumerate(lines):\n yield line\n yield \"\\nTotal Number of lines: {}\".format(nlines+1)\n\n output = tubo.pipeline(\n open(filename),\n uniq,\n reverse_string,\n append_nlines,\n )\n\nConcatenate two files 1st words\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nWhen we need to merge two inputs, or two results of different pipes, we will use the functions `merge` and `merge_longest`, which will \n\n.. code-block:: python\n\n def select_Nth_word(N, lines):\n for line in lines:\n yield line.split(' ')[N]\n select_first_word = functools.partial(select_Nth_word, 0)\n select_second_word = functools.partial(select_Nth_word, 1)\n\n def concatenate(words):\n for word1, word2 in words:\n yield \"{} {}\".format(word1, word2)\n\n pipeline1 = tubo.pipeline(\n open(fname1),\n select_first_word,\n )\n pipeline2 = tubo.pipeline(\n open(fname2),\n select_second_word,\n )\n output = tubo.pipeline(\n tubo.merge(\n pipeline1,\n pipeline2,\n ),\n concatenate\n )\n\nCredits\n-------\n\nThe library was inspired from a `post by Christoph Rauch `_.\n\n\n\n.. :changelog:\n\nHistory\n-------\n\n0.1.1 (2014-08-02)\n~~~~~~~~~~~~~~~~~~\n\nNow works for Python3. Wheel added.\n\n0.1.0 (2014-08-02)\n~~~~~~~~~~~~~~~~~~\n\nInitial concept.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/themiurgo/tubo", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "tubo", "package_url": "https://pypi.org/project/tubo/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/tubo/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/themiurgo/tubo" }, "release_url": "https://pypi.org/project/tubo/0.1.1/", "requires_dist": null, "requires_python": null, "summary": "A pipeline library for Python that cuts down your boilerplate code.", "version": "0.1.1" }, "last_serial": 1177705, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "5f1876e2b33a5076ce1fc7ec762be92a", "sha256": "447d0f6a787e9e52abf214ecddec53e2f9e869959070c7084757b108f38fa82e" }, "downloads": -1, "filename": "tubo-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5f1876e2b33a5076ce1fc7ec762be92a", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6836, "upload_time": "2014-08-02T14:24:03", "url": "https://files.pythonhosted.org/packages/d0/fd/7c23f552a4750115c712a9f4c9ff6aebc0e3352ed0bd1958150bbbb3280d/tubo-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8efa4f6d82cc32f4e41ac3835ebcd953", "sha256": "21e6b3e6860321c2ef20c8206e64c2561e09e97f32893043aaf5b7586737cab7" }, "downloads": -1, "filename": "tubo-0.1.0.tar.gz", "has_sig": false, "md5_digest": "8efa4f6d82cc32f4e41ac3835ebcd953", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3018, "upload_time": "2014-08-02T11:12:24", "url": "https://files.pythonhosted.org/packages/87/18/e685fdf880f14c6bb7a1af89b7a8c50a6b6fb87903f820cd6cae4433df10/tubo-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "a9bcef604a65ffb4916a59395527d975", "sha256": "6fa9f73d68dae794e024cbcf68684d269519f543e223314dbab05a699dafb50b" }, "downloads": -1, "filename": "tubo-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a9bcef604a65ffb4916a59395527d975", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6927, "upload_time": "2014-08-02T14:32:23", "url": "https://files.pythonhosted.org/packages/ac/97/d0516efb74292b60155bdab44f1f420d1b25b6336ce4efb7557ba70cd6e1/tubo-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ec64b01e1fafc511ca9358c5f6e2158", "sha256": "13bc9e1b12085bb52ec0eeb8a73e65e7ca571956bb94129bbee5c5a58c23b71c" }, "downloads": -1, "filename": "tubo-0.1.1.tar.gz", "has_sig": false, "md5_digest": "8ec64b01e1fafc511ca9358c5f6e2158", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3897, "upload_time": "2014-08-02T14:32:21", "url": "https://files.pythonhosted.org/packages/64/6e/f59e21d6453d37126ecf94b536f8e26c5255a3e87acb40a66a712f9fefd7/tubo-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a9bcef604a65ffb4916a59395527d975", "sha256": "6fa9f73d68dae794e024cbcf68684d269519f543e223314dbab05a699dafb50b" }, "downloads": -1, "filename": "tubo-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a9bcef604a65ffb4916a59395527d975", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6927, "upload_time": "2014-08-02T14:32:23", "url": "https://files.pythonhosted.org/packages/ac/97/d0516efb74292b60155bdab44f1f420d1b25b6336ce4efb7557ba70cd6e1/tubo-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ec64b01e1fafc511ca9358c5f6e2158", "sha256": "13bc9e1b12085bb52ec0eeb8a73e65e7ca571956bb94129bbee5c5a58c23b71c" }, "downloads": -1, "filename": "tubo-0.1.1.tar.gz", "has_sig": false, "md5_digest": "8ec64b01e1fafc511ca9358c5f6e2158", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3897, "upload_time": "2014-08-02T14:32:21", "url": "https://files.pythonhosted.org/packages/64/6e/f59e21d6453d37126ecf94b536f8e26c5255a3e87acb40a66a712f9fefd7/tubo-0.1.1.tar.gz" } ] }