{"id":20971092,"url":"https://github.com/datalayer/jupyter-server-nbmodel","last_synced_at":"2025-05-14T11:33:44.614Z","repository":{"id":238699097,"uuid":"796558951","full_name":"datalayer/jupyter-server-nbmodel","owner":"datalayer","description":"Jupyter Server NbModel - Server-side Jupyter Notebooks.","archived":false,"fork":false,"pushed_at":"2025-05-01T11:19:50.000Z","size":623,"stargazers_count":24,"open_issues_count":11,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-02T23:38:05.182Z","etag":null,"topics":["jupyter","nbmodel","rtc","server"],"latest_commit_sha":null,"homepage":"https://datalayer.tech","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datalayer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["datalayer"]}},"created_at":"2024-05-06T07:24:15.000Z","updated_at":"2025-04-01T15:44:01.000Z","dependencies_parsed_at":"2024-05-30T16:53:59.892Z","dependency_job_id":"b9a47c87-53c5-4bae-b1c9-1b23de2cdd49","html_url":"https://github.com/datalayer/jupyter-server-nbmodel","commit_stats":null,"previous_names":["datalayer/jupyter-server-nbmodel"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalayer%2Fjupyter-server-nbmodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalayer%2Fjupyter-server-nbmodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalayer%2Fjupyter-server-nbmodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datalayer%2Fjupyter-server-nbmodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datalayer","download_url":"https://codeload.github.com/datalayer/jupyter-server-nbmodel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254131888,"owners_count":22020035,"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":["jupyter","nbmodel","rtc","server"],"created_at":"2024-11-19T04:00:50.505Z","updated_at":"2025-05-14T11:33:44.601Z","avatar_url":"https://github.com/datalayer.png","language":"Python","funding_links":["https://github.com/sponsors/datalayer"],"categories":[],"sub_categories":[],"readme":"# jupyter_server_nbmodel\n\n[![Github Actions Status](https://github.com/datalayer/jupyter-server-nbmodel/workflows/Build/badge.svg)](https://github.com/datalayer/jupyter-server-nbmodel/actions/workflows/build.yml)\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/datalayer/jupyter-server-nbmodel/main?urlpath=lab)\n\nA Jupyter Server extension to execute code cell from the server.\n\nThis extension is composed of a Python package named `jupyter_server_nbmodel`\nfor the server extension and a NPM package named `jupyter-server-nbmodel`\nfor the frontend extension.\n\n## Requirements\n\n- Jupyter Server\n- \\[recommended\\] Real-time collaboration for JupyterLab/Notebook:\n  This will push the kernels results in the notebook from the server.\n\n## Install\n\nTo install the extension for use in JupyterLab or Notebook 7, execute:\n\n```bash\npip install jupyter_server_nbmodel[lab]\n```\n\nFor API-only use:\n\n```bash\npip install jupyter_server_nbmodel\n```\n\n## Uninstall\n\nTo remove the extension, execute:\n\n```bash\npip uninstall jupyter_server_nbmodel\n```\n\n## Troubleshoot\n\nIf you are seeing the frontend extension, but it is not working, check\nthat the server extension is enabled:\n\n```bash\njupyter server extension list\n```\n\nIf the server extension is installed and enabled, but you are not seeing\nthe frontend extension, check the frontend extension is installed:\n\n```bash\njupyter labextension list\n```\n\n## How does it works\n\n### Generic case\n\nExecution of a Python code snippet: `print(\"hello\")`\n\n```mermaid\nsequenceDiagram\n    Frontend-\u003e\u003e+Server: POST /api/kernels/\u003cid\u003e/execute\n    Server-\u003e\u003e+ExecutionStack: Queue request\n    ExecutionStack-\u003e\u003eKernel: Execute request msg\n    activate Kernel\n    ExecutionStack--\u003e\u003eServer: Task uid\n    Server--\u003e\u003e-Frontend: Returns task uid\n    loop Running\n        Kernel-\u003e\u003eShared Document: Add output\n        Shared Document-\u003e\u003eFrontend: Document update\n    end\n    loop While status is 202\n        Frontend-\u003e\u003e+Server: GET /api/kernels/\u003cid\u003e/requests/\u003cuid\u003e\n        Server-\u003e\u003eExecutionStack: Get task result\n        ExecutionStack--\u003e\u003eServer: null\n        Server--\u003e\u003e-Frontend: Request status 202\n    end\n    Kernel--\u003e\u003eExecutionStack: Execution reply\n    deactivate Kernel\n    Frontend-\u003e\u003e+Server: GET /api/kernels/\u003cid\u003e/requests/\u003cuid\u003e\n    Server-\u003e\u003eExecutionStack: Get task result\n    ExecutionStack--\u003e\u003eServer: Result\n    Server--\u003e\u003e-Frontend: Status 200 \u0026 result\n```\n\n### With input case\n\nExecution of a Python code snippet: `input(\"Age:\")`\n\n```mermaid\nsequenceDiagram\n    Frontend-\u003e\u003e+Server: POST /api/kernels/\u003cid\u003e/execute\n    Server-\u003e\u003e+ExecutionStack: Queue request\n    ExecutionStack-\u003e\u003eKernel: Execute request msg\n    activate Kernel\n    ExecutionStack--\u003e\u003eServer: Task uid\n    Server--\u003e\u003e-Frontend: Returns task uid\n    loop Running\n        Kernel-\u003e\u003eShared Document: Add output\n        Shared Document-\u003e\u003eFrontend: Document update\n    end\n    loop While status is 202\n        Frontend-\u003e\u003e+Server: GET /api/kernels/\u003cid\u003e/requests/\u003cuid\u003e\n        Server-\u003e\u003eExecutionStack: Get task result\n        ExecutionStack--\u003e\u003eServer: null\n        Server--\u003e\u003e-Frontend: Request status 202\n    end\n    Kernel-\u003e\u003eExecutionStack: Set pending input\n    Frontend-\u003e\u003e+Server: GET /api/kernels/\u003cid\u003e/requests/\u003cuid\u003e\n    Server-\u003e\u003eExecutionStack: Get task result\n    ExecutionStack--\u003e\u003eServer: Pending input\n    Server--\u003e\u003e-Frontend: Status 300 \u0026 Pending input\n    Frontend-\u003e\u003e+Server: POST /api/kernels/\u003cid\u003e/input\n    Server-\u003e\u003eKernel: Send input msg\n    Server--\u003e\u003e-Frontend: Returns\n    loop While status is 202\n        Frontend-\u003e\u003e+Server: GET /api/kernels/\u003cid\u003e/requests/\u003cuid\u003e\n        Server-\u003e\u003eExecutionStack: Get task result\n        ExecutionStack--\u003e\u003eServer: null\n        Server--\u003e\u003e-Frontend: Request status 202\n    end\n    Kernel--\u003e\u003eExecutionStack: Execution reply\n    deactivate Kernel\n    Frontend-\u003e\u003e+Server: GET /api/kernels/\u003cid\u003e/requests/\u003cuid\u003e\n    Server-\u003e\u003eExecutionStack: Get task result\n    ExecutionStack--\u003e\u003eServer: Result\n    Server--\u003e\u003e-Frontend: Status 200 \u0026 result\n```\n\n\u003e \\[!NOTE\\]\n\u003e The code snippet is always send in the body of the POST `/api/kernels/\u003cid\u003e/execute`\n\u003e request to avoid document model discrepancy; the document on the backend is only\n\u003e eventually identical with the frontends (document updates are not instantaneous).\n\u003e\n\u003e The `ExecutionStack` maintains an execution queue per kernels to ensure execution\n\u003e order.\n\n## Contributing\n\n### Development install\n\nNote: You will need NodeJS to build the extension package.\n\nThe `jlpm` command is JupyterLab's pinned version of\n[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use\n`yarn` or `npm` in lieu of `jlpm` below.\n\n```bash\n# Clone the repo to your local environment\n# Change directory to the jupyter_server_nbmodel directory\n# Install package in development mode\npip install -e \".[test]\"\n# Link your development version of the extension with JupyterLab\njupyter labextension develop . --overwrite\n# Server extension must be manually installed in develop mode\njupyter server extension enable jupyter_server_nbmodel\n# Rebuild extension Typescript source after making changes\njlpm build\n```\n\nYou can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.\n\n```bash\n# Watch the source directory in one terminal, automatically rebuilding when needed\njlpm watch\n# Run JupyterLab in another terminal\njupyter lab --autoreload\n```\n\nWith the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).\n\nBy default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:\n\n```bash\njupyter lab build --minimize=False\n```\n\n### Development uninstall\n\n```bash\n# Server extension must be manually disabled in develop mode\njupyter server extension disable jupyter_server_nbmodel\npip uninstall jupyter_server_nbmodel\n```\n\nIn development mode, you will also need to remove the symlink created by `jupyter labextension develop`\ncommand. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`\nfolder is located. Then you can remove the symlink named `jupyter-server-nbmodel` within that folder.\n\n### Testing the extension\n\n#### Server tests\n\nThis extension is using [Pytest](https://docs.pytest.org/) for Python code testing.\n\nInstall test dependencies (needed only once):\n\n```sh\npip install -e \".[test]\"\n# Each time you install the Python package, you need to restore the front-end extension link\njupyter labextension develop . --overwrite\n```\n\nTo execute them, run:\n\n```sh\npytest -vv -r ap --cov jupyter_server_nbmodel\n```\n\n#### Frontend tests\n\nThis extension is using [Jest](https://jestjs.io/) for JavaScript code testing.\n\nTo execute them, execute:\n\n```sh\njlpm\njlpm test\n```\n\n#### Integration tests\n\nThis extension uses [Playwright](https://playwright.dev/docs/intro) for the integration tests (aka user level tests).\nMore precisely, the JupyterLab helper [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) is used to handle testing the extension in JupyterLab.\n\nMore information are provided within the [ui-tests](./ui-tests/README.md) README.\n\n### Manual testing\n\n```bash\n# Terminal 1.\njupyter server --port 8888 --autoreload --ServerApp.disable_check_xsrf=True --IdentityProvider.token= --ServerApp.port_retries=0\n\n# Terminal 2.\nKERNEL=$(curl -X POST http://localhost:8888/api/kernels)\necho $KERNEL\nKERNEL_ID=$(echo $KERNEL | jq --raw-output '.id')\necho $KERNEL_ID\nREQUEST=$(curl --include http://localhost:8888/api/kernels/$KERNEL_ID/execute -d \"{ \\\"code\\\": \\\"print('1+1')\\\" }\")\nRESULT=$(echo $REQUEST | grep -i ^Location: | cut -d' ' -f2 | tr -d '\\r')\necho $RESULT\n\ncurl http://localhost:8888$RESULT\n{\"status\": \"ok\", \"execution_count\": 1, \"outputs\": \"[{\\\"output_type\\\": \\\"stream\\\", \\\"name\\\": \\\"stdout\\\", \\\"text\\\": \\\"1+1\\\\n\\\"}]\"}\n```\n\n### Running Tests\n\nInstall dependencies:\n\n```bash\npip install -e \".[test]\"\n```\n\nTo run the python tests, use:\n\n```bash\npytest\n\n# To test a specific file\npytest jupyter_server_nbmodel/tests/test_handlers.py\n\n# To run a specific test\npytest jupyter_server_nbmodel/tests/test_handlers.py -k \"test_post_execute\"\n```\n\n### Development uninstall\n\n```bash\npip uninstall jupyter_server_nbmodel\n```\n\n### Packaging the extension\n\nSee [RELEASE](RELEASE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatalayer%2Fjupyter-server-nbmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatalayer%2Fjupyter-server-nbmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatalayer%2Fjupyter-server-nbmodel/lists"}