nbtopy


Namenbtopy JSON
Version 1.1 PyPI version JSON
download
home_page
SummaryConverts Jupyter notebook files to Python (interactive) files
upload_time2023-06-19 22:32:35
maintainer
docs_urlNone
author
requires_python>=3.6
licenseGPLv3
keywords jupyter notebook nbconvert vscode
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## NBTOPY - Converts Jupyter notebook files to Python files
[![PyPi](https://img.shields.io/pypi/v/nbtopy)](https://pypi.org/project/nbtopy/)
[![AUR](https://img.shields.io/aur/version/nbtopy)](https://aur.archlinux.org/packages/nbtopy/)

[nbtopy](http://github.com/bulletmark/nbtopy) is a Linux command line
utility to convert one or more [Jupyter](https://jupyter.org/) notebook
files (`.ipynb`) to Python files (`.py`). My primary purpose for
creating this utility is to quickly and easily create Python files to
use with the superb [Python
Interactive](https://code.visualstudio.com/docs/python/jupyter-support-py)
mode in [Visual Studio Code](https://code.visualstudio.com/), which I
often prefer to use instead of the Jupyter notebook. In the generated
code, Python code blocks are delimited by `# %%` tags and markdown
blocks are delimited by `# %% [markdown]` tags.

A typical use case is when you download a directory of Jupyter notebook
files and want run them using a VS Code [Python
Interactive](https://code.visualstudio.com/docs/python/jupyter-support-py)
window. Just run `nbtopy .` in the directory and all the Python files
are created and ready to use. You could use VS Code's inbuilt command to
create a Python file from the notebook but that is slow and awkward
because you have to run it explicitly for each notebook, and then
manually rename each created file. Also, VS Code uses Jupyter's
[`nbconvert`](https://nbconvert.readthedocs.io/) tool to do the
conversion and that runs *much* slower than `nbtopy`.

This program uses only pure Python and does not require any
[Jupyter](https://jupyter.org/) or 3rd party software or utilities to be
installed.

### Examples

1. Convert single `myfile.ipynb` file to new `myfile.py`:

    ```
    $ nbtopy myfile.ipynb
    ```

2. Convert all `*.ipynb` files in current directory to `*.py`:

    ```
    $ nbtopy . (effectively same as nbtopy *.ipynb)
    ```

3. Write all `*.py` files to directory `pyfiles/` instead of current dir:

    ```
    $ nbtopy -d pyfiles .
    ```

4. Recurse through all child directories and write `*.py` files to
   directory `pyfiles/` in same directories as source `**/*.ipynb`
   files.

    ```
    $ nbtopy -r -d pyfiles .
    ```

5. Recurse through all child directories and write `*.py` files to new
   and independent tree rooted under `pyfiles/`. Specify this by using
   an absolute (rather than relative) path for `-d/--dir`.

    ```
    $ nbtopy -r -d $PWD/pyfiles .
    ```

## Installation or Upgrade

Arch users can install [nbtopy from the
AUR](https://aur.archlinux.org/packages/nbtopy/).

Python 3.6 or later is required. Note [nbtopy is on
PyPI](https://pypi.org/project/nbtopy/) so just ensure that
[`pipx`](https://pypa.github.io/pipx/) is installed then type the
following:

```
$ pipx install nbtopy
```

To upgrade:

```
$ pipx upgrade nbtopy
```

This program runs on pure Python. No 3rd party packages are required.
Note that this program does not require Jupyter's
[nbconvert](https://nbconvert.readthedocs.io/) tool.

## Command Line Options

Type `nbtopy -h` to view the usage summary:

```
usage: nbtopy [-h] [-m] [-M] [-c] [-e] [-x] [-f] [-r] [-p] [-q] [-w]
                 [-o OUT] [-d DIR] [-V]
                 [ipynb_path ...]

Converts Jupyter notebook file[s] to Python (interactive) file[s].

positional arguments:
  ipynb_path            input ipynb file[s] (or dir for all *.ipynb files)

options:
  -h, --help            show this help message and exit
  -m, --no-markdown-tag
                        do not add markdown tag on markdown cells
  -M, --no-markdown     do not output markdown cells at all
  -c, --no-code-tag     do not add code tag on code cells
  -e, --include-empty   include empty/blank cells in output
  -x, --exclude-no-code
                        skip file if it contains no Python code cells
  -f, --force           force overwrite existing file[s]
  -r, --recurse         recursively process files in all sub-directories
  -p, --purge           just purge associated output file[s]
  -q, --quiet           suppress messages about processed file[s]
  -w, --no-warnings     suppress warning messages about processed file[s]
  -o OUT, --out OUT     alternative output file name, or '-' for stdout
  -d DIR, --dir DIR     output directory, default = ".". Specify absolute path
                        to create separate tree of output files
  -V, --version         show nbtopy version

Note you can set default options in ~/.config/nbtopy-flags.conf.
```

## Default Options

You can add default options to a personal configuration file
`~/.config/nbtopy-flags.conf`. If that file exists then each line of
options will be concatenated and automatically prepended to your
`nbtopy` command line options. Type `nbtopy -h` to see the options
supported.

E.g. in your `~/.config/nbtopy-flags.conf` you could have the line
`--no-markdown-tag` so that markdown cells are always merely aded as
comments, without an explicit markdown tag.

## License

Copyright (C) 2022 Mark Blakeney. This program is distributed under the
terms of the GNU General Public License. This program is free software:
you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation,
either version 3 of the License, or any later version. This program is
distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at
<http://www.gnu.org/licenses/> for more details.

<!-- vim: se ai syn=markdown: -->

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "nbtopy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "jupyter,notebook,nbconvert,vscode",
    "author": "",
    "author_email": "Mark Blakeney <mark.blakeney@bullet-systems.net>",
    "download_url": "https://files.pythonhosted.org/packages/05/98/b391b9a9da9643b51e2c71304a9c9f7c0afbe50b55caa21c55eeefe341f7/nbtopy-1.1.tar.gz",
    "platform": null,
    "description": "## NBTOPY - Converts Jupyter notebook files to Python files\n[![PyPi](https://img.shields.io/pypi/v/nbtopy)](https://pypi.org/project/nbtopy/)\n[![AUR](https://img.shields.io/aur/version/nbtopy)](https://aur.archlinux.org/packages/nbtopy/)\n\n[nbtopy](http://github.com/bulletmark/nbtopy) is a Linux command line\nutility to convert one or more [Jupyter](https://jupyter.org/) notebook\nfiles (`.ipynb`) to Python files (`.py`). My primary purpose for\ncreating this utility is to quickly and easily create Python files to\nuse with the superb [Python\nInteractive](https://code.visualstudio.com/docs/python/jupyter-support-py)\nmode in [Visual Studio Code](https://code.visualstudio.com/), which I\noften prefer to use instead of the Jupyter notebook. In the generated\ncode, Python code blocks are delimited by `# %%` tags and markdown\nblocks are delimited by `# %% [markdown]` tags.\n\nA typical use case is when you download a directory of Jupyter notebook\nfiles and want run them using a VS Code [Python\nInteractive](https://code.visualstudio.com/docs/python/jupyter-support-py)\nwindow. Just run `nbtopy .` in the directory and all the Python files\nare created and ready to use. You could use VS Code's inbuilt command to\ncreate a Python file from the notebook but that is slow and awkward\nbecause you have to run it explicitly for each notebook, and then\nmanually rename each created file. Also, VS Code uses Jupyter's\n[`nbconvert`](https://nbconvert.readthedocs.io/) tool to do the\nconversion and that runs *much* slower than `nbtopy`.\n\nThis program uses only pure Python and does not require any\n[Jupyter](https://jupyter.org/) or 3rd party software or utilities to be\ninstalled.\n\n### Examples\n\n1. Convert single `myfile.ipynb` file to new `myfile.py`:\n\n    ```\n    $ nbtopy myfile.ipynb\n    ```\n\n2. Convert all `*.ipynb` files in current directory to `*.py`:\n\n    ```\n    $ nbtopy . (effectively same as nbtopy *.ipynb)\n    ```\n\n3. Write all `*.py` files to directory `pyfiles/` instead of current dir:\n\n    ```\n    $ nbtopy -d pyfiles .\n    ```\n\n4. Recurse through all child directories and write `*.py` files to\n   directory `pyfiles/` in same directories as source `**/*.ipynb`\n   files.\n\n    ```\n    $ nbtopy -r -d pyfiles .\n    ```\n\n5. Recurse through all child directories and write `*.py` files to new\n   and independent tree rooted under `pyfiles/`. Specify this by using\n   an absolute (rather than relative) path for `-d/--dir`.\n\n    ```\n    $ nbtopy -r -d $PWD/pyfiles .\n    ```\n\n## Installation or Upgrade\n\nArch users can install [nbtopy from the\nAUR](https://aur.archlinux.org/packages/nbtopy/).\n\nPython 3.6 or later is required. Note [nbtopy is on\nPyPI](https://pypi.org/project/nbtopy/) so just ensure that\n[`pipx`](https://pypa.github.io/pipx/) is installed then type the\nfollowing:\n\n```\n$ pipx install nbtopy\n```\n\nTo upgrade:\n\n```\n$ pipx upgrade nbtopy\n```\n\nThis program runs on pure Python. No 3rd party packages are required.\nNote that this program does not require Jupyter's\n[nbconvert](https://nbconvert.readthedocs.io/) tool.\n\n## Command Line Options\n\nType `nbtopy -h` to view the usage summary:\n\n```\nusage: nbtopy [-h] [-m] [-M] [-c] [-e] [-x] [-f] [-r] [-p] [-q] [-w]\n                 [-o OUT] [-d DIR] [-V]\n                 [ipynb_path ...]\n\nConverts Jupyter notebook file[s] to Python (interactive) file[s].\n\npositional arguments:\n  ipynb_path            input ipynb file[s] (or dir for all *.ipynb files)\n\noptions:\n  -h, --help            show this help message and exit\n  -m, --no-markdown-tag\n                        do not add markdown tag on markdown cells\n  -M, --no-markdown     do not output markdown cells at all\n  -c, --no-code-tag     do not add code tag on code cells\n  -e, --include-empty   include empty/blank cells in output\n  -x, --exclude-no-code\n                        skip file if it contains no Python code cells\n  -f, --force           force overwrite existing file[s]\n  -r, --recurse         recursively process files in all sub-directories\n  -p, --purge           just purge associated output file[s]\n  -q, --quiet           suppress messages about processed file[s]\n  -w, --no-warnings     suppress warning messages about processed file[s]\n  -o OUT, --out OUT     alternative output file name, or '-' for stdout\n  -d DIR, --dir DIR     output directory, default = \".\". Specify absolute path\n                        to create separate tree of output files\n  -V, --version         show nbtopy version\n\nNote you can set default options in ~/.config/nbtopy-flags.conf.\n```\n\n## Default Options\n\nYou can add default options to a personal configuration file\n`~/.config/nbtopy-flags.conf`. If that file exists then each line of\noptions will be concatenated and automatically prepended to your\n`nbtopy` command line options. Type `nbtopy -h` to see the options\nsupported.\n\nE.g. in your `~/.config/nbtopy-flags.conf` you could have the line\n`--no-markdown-tag` so that markdown cells are always merely aded as\ncomments, without an explicit markdown tag.\n\n## License\n\nCopyright (C) 2022 Mark Blakeney. This program is distributed under the\nterms of the GNU General Public License. This program is free software:\nyou can redistribute it and/or modify it under the terms of the GNU\nGeneral Public License as published by the Free Software Foundation,\neither version 3 of the License, or any later version. This program is\ndistributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or\nFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at\n<http://www.gnu.org/licenses/> for more details.\n\n<!-- vim: se ai syn=markdown: -->\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Converts Jupyter notebook files to Python (interactive) files",
    "version": "1.1",
    "project_urls": {
        "Homepage": "https://github.com/bulletmark/nbtopy"
    },
    "split_keywords": [
        "jupyter",
        "notebook",
        "nbconvert",
        "vscode"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0da5605f98f8c6b7b7d9c7212d16d238df2a39cd104f311025f7be03986a5a21",
                "md5": "fab7340b0ac4e9f4d2fbb435395a0fa3",
                "sha256": "72c2a022c7ed66f5c65c8ebff38504b7d9cb824aae587387db77a19291114eab"
            },
            "downloads": -1,
            "filename": "nbtopy-1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fab7340b0ac4e9f4d2fbb435395a0fa3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6466,
            "upload_time": "2023-06-19T22:32:34",
            "upload_time_iso_8601": "2023-06-19T22:32:34.047556Z",
            "url": "https://files.pythonhosted.org/packages/0d/a5/605f98f8c6b7b7d9c7212d16d238df2a39cd104f311025f7be03986a5a21/nbtopy-1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0598b391b9a9da9643b51e2c71304a9c9f7c0afbe50b55caa21c55eeefe341f7",
                "md5": "76da833720d955e244f38ce7270dfc77",
                "sha256": "be56ee0e7c64e99d4c9b97e250ca25f76645fe33937230167990b03e0b1ce163"
            },
            "downloads": -1,
            "filename": "nbtopy-1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "76da833720d955e244f38ce7270dfc77",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6720,
            "upload_time": "2023-06-19T22:32:35",
            "upload_time_iso_8601": "2023-06-19T22:32:35.779795Z",
            "url": "https://files.pythonhosted.org/packages/05/98/b391b9a9da9643b51e2c71304a9c9f7c0afbe50b55caa21c55eeefe341f7/nbtopy-1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-19 22:32:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bulletmark",
    "github_project": "nbtopy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nbtopy"
}
        
Elapsed time: 0.07747s