{"id":14977427,"url":"https://github.com/hmiladhia/nbmanips","last_synced_at":"2025-10-28T03:32:16.175Z","repository":{"id":43479182,"uuid":"368320923","full_name":"hmiladhia/nbmanips","owner":"hmiladhia","description":"nbmanips allows you easily manipulate ipynb files","archived":false,"fork":false,"pushed_at":"2024-12-25T21:32:39.000Z","size":434,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T11:24:21.284Z","etag":null,"topics":["databricks-notebooks","dbc","jupyter-notebook","markdown","notebook","python","zeppelin","zeppelin-notebook","zpln"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hmiladhia.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-17T21:01:32.000Z","updated_at":"2024-12-30T22:26:03.000Z","dependencies_parsed_at":"2024-09-28T00:01:19.125Z","dependency_job_id":"5505aa00-be10-4fba-a6ee-117b002bd535","html_url":"https://github.com/hmiladhia/nbmanips","commit_stats":{"total_commits":362,"total_committers":2,"mean_commits":181.0,"dds":0.002762430939226568,"last_synced_commit":"945c15209825d9646f80e1d8cc7c51eb6edec950"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2Fnbmanips","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2Fnbmanips/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2Fnbmanips/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2Fnbmanips/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hmiladhia","download_url":"https://codeload.github.com/hmiladhia/nbmanips/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238590596,"owners_count":19497350,"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":["databricks-notebooks","dbc","jupyter-notebook","markdown","notebook","python","zeppelin","zeppelin-notebook","zpln"],"created_at":"2024-09-24T13:55:38.194Z","updated_at":"2025-10-28T03:32:10.820Z","avatar_url":"https://github.com/hmiladhia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nbmanips\n\n[![logo](https://raw.githubusercontent.com/hmiladhia/nbmanips/refs/heads/main/docs/linelogo.png)](https://pypi.org/project/nbmanips/)\n\n[![PyPI](https://img.shields.io/pypi/v/nbmanips)](https://pypi.org/project/nbmanips/)\n[![PyPI - License](https://img.shields.io/pypi/l/nbmanips)](https://pypi.org/project/nbmanips/)\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/nbmanips)](https://pypi.org/project/nbmanips/)\n\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n![Tests](https://github.com/hmiladhia/nbmanips/actions/workflows/tests.yml/badge.svg)\n[![codecov](https://codecov.io/gh/hmiladhia/nbmanips/branch/main/graph/badge.svg)](https://codecov.io/gh/hmiladhia/nbmanips)\n\nA collections of utilities to manipulate IPython/Jupyter Notebooks via a python script.\n\n## I - Usage/Examples\n### 1 - Basic usage\nA simple example of using nbmanips:\n\n```python\nfrom nbmanips import Notebook\n\n# Read ipynb file\nnb = Notebook.read_ipynb(\"my_notebook.ipynb\")\n\n# delete empty cells\nnb.select(\"empty\").delete()\n\n# save ipynb file\nnb.to_ipynb(\"new_notebook.ipynb\")\n```\n\nExamples of operations you can perform on a Notebook:\n\n- `replace`: Replace matching text in the selected cells\n- `tag`: Add metadata to the selected cells\n- `erase`: Erase the content of the selected cells\n- `delete`: Delete the selected cells\n- `keep`: Kepp the selected cells\n\n### 2 - Selectors\nTo select cells on which to apply the previous operations, you can use:\n\n- The cell number\n\n```python\nnb[0].show()\n\n# OR\nnb.select(0).show()\n```\n- A slice object\n\n```python\nnb[1:6:2].show()\n\n# OR\nselected_cells = slice(1, 6, 2)\n\nnb.select(selected_cells).show()\n```\n- A predefined selector. Available predefined selectors are the following:\n\n    - `code_cells` / `markdown_cells` / `raw_cells`: Selects cells with the given type\n    - `contains`: Selects Cells containing a certain text.\n    - `is_empty` / `empty`: Selects empty cells\n    - `has_output`: Checks if the cell has any output\n    - `has_output_type`: Select cells that have a given output_type\n    - `has_slide_type`: Select cells that have a given slide type\n    - `is_new_slide`: Selects cells where a new slide/subslide starts\n    - `has_byte_size`: Selects cells with byte size within a given range of values.\n\n```python\n# Show Markdown Cells\nnb.select('markdown_cells').show()\n\n# Show Cells containing the equal sign\nnb.select('contains', '=').show()\n```\n\n\n\n- A function that takes a Cell object and returns True if the cell should be selected\n```python\n# Show Cells with length \u003e 10\nnb.select(lambda cell: len(cell.source) \u003e 10).show()\n```\n- A list of Selectors\n```python\n# Show Empty Markdown Cells\nnb.select(['markdown_cells', 'is_empty']).show()\n\n# Show Markdown or Code Cells\nnb.select(['markdown_cells', 'code_cells'], type='or').show()\n```\n\n### 3 - Export Formats\nYou can export the notebooks to these formats:\n\n- to_ipynb\n- to_dbc\n- to_html\n- to_slides (using reveal.js)\n- to_md (to markdown)\n- to_py (to python)\n- to_text (textual representation of the notebook)\n\n### 4 - Slide manipulations\nYou can manipulate the slides by tagging which cells to keep and which to skip.\nThe following actions are available:\n\n- set_slide\n- set_subslide\n- set_skip\n- set_fragment\n- set_notes\n\nA neat trick is to use `auto_slide` method to automatically create slides out of your notebook:\n```python\nfrom nbmanips import Notebook\n\n# Read ipynb file\nnb = Notebook.read_ipynb(\"my_notebook.ipynb\")\n\n# Automatically create slides\nnb.auto_slide()\n\n# Export to Reveal.js slides (HTML)\nnb.to_slides(\"new_slides.slides.html\", theme='beige')\n```\n\n## II - CLI\n### 1 - Show a notebook\nTo get a readable representation of the notebook\n```bash\nnb show my_notebook.ipynb\n```\n\nOther options are available. For example, you can customize the style, weather to truncate the output of cells:\n```bash\nnb show -s double -t 100 my_notebook.ipynb\n```\n\nTo show a subset of the notebook cells, you can perform a select operation:\n```bash\nnb select 0:3 | nb show my_notebook.ipynb\n\n# Or if you're using negative indexes ( to show the last 3 cells )\nnb select [-3:] | nb show my_notebook.ipynb\n```\n### 2 - Basic usage\nA simple example of using nbmanips via the cli:\n\n```bash\n# delete empty cells\nnb select empty | nb delete my_notebook.ipynb --output new_notebook.ipynb\n\n# Or equivalently:\nnbmanips select empty | nbmanips delete my_notebook.ipynb --output new_notebook.ipynb\n```\n\nYou could also show the table of contents of a certain notebook:\n```bash\nnb toc nb.ipynb\n```\n\nOr split a notebook into multiple notebooks:\n\n```bash\nnb split nb.ipynb 5,9\n```\n\n### 3 - Export Formats\nYou can convert a notebook to the following formats:\n\n- html: `nb convert html my_notebook.ipynb --output my_notebook.html`\n- slides (using reveal.js): `nb convert slides my_notebook.ipynb --output my_notebook.slides.html`\n- md (to markdown): `nb convert md my_notebook.ipynb --output my_notebook.md`\n- py (to python): `nb convert py my_notebook.ipynb --output my_notebook.py`\n\n### 4 - Slide manipulations\n```bash\n# Automatically set slides\nnb auto-slide -f my_notebook.ipynb\n\n# Generate a my_notebook.slides.html file\nnb convert slides my_notebook.ipynb\n```\n\nOr if you do not wish to modify your original notebook:\n```bash\n# Automatically set slides\nnb auto-slide my_notebook.ipynb -o my_temp_notebook.ipynb\n\n# Generate a my_notebook.slides.html file\nnb convert slides my_temp_notebook.ipynb -o my_notebook.slides.html\n```\n\nIf you need more details you can check the --help option:\n```\nnbmanips --help\n```\n\n## III - Optional Requirements\n\nThere are optional requirements you may want to install to render images in the terminal.\nThe results, however, are not always convincing.\nIf you want to enable this feature, you can just run the following command:\n\n```bash\npip install nbmanips[images]\n```\n\n## Roadmap\n\n- Add Custom Templates\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmiladhia%2Fnbmanips","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhmiladhia%2Fnbmanips","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmiladhia%2Fnbmanips/lists"}