{ "info": { "author": "M\u00e9d\u00e9ric Hurier (fmind)", "author_email": "fmind@fmind.me", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta" ], "description": "# gampy\n\nGampy provides experimental constructs to improve your Python programs.\n\n## Pipeline\n\nWhile functional programming is a great paradigm to create data pipelines, some operations remains hard to express:\n- wrap every function of a data pipeline with an external function (e.g. logging, safe exception handling ...)\n- concatenate and transform data pipelines with algebra operators (e.g. convert and compare a pipeline ...)\n- apply the `compose` and `partial` operators on a data pipeline to create a single callable function\n\nGampy Pipeline is a data structure created to address these problems.\n\nHere is an example of a simple pipeline:\n\n```python\nfrom gampy.structures import Pipeline\n\npipeline = Pipeline([\n (map, [lambda x: x + 1], {}),\n (filter, [lambda x: x % 2 == 0]),\n (list,)\n])\n```\n\nEach **step** of the pipeline is represented as a 3-tuple: `(function, arguments, keyword arguments)`. While `function` is mandatory, `arguments` and `keyword argument` will be replaced by `list()` and `dict()` respectively if they are missing. This structure allows the creation of **unevaluated expression**, that can be further transformed prior to their execution.\n\nThe most interesting operations over a pipeline are `()` (call) and `@` (matmul).\n\n`Call` converts the pipeline into a single function. This process is divided in two steps:\n- `functools.partial` is applied on each step arguments to create a single function per step\n- functions are composed two by two with `functools.reduce` to create a single function per pipeline\n\n```python\n>>> f = pipeline()\n>>> f(range(10))\n30\n```\n\n`Matmul` applies **an advice** to each function of the pipeline. This allows the expression of cross concern aspects.\n\nIn the snippet below, any exception raised by a pipeline function will return `None`.\n\n```python\nfrom gampy.advices import exceptional\n\nsafepipe = pipeline @ exceptional(None)\n```\n\nAn advice is similar to a **parametrized decorator**, which create a function that takes a function and replaced it by a new function. The purpose is to extend the behavior of the original function.\n\n```python\ndef exceptional(x: Any = None, on: Type[Exception] = Exception) -> Advice:\n \"\"\"Return x when f raises an exception.\"\"\"\n\n def advice(f):\n @wraps(f)\n def wrapped(*args, **kwargs):\n try:\n return f(*args, **kwargs)\n except on:\n return x\n\n return wrapped\n\n return advice\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/fmind/gampy", "keywords": "general abstract meta programming", "license": "LGPL-3.0", "maintainer": "", "maintainer_email": "", "name": "gampy", "package_url": "https://pypi.org/project/gampy/", "platform": "", "project_url": "https://pypi.org/project/gampy/", "project_urls": { "Homepage": "https://github.com/fmind/gampy" }, "release_url": "https://pypi.org/project/gampy/1.1.0/", "requires_dist": null, "requires_python": ">=3.7", "summary": "General Abstract Meta Programming for Python", "version": "1.1.0" }, "last_serial": 5819386, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "af43fc9e374d645d9e9e5cddc6e54999", "sha256": "25406f83787c6660f12bb33aa96a37bc6b023ad640437297f02f317ef7cc763f" }, "downloads": -1, "filename": "gampy-0.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "af43fc9e374d645d9e9e5cddc6e54999", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6", "size": 4086, "upload_time": "2018-10-11T13:40:00", "url": "https://files.pythonhosted.org/packages/44/e9/57c517bbf7031c77b7446ec08ff7176689e823acf1570447a628480adb69/gampy-0.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1ce87605a0c616fd6607ee5c026fb44e", "sha256": "a7f651ba21ad8b0b64656eaee384c375263662d99b962c9f3e706ff6947002dd" }, "downloads": -1, "filename": "gampy-0.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1ce87605a0c616fd6607ee5c026fb44e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 1536, "upload_time": "2018-09-04T16:10:12", "url": "https://files.pythonhosted.org/packages/92/fb/97d9defbc55010ff05cb174ab0c56e460406f9e59605a9ec69d5f7bad4f4/gampy-0.0.0-py3-none-any.whl" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "076a97fc7e07074f55029719956a0ee2", "sha256": "95b8868e203d35d7f99306a752a4301b05d6c3c56fece8a15722db1a0263f53a" }, "downloads": -1, "filename": "gampy-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "076a97fc7e07074f55029719956a0ee2", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.7.0", "size": 5541, "upload_time": "2018-10-18T19:21:38", "url": "https://files.pythonhosted.org/packages/4c/d7/5eb48527aea1b5d7f05aa2c7949524dd29609f84afa7e2bedf721d1b7f7d/gampy-1.0.0-py2.py3-none-any.whl" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "c69cdc82b84da03d817c8d3d6051dc9b", "sha256": "9409bdd7be49cddef0beaa134183e96064999e2d916d11713097c6893b469788" }, "downloads": -1, "filename": "gampy-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c69cdc82b84da03d817c8d3d6051dc9b", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.7.0", "size": 6612, "upload_time": "2018-10-21T19:07:20", "url": "https://files.pythonhosted.org/packages/51/83/d8bfe52b9ba946eee9213e25162de2163fa40159abdc815968d7c55be94d/gampy-1.0.1-py2.py3-none-any.whl" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "3e0deb5f7cd0d3dd7450bedd5a800cd1", "sha256": "773a2c0dd18205a52b915b9c3e0145ca9417364052cc565d5c27a444969971a5" }, "downloads": -1, "filename": "gampy-1.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3e0deb5f7cd0d3dd7450bedd5a800cd1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.7", "size": 6490, "upload_time": "2019-09-12T09:44:01", "url": "https://files.pythonhosted.org/packages/d5/7f/b86a1e3b2669928c20bee443d7b73a9b340e44e0c00076ddebf07d40292d/gampy-1.1.0-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3e0deb5f7cd0d3dd7450bedd5a800cd1", "sha256": "773a2c0dd18205a52b915b9c3e0145ca9417364052cc565d5c27a444969971a5" }, "downloads": -1, "filename": "gampy-1.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3e0deb5f7cd0d3dd7450bedd5a800cd1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.7", "size": 6490, "upload_time": "2019-09-12T09:44:01", "url": "https://files.pythonhosted.org/packages/d5/7f/b86a1e3b2669928c20bee443d7b73a9b340e44e0c00076ddebf07d40292d/gampy-1.1.0-py2.py3-none-any.whl" } ] }