{"id":24408031,"url":"https://github.com/ayasyrev/nbmetaclean","last_synced_at":"2025-04-12T01:17:01.504Z","repository":{"id":203046655,"uuid":"708700665","full_name":"ayasyrev/nbmetaclean","owner":"ayasyrev","description":"Cl app / pre-commit hook to clean Jupyter Notebooks metadata, execution_count and optionally output.","archived":false,"fork":false,"pushed_at":"2025-03-03T08:26:00.000Z","size":767,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T01:16:51.823Z","etag":null,"topics":["notebooks","pre-commit-hook"],"latest_commit_sha":null,"homepage":"https://ayasyrev.github.io/nbmetaclean/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ayasyrev.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":"2023-10-23T08:00:42.000Z","updated_at":"2025-03-03T08:24:45.000Z","dependencies_parsed_at":"2023-10-28T11:23:58.784Z","dependency_job_id":"fb9bf8b7-10a7-4a8f-8bd2-9c06b2874111","html_url":"https://github.com/ayasyrev/nbmetaclean","commit_stats":null,"previous_names":["ayasyrev/nbmetaclean"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayasyrev%2Fnbmetaclean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayasyrev%2Fnbmetaclean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayasyrev%2Fnbmetaclean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayasyrev%2Fnbmetaclean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayasyrev","download_url":"https://codeload.github.com/ayasyrev/nbmetaclean/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501859,"owners_count":21114684,"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":["notebooks","pre-commit-hook"],"created_at":"2025-01-20T05:18:40.088Z","updated_at":"2025-04-12T01:17:01.483Z","avatar_url":"https://github.com/ayasyrev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nbmetaclean\nCollections of python scripts for checking and cleaning Jupyter Notebooks metadata, execution_count and optionally output.\nCan be used as command line tool or pre-commit hook.\n\n\nPure Python, no dependencies.\n\nCan be used as a pre-commit hook or as a command line tool.\n\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/benchmark-utils)](https://pypi.org/project/nbmetaclean/)\n[![PyPI Status](https://badge.fury.io/py/nbmetaclean.svg)](https://badge.fury.io/py/nbmetaclean)\n[![Tests](https://github.com/ayasyrev/nbmetaclean/workflows/Tests/badge.svg)](https://github.com/ayasyrev/nbmetaclean/actions?workflow=Tests)  \n[![Codecov](https://codecov.io/gh/ayasyrev/nbmetaclean/branch/main/graph/badge.svg)](https://codecov.io/gh/ayasyrev/nbmetaclean)\n\n## nbmetaclean\n\nClean Jupyter Notebooks metadata, execution_count and optionally output.\n\n## nbcheck\nCheck Jupyter Notebooks for errors and (or) warnings in outputs.\n\n\n## Base usage\n\n### Pre-commit hook\nNbmetaclean can be used as a pre-commit hook, with [pre-commit](https://pre-commit.com/pre-commit)\nYou do not need to install nbmetaclean, it will be installed automatically.\nadd to `.pre-commit-config.yaml`:\n```yaml\nrepos:\n    - repo: https://github.com/ayasyrev/nbmetaclean\n        rev: 0.1.1\n        hooks:\n        - id: nbmetaclean\n        - id: nbcheck\n          args: [ --ec, --err, --warn ]\n```\n\n\n\n### Command line tool\n\n#### Without install:\nIf you use [uv](https://github.com/astral-sh/uv) package manager, you can nbmetaclean without install.\nTo clean notebooks:\n```bash\nuvx nbmetaclean\n```\nTo check notebooks:\n```bash\nuvx --from nbmetaclean nbcheck --ec --err --warn\n```\n\n####  Install:\n```bash\npip install nbmetaclean\n```\n\nUsage:\nrun `nbmetaclean` or `nbcheck` command with `path` to notebook or folder with notebooks.\nIf no `path` is provided, current directory will be used as `path`.\n\nIt is possible to use `nbclean` command instead of `nbmetaclean`.\n`nbmetaclean` will be used by defaults in favour of usage with `uvx`\n\n\n\n```bash\nnbmetaclean\n```\n\n`nbcheck` should be run with flags:\n- `--ec` for execution_count check\n- `--err` for check errors in outputs\n- `--warn` for check warnings in outputs\n```bash\nnbcheck --ec --err --warn\n```\n\n\n## Nbmetaclean\n### Default settings\nBy default, the following settings are used:\n\n- Clean notebook metadata, except `authors` and `language_info / name`.\n- Clean cells execution_count.\n- Preserve metadata at  cells.\n- Preserve cells outputs.\n- After cleaning notebook, timestamp for file will be set to previous values.\n\n\n\n\n\n\n### Arguments\nCheck available arguments:\n\n```bash\nnbmetaclean -h\n\nusage: nbmetaclean [-h] [-s] [--not_ec] [--not-pt] [--dont_clear_nb_metadata] [--clear_cell_metadata] [--clear_outputs]\n[--nb_metadata_preserve_mask NB_METADATA_PRESERVE_MASK [NB_METADATA_PRESERVE_MASK ...]]\n[--cell_metadata_preserve_mask CELL_METADATA_PRESERVE_MASK [CELL_METADATA_PRESERVE_MASK ...]] [--dont_merge_masks] [--clean_hidden_nbs] [-D] [-V]\n[path ...]\n\nClean metadata and execution_count from Jupyter notebooks.\n\npositional arguments:\n  path                  Path for nb or folder with notebooks.\n\noptions:\n  -h, --help            show this help message and exit\n  -s, --silent          Silent mode.\n  --not_ec              Do not clear execution_count.\n  --not-pt              Do not preserve timestamp.\n  --dont_clear_nb_metadata\n                        Do not clear notebook metadata.\n  --clear_cell_metadata\n                        Clear cell metadata.\n  --clear_outputs       Clear outputs.\n  --nb_metadata_preserve_mask NB_METADATA_PRESERVE_MASK [NB_METADATA_PRESERVE_MASK ...]\n                        Preserve mask for notebook metadata.\n  --cell_metadata_preserve_mask CELL_METADATA_PRESERVE_MASK [CELL_METADATA_PRESERVE_MASK ...]\n                        Preserve mask for cell metadata.\n  --dont_merge_masks    Do not merge masks.\n  --clean_hidden_nbs    Clean hidden notebooks.\n  -D, --dry_run         perform a trial run, don't write results\n  -V, --verbose         Verbose mode. Print extra information.\n```\n\n### Execution_count\nIf you want to leave execution_count add `--not_ec` flag at command line or `args: [--not_ec]` line to `.pre-commit-config.yaml`.\n\n```yaml\nrepos:\n    - repo: https://github.com/ayasyrev/nbmetaclean\n        rev: 0.1.1\n        hooks:\n        - id: nbmetaclean\n          args: [ --not_ec ]\n```\n\n```bash\nnbmetaclean --not_ec\n```\n\n### Clear outputs\nIf you want to clear outputs, add `--clear_outputs` at command line or `[ --clean_outputs ]` line to `.pre-commit-config.yaml`.\n```yaml\nrepos:\n    - repo: https://github.com/ayasyrev/nbmetaclean\n        rev: 0.1.1\n        hooks:\n        - id: nbmetaclean\n          args: [ --clean_outputs ]\n```\n\n```bash\nnbmetaclean --clean_outputs\n```\n\n## Nbcheck\nCheck Jupyter Notebooks for correct execution_count, errors and (or) warnings in outputs.\n\n### Execution_count\nCheck that all code cells executed one after another.\n\n#### Strict mode\nBy default, execution_count check in `strict` mode.\nAll cells must be executed, one after another.\n\npre-commit config example:\n```yaml\nrepos:\n    - repo: https://github.com/ayasyrev/nbmetaclean\n        rev: 0.1.1\n        hooks:\n        - id: nbcheck\n          args: [ --ec ]\n```\n\ncommand line example:\n```bash\nnbcheck --ec\n```\n\n#### Not strict mode\n`--not_strict` flag can be used to check that next cell executed after previous one, but execution number can be more than `+1`.\n\npre-commit config example:\n```yaml\nrepos:\n    - repo: https://github.com/ayasyrev/nbmetaclean\n        rev: 0.1.1\n        hooks:\n        - id: nbcheck\n          args: [ --ec, --not_strict ]\n```\n\ncommand line example:\n```bash\nnbcheck --ec --not_strict\n```\n\n#### Allow notebooks with no execution_count\n\n`--no_exec` flag allows notebooks with all cells without execution_count.\nIf notebook has cells with execution_count and without execution_count, pre-commit will return error.\n\npre-commit config example:\n```yaml\nrepos:\n    - repo: https://github.com/ayasyrev/nbmetaclean\n        rev: 0.1.1\n        - id: nbcheck\n          args: [ --ec, --no_exec ]\n```\n\ncommand line example:\n```bash\nnbcheck --ec --no_exec\n```\n\n\n\n### Errors and Warnings\n\n`--err` and `--warn` flags can be used to check for errors and warnings in outputs.\n\npre-commit config example:\n```yaml\nrepos:\n    - repo: https://github.com/ayasyrev/nbmetaclean\n        rev: 0.1.1\n        hooks:\n        - id: nbcheck\n          args: [ --err, --warn ]\n```\n\ncommand line example:\n```bash\nnbcheck --err --warn\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayasyrev%2Fnbmetaclean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayasyrev%2Fnbmetaclean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayasyrev%2Fnbmetaclean/lists"}