{ "info": { "author": "Damien Drix", "author_email": "damien.drix+pypi@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Framework :: IPython" ], "description": "callipy: call IPython notebooks with arguments\n==============================================\n\nDependencies\n------------\n\n- ``runipy``: https://github.com/paulgb/runipy\n- ``IPython`` (tested with IPython 2.3.0)\n\nInstallation\n------------\n\n::\n\n pip install callipy\n\nSimple Usage\n------------\n\nLet's create a notebook called ``notebook.ipynb``, containing the\nfollowing cell:\n\n::\n\n y = 2 * x\n\nNow let's call this notebook from another session with a value for ``x``\nand get the result ``y``:\n\n::\n\n >>> import callipy\n >>> callipy.call_notebook(\"notebook.ipynb\", x=2).y\n 4\n\nHow it works\n------------\n\nFirst the keyword arguments given to ``call_notebook`` are injected into\nthe notebook's namespace and ``runipy`` is used to execute all of its\ncells:\n\n::\n\n >>> result = callipy.call_notebook(\"notebook.ipynb\", x=2)\n >>> result\n \n\nAfter running the notebook, the value of any variable in the notebook's\nnamespace can be read using attribute or dict notation:\n\n::\n\n >>> result.y\n 4\n >>> result['y']\n 4\n\nNote: arguments and output values must be pickleable.\n\nFinally, the notebook object itself can be accessed as\n``result.notebook``. See https://github.com/paulgb/runipy for examples\nof things you can do with the notebook object.\n\nDefault values and validation\n-----------------------------\n\nThat's all good and well, but we have a slight problem: if we try to run\nthe target notebook on its own, it will complain about ``x`` not being\ndefined.\n\nThe solution is to declare the parameters and their default value at the\nbeginning of ``notebook.ipynb``:\n\n::\n\n %load_ext callipy\n %param x 5\n\nNow we can run the notebook from the browser, or call it without\narguments, and it will use the default value for every missing argument:\n\n::\n\n >>> callipy.call_notebook(\"notebook.ipynb\").y\n 10\n\nWhen more than one value is given, the parameter behaves as an\nenumerated type and the first value is the default value:\n\n::\n\n %param mode \"simple\", \"advanced\"\n\nIf the notebook is called with a value that was not declared, an error\nwill be raised:\n\n::\n\n >>> callipy.call_notebook(\"notebook.ipynb\", mode=\"wrong\")\n ValueError: Invalid value 'wrong' for parameter mode: \"simple\", \"advanced\"\n\nYou can customise this behaviour by giving as the default value an\nobject ``mydefault`` that supports the following:\n\n- ``mydefault[0]``: returns the default value\n- ``x in mydefault``: tests whether ``x`` is allowed\n\nNote that a lone string is treated as an atomic value, not as an\nenumeration of characters:\n\n::\n\n %param a \"test\" # the default value is 'test'\n %param b list(\"test\") # the default value is 't'\n\nFinally, a notebook can be queried for the parameters it declares:\n\n::\n\n >>> callipy.get_notebook_params(\"notebook.ipynb\")\n {'x': 5, 'mode': (\"simple\", \"advanced\")}\n\nCaveat: to extract this information, ``callipy`` must execute the\nnotebook. What if this takes time or produces side-effects? To alleviate\nthe problem, the instruction ``%params_done`` can be placed in the\nnotebook:\n\n::\n\n %param x 5\n %param mode \"simple\", \"advanced\"\n %params_done\n\nThen when calling ``get_notebook_params()`` anything after this cell\nwill be ignored.\n\nAcknowledgments\n---------------\n\nBased on the good work by **@paulgb**: https://github.com/paulgb/runipy\n\nAny reference to a famous statue is purely coincidental.", "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/damiendr/callipy", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "callipy", "package_url": "https://pypi.org/project/callipy/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/callipy/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/damiendr/callipy" }, "release_url": "https://pypi.org/project/callipy/0.3/", "requires_dist": null, "requires_python": null, "summary": "Calling IPython notebooks with arguments", "version": "0.3" }, "last_serial": 1300957, "releases": { "0.3": [ { "comment_text": "", "digests": { "md5": "49513215eff329561a232e33d63bdd78", "sha256": "a7c11757db06a696385a2f16e8475295efacb701642e1dd007ca77695dbfbc4f" }, "downloads": -1, "filename": "callipy-0.3.tar.gz", "has_sig": false, "md5_digest": "49513215eff329561a232e33d63bdd78", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2772, "upload_time": "2014-11-10T12:52:44", "url": "https://files.pythonhosted.org/packages/ff/ff/8dc8116eea82029c28e9155264dedec3c170d3c44ff46b991db7086c1488/callipy-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "49513215eff329561a232e33d63bdd78", "sha256": "a7c11757db06a696385a2f16e8475295efacb701642e1dd007ca77695dbfbc4f" }, "downloads": -1, "filename": "callipy-0.3.tar.gz", "has_sig": false, "md5_digest": "49513215eff329561a232e33d63bdd78", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2772, "upload_time": "2014-11-10T12:52:44", "url": "https://files.pythonhosted.org/packages/ff/ff/8dc8116eea82029c28e9155264dedec3c170d3c44ff46b991db7086c1488/callipy-0.3.tar.gz" } ] }