Package: nbtopy
NBTOPY - Converts Jupyter notebook files to Python filesnbtopyis a Linux command line
utility to convert one or moreJupyternotebook
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 superbPython
Interactivemode inVisual Studio Code, 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 CodePython
Interactivewindow. Just runnbtopy .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'snbconverttool to do the
conversion and that runsmuchslower thannbtopy.This program uses only pure Python and does not require anyJupyteror 3rd party software or utilities to be
installed.ExamplesConvert singlemyfile.ipynbfile to newmyfile.py:$ nbtopy myfile.ipynbConvert all*.ipynbfiles in current directory to*.py:$ nbtopy . (effectively same as nbtopy *.ipynb)Write all*.pyfiles to directorypyfiles/instead of current dir:$ nbtopy -d pyfiles .Recurse through all child directories and write*.pyfiles to
directorypyfiles/in same directories as source**/*.ipynbfiles.$ nbtopy -r -d pyfiles .Recurse through all child directories and write*.pyfiles to new
and independent tree rooted underpyfiles/. Specify this by using
an absolute (rather than relative) path for-d/--dir.$ nbtopy -r -d $PWD/pyfiles .Installation or UpgradeArch users can installnbtopy from the
AUR.Python 3.6 or later is required. Notenbtopy is on
PyPIso just ensure thatpipxis installed then type the
following:$ pipx install nbtopyTo upgrade:$ pipx upgrade nbtopyThis program runs on pure Python. No 3rd party packages are required.
Note that this program does not require Jupyter'snbconverttool.Command Line OptionsTypenbtopy -hto 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 OptionsYou 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 yournbtopycommand line options. Typenbtopy -hto see the options
supported.E.g. in your~/.config/nbtopy-flags.confyou could have the line--no-markdown-tagso that markdown cells are always merely aded as
comments, without an explicit markdown tag.LicenseCopyright (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 athttp://www.gnu.org/licenses/for more details.