{"id":18420579,"url":"https://github.com/openworm/org.geppetto.frontend.jupyter","last_synced_at":"2025-04-07T13:32:05.962Z","repository":{"id":11250838,"uuid":"68935090","full_name":"openworm/org.geppetto.frontend.jupyter","owner":"openworm","description":"Geppetto Jupyter Notebook Extension","archived":false,"fork":false,"pushed_at":"2023-03-04T03:00:02.000Z","size":3452,"stargazers_count":5,"open_issues_count":27,"forks_count":4,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-22T19:42:36.470Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://geppetto.org","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openworm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-22T15:29:37.000Z","updated_at":"2023-07-04T06:41:45.000Z","dependencies_parsed_at":"2023-01-13T18:00:27.969Z","dependency_job_id":null,"html_url":"https://github.com/openworm/org.geppetto.frontend.jupyter","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Forg.geppetto.frontend.jupyter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Forg.geppetto.frontend.jupyter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Forg.geppetto.frontend.jupyter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Forg.geppetto.frontend.jupyter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openworm","download_url":"https://codeload.github.com/openworm/org.geppetto.frontend.jupyter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247661874,"owners_count":20975139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T04:22:17.874Z","updated_at":"2025-04-07T13:32:04.557Z","avatar_url":"https://github.com/openworm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/tarelli/bucket/blob/master/geppetto%20logo.png?raw=true\" alt=\"Geppetto logo\"/\u003e\n\u003c/p\u003e\n\n# Geppetto Jupyter Notebook Extension\nThis is an experimental repo for a Jupyter notebook [extension](https://ipython.readthedocs.io/en/stable/config/extensions/). \nThis extension enables the Jupyter Python server based \non tornado that allows the client to establish a websocket connection and serve static resources.\n\nOther than serving the application as a Geppetto backend, Jupyter Geppetto allows, by embedding a notebook in the page, \nto interact with the notebook and synchronize frontend features with the notebook.\n\n## How to install\n\nBefore installing, it is recommended to activate a Python 3 virtual environment:\n```bash\npython3 -m venv jupyter-geppetto\nsource jupyter-geppetto/bin/activate\n```\n\nOr, with conda\n\n```bash\nconda create -n jupyter-geppetto python=3.7\nconda activate jupyter-geppetto\n```\n\nInstall with pip\n```bash\npip install jupyter_geppetto\njupyter nbextension enable --py --sys-prefix jupyter_geppetto\n```\n\nInstall extension from sources\n```bash\ngit clone --recursive https://github.com/openworm/org.geppetto.frontend.jupyter.git\npip install .\n\njupyter nbextension install --py --symlink --sys-prefix jupyter_geppetto\njupyter nbextension enable --py --sys-prefix jupyter_geppetto\njupyter serverextension enable --py --sys-prefix jupyter_geppetto\n```\n## Overwrite the local install\n```bash\npip install . --upgrade --no-deps --force-reinstall\n```\nNotice: old installs made without --sys-prefix (so )\n\n## How to run\nAfter the extension is installed the Jupyter notebook must be run with the parameter --library, which specifies the \nPython libraries to be loaded together with the extension:\n```bash\nexec jupyter notebook --NotebookApp.default_url=/geppetto --NotebookApp.token='' --library=my_geppetto_application_lib\n```\n\nTo connect go to the URL:\nhttp://localhost:8888/geppetto\nassuming the default Jupyter configuration, otherwise change the port accordingly.\n\nNote if you get a 404 and you have a custom configuration of Jupyter notebook you will have to add the following to your jupyter_notebook_config.py:\n```\nc.NotebookApp.nbserver_extensions = {'jupyter_geppetto':True}\n```\n\n\n# Development \n\nJupyter Geppetto serves In order to use the synchronization capability, \n\n## Geppetto websocket api\nJupyter Geppetto implements the websocket api through a Tornado handler. It supports the messages coming from\na [geppetto-application](https://github.com/openworm/geppetto-application) frontend. See \n[geppetto-client](https://github.com/openworm/geppetto-client) for the available messages and implementation.\n\nCurrently, only a subset of the messages is supported. For further information, see the current release of \n[pygeppetto](https://github.com/openworm/pygeppetto).\n\n## Web api\nAllows to add own custom routes and handlers from inside the application.\nThe dependencies must be added from within the libraries specified in the parameter --library\n\nIn the file root of your module (__init__.py of your package), call the RouteManager methods to add your custom routes:\n```python\nfrom jupyter_geppetto.webapi import RouteManager\n\nRouteManager.add_controller(MyController) # Add a controller (preferred way for http requests)\nRouteManager.add_route('/my/path', MyTornadoHandler) # for more custom control\n```\n\nA controller class is a standard class with webapi annotations on methods.\nMethods return the response as a string.\nThe RouteManager creates a handler for each method and binds the method with the handler.\n\nExample:\n```Python\nfrom jupyter_geppetto.webapi import get, post\n\nclass MyController:\n\n    @get('/my/simple/path')\n    def simple_action(handler):\n        return \"My response payload\" # Simple text response\n\n    @get('/myresource/(.*)')\n    def action_with_url_param(handler, param):\n        import json\n        return json.dumps({'param':param}) # JSON response\n    \n    @get('/myresource')\n    def action_with_query_string_params(handler, param1, param2=None):\n        '''Handles \n            /myresource?param1=something\u0026param2=somethingelse\n            /myresource?param1=something\n        '''\n        return ...   \n    \n    @get('/myresource1')\n    def alt_action_with_query_string_params(handler, **kwargs):\n        '''Handles any query string parameter'''\n        return ...   \n        \n    @get('/myresource1/(.*)')\n    def action_with_url_and_query_string_params(handler, param, param1, param2):\n        '''Handles /myresource?param1=comething\u0026param2=somethingelse'''\n        return ... \n        \n    @post('/myresource2')\n    def simple_post_action(handler, payload, param1, param2):\n        '''Handles /myresource and body param1=something\u0026param2=somethingelse'''\n        return ... \n        \n    @get('/myresource3', {'Content-type': 'image/png', 'Cache-Control': 'max-age=600'})\n    def get_action_with_headers(handler):\n        '''Sets headers'''\n        return ... \n        \n    @get('/myresource3')\n    def get_action_use_handler(handler):\n        '''The first parameter is the tornado handler'''\n        handler.write('Whatever')\n        return ... \n```\n\n## Iframe embedding\nIn the frontend, it is required to embed an iframe with a jupyter notebook.\n\nExample\n```javascript\nimport PythonConsole from 'geppetto-client/js/components/interface/pythonConsole/PythonConsole';\n\n// Inside your React component render:\n\u003cPythonConsole key=\"console\" pythonNotebookPath=\"notebooks/notebook.ipynb\" /\u003e\n```\n\n## Synchronization\nThis feature allows to synchronize backend and frontend objects. In order to use synchronization, it is required to have\nthe iframe embed enabled and initialized.\nIt's implemented through a [IPython/Jupyter widget](https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Basics.html).\nOn the JS side, the connection is achieved through the PythonControlledCapability of the [Geppetto client](https://github.com/openworm/geppetto-client/).\n\n \nUsage\n```python\nfrom jupyter_geppetto import synchronization\nclass MyClass:\n    def a(self):\n        ...\n    def b(self):\n        ...\nsynchronization.startSynchronization(MyClass().__dict__)\n\n```\n\n## Deployment\nAn application based on Jupyter Geppetto can be deployed as a standard jupyter notebook application.\nIt is recommended a dockerized setup with JupyterHub (e.g. on Kubernetes).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenworm%2Forg.geppetto.frontend.jupyter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenworm%2Forg.geppetto.frontend.jupyter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenworm%2Forg.geppetto.frontend.jupyter/lists"}