nbcommands bring the goodness of Unix commands to Jupyter notebooks.

Related tags

CLI Tools nbcommands
Overview

nbcommands

image image image image

nbcommands bring the goodness of Unix commands to Jupyter notebooks.

Installation

You can simply use pip to install nbcommands:

$ pip install nbcommands

or conda:

$ conda install -c conda-forge nbcommands

Usage

nbcommands installs the following commands which let you interact with your Jupyter notebooks without spinning up a notebook server.

  • nbtouch: Update the access and modification times of each Jupyter notebook to the current time.

      $ nbtouch notebook1.ipynb notebook2.ipynb

    nbtouch

  • nbgrep: Search for a pattern in Jupyter notebooks.

      $ nbgrep "os" notebook1.ipynb notebook2.ipynb
      $ nbgrep "os" directory/

    nbgrep

  • nbhead: Print the first 5 cells of a Jupyter notebook to standard output.

      $ nbhead notebook1.ipynb

    nbhead

    Note: You can also specify the number of cells you want to print using the -n option.

      $ nbhead -n 10 notebook1.ipynb
  • nbtail: Print the last 5 cells of a Jupyter notebook to standard output.

      $ nbtail notebook2.ipynb

    nbtail

    Note: You can also specify the number of cells you want to print using the -n option.

      $ nbtail -n 10 notebook2.ipynb
  • nbcat: Concatenate Jupyter notebooks to standard output.

      $ nbcat notebook1.ipynb notebook2.ipynb

    nbcat

    Note: You can create a new notebook by concatenating multiple notebooks using the -o option.

      $ nbcat notebook1.ipynb notebook2.ipynb -o notebook3.ipynb
  • nbless: Print a Jupyter notebook using a pager program.

      $ nbless notebook1.ipynb

    nbless

And some non-Unix goodness,

  • nbblack: Blacken Jupyter notebooks.

      $ nbblack notebook1.ipynb notebook2.ipynb

    nbblack


Planned enhancements:

  • nbstrip: Strip outputs from Jupyter notebooks.
  • nbdiff: Find the diff between two Jupyter notebooks.
  • nbecho: Add a code cell to a Jupyter notebook.
  • nbedit: Interactively edit a Jupyter notebook.
  • nbtime: Run and time a Jupyter notebook.
  • nbwc: Print word count for a Jupyter notebook.

Versioning

nbcommands uses Semantic Versioning. For the available versions, see the tags on this repository.

License

This project is licensed under the Apache License, see the LICENSE file for details.

Comments
  • Error with nbcat

    Error with nbcat

    Hi, I just installed and got this error trying nbcat:

    Traceback (most recent call last): File "/Users/cherny/miniconda3/envs/pandasnlp/bin/nbcat", line 8, in <module> sys.exit(cat()) File "/Users/cherny/miniconda3/envs/pandasnlp/lib/python3.7/site-packages/click/core.py", line 764, in __call__ return self.main(*args, **kwargs) File "/Users/cherny/miniconda3/envs/pandasnlp/lib/python3.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/Users/cherny/miniconda3/envs/pandasnlp/lib/python3.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/cherny/miniconda3/envs/pandasnlp/lib/python3.7/site-packages/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/Users/cherny/miniconda3/envs/pandasnlp/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/Users/cherny/miniconda3/envs/pandasnlp/lib/python3.7/site-packages/nbcommands/_cat.py", line 42, in cat click.echo("\n".join(display(merged.cells))) File "/Users/cherny/miniconda3/envs/pandasnlp/lib/python3.7/site-packages/nbcommands/terminal.py", line 15, in display cell["execution_count"] if cell["execution_count"] is not None else " " KeyError: 'execution_count'

    Any ideas? Python 3.7, nbcommands-0.3.2

    opened by arnicas 5
  • Distribution via conda-forge

    Distribution via conda-forge

    @vinayak-mehta I'm also wondering whether you'd like to consider distributing the package through conda-forge?

    If you are interested in doing so, but don't have the bandwidth to begin, I'm happy to kickstart the process for you. Maintenance post-deployment to conda-forge is very easy, as you just have to take care of the PyPI version, and a bot will do what's needed to update on conda-forge and ping you (and me, I'm happy to look out for the conda-forge package updates too).

    Please let me know!

    enhancement 
    opened by ericmjl 3
  • support directories in nbgrep

    support directories in nbgrep

    • when a directory is given, grep all notebooks in the directory
    • set type to Path to get errors from click when paths don't exist
    • set required=True for "missing argument" error when no path is specified, instead of doing nothing
    opened by minrk 2
  • [MRG] Note what nbtouch does for nonexistent files

    [MRG] Note what nbtouch does for nonexistent files

    Looking at the docs, I was confused why nbtouch would exist when touch works exactly the same for existing notebook files, but on looking at the code I saw that it creates empty notebook files, which is useful! This behavior wasn't documented as far as I could tell, so I added a mention of it to the nbtouch docstring and summary in the docs.

    opened by minrk 2
  • nbblack does not ignore jupyter magic cell lines

    nbblack does not ignore jupyter magic cell lines

    @vinayak-mehta, first off, I want to say a big huge THANK YOU for this package! :tada: It'll be very helpful for me in interacting with my notebooks at the command line.

    One thing I was very eager to try out was nbblack, because it has the ability to format every code cell in my notebook. The only problem that I encountered, though, was the code cell lines that have Jupyter magic inside of them. For example, if a code cell reads as:

    %load_ext autoreload
    %autoreload2
    

    then nbblack will raise the following error:

    black.InvalidInput: Cannot parse 10:0: %load_ext autoreload
    

    I was wondering if it might be possible to skip code magic when extracting code from each cell? A simple search to skip lines that contain % signs at the beginning might be the way to do it, I think, but having not dug further into the code base, I would defer to your knowledge on this.

    bug 
    opened by ericmjl 2
  • Fix bug when execution_count = 0

    Fix bug when execution_count = 0

    When execution_count does not exist, the commands nbcat, nbtail or nbhead throw an error. So far this has fixed it for me and now those commands work again.

    Related issue: #19

    opened by polyrand 1
  • Use ansimarkup instead of colorama for color support.

    Use ansimarkup instead of colorama for color support.

    Use the parse function from the ansimarkup package to render colored output instead of concatenating escape sequences from the colorama package.

    En passant, also used the MarkdownLexer to highlight markdown cells.

    opened by P403n1x87 2
  • Cannot parse ?? when specified at the end of function name

    Cannot parse ?? when specified at the end of function name

    @vinayak-mehta thanks for handling #9 so quickly! I just upgraded nbcommands, and I think I might have found one more edge case, I hope you don't mind me reporting this here.

    There are some code cells where we want to show the source of the function, so we write:

    func_name??
    

    to show the full source, or

    func_name?
    

    to show just the signature + docstring (if I remember correctly).

    This example, I think, also gave me an error, this time being:

    black.InvalidInput: Cannot parse: 1:6: func_name??
    

    I dug into the source, and saw that you basically added a regex replacement, is that right? Would the correct thing to do here be the following? I think the order has to be the double-?? before the single-?.

    source = re.sub("^??", "#??", source, flags=re.M)
    source = re.sub("^?", "#?", source, flags=re.M)
    
    # followed by...
    
    black_source = re.sub("^#??", "??", black_source, flags=re.M)
    black_source = re.sub("^#?", "?", black_source, flags=re.M)
    
    bug 
    opened by ericmjl 6
  • Print context with grep

    Print context with grep

    -B, --before-context=NUM  print NUM lines of leading context
    -A, --after-context=NUM   print NUM lines of trailing context
    -C, --context=NUM         print NUM lines of output context
    
    enhancement 
    opened by vinayak-mehta 0
Owner
Vinayak Mehta
Working on open source tools
Vinayak Mehta
Lets you view, edit and execute Jupyter Notebooks in the terminal.

Lets you view, edit and execute Jupyter Notebooks in the terminal.

David Brochart 684 Dec 28, 2022
Euporie is a text-based user interface for running and editing Jupyter notebooks

Euporie is a text-based user interface for running and editing Jupyter notebooks

null 781 Jan 1, 2023
xonsh is a Python-powered, cross-platform, Unix-gazing shell

xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

xonsh 6.7k Dec 31, 2022
adds flavor of interactive filtering to the traditional pipe concept of UNIX shell

percol __ ____ ___ ______________ / / / __ \/ _ \/ ___/ ___/ __ \/ / / /_/ / __/ / / /__/ /_/ / / / .__

Masafumi Oyamada 3.2k Jan 7, 2023
xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

xonsh xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt. The language is a superset of Python 3.6+ with additio

xonsh 6.7k Jan 8, 2023
gcptree - Like the unix tree command but for GCP Org Heirarchy

gcptree Like the unix tree command but for GCP Org Heirarchy. For a note on coloring, the org node is green, folders and blue, and projects that are n

Ryan Canty 25 Sep 6, 2022
A CLI Spigot plugin manager that adheres to Unix conventions and Python best practices.

Spud A cross-platform, Spigot plugin manager that adheres to the Unix philosophy and Python best practices. Some focuses of the project are: Easy and

Tommy Dougiamas 9 Dec 2, 2022
Python commandline tool for remembering linux/terminal commands

ehh Remember linux commands Commandline tool for remembering linux/terminal commands. It stores your favorite commands in ~/ehh.json in your homedir a

null 56 Nov 10, 2022
Management commands to help backup and restore your project database and media files

Django Database Backup This Django application provides management commands to help backup and restore your project database and media files with vari

null 687 Jan 4, 2023
A multipurpose discord bot with more than 220 commands

Welcome WM Bot A advanced bot with more than 220 commands to fit your needs Explore the commands » View Demo · Report Bug · Request Feature Table of C

Wasi Master 12 Dec 16, 2022
commandpack - A package of modules for working with commands, command packages, files with command packages.

commandpack Help the project financially: Donate: https://smartlegion.github.io/donate/ Yandex Money: https://yoomoney.ru/to/4100115206129186 PayPal:

null 4 Sep 4, 2021
AWS Interactive CLI - Allows you to execute a complex AWS commands by chaining one or more other AWS CLI dependency

AWS Interactive CLI - Allows you to execute a complex AWS commands by chaining one or more other AWS CLI dependency

Rafael Torres 2 Dec 10, 2021
Output Analyzer for you terminal commands

Output analyzer (OZER) You can specify a few words inside config.yaml file and specify the color you want to be used. installing: Install command usin

Ehsan Shirzadi 1 Oct 21, 2021
CLI/GUI Math commands based on python 3

PyMath Commands Syntax Installation Commands: pymath add: usage: pymath add 12.5 12.5 sub: usage: pymath sub 25 12.5 div: usage: pymath div 144 12 mul

eggsnham07 0 Nov 22, 2021
A terminal tool for git. When we use git, do you feel very uncomfortable with too long commands

PIGIT A terminal tool for git. When we use git, do you feel very uncomfortable with too long commands. For example: git status --short, this project c

Zachary 1 Apr 9, 2022
⚙ A lightweight command line interface library for creating commands.

⚙ A lightweight command line interface library for creating cli commands. About | Installation | Usage | Features | Contributors | License About Next:

Serum 16 Sep 25, 2022
tox-server is a command line tool which runs tox in a loop and calls it with commands from a remote CLI.

Tox Server tox-server is a command line tool which runs tox in a loop and calls it with commands from a remote CLI. It responds to commands via ZeroMQ

Alexander Rudy 3 Jan 10, 2022
🐍The nx-python plugin allows users to create a basic python application using nx commands.

?? NxPy: Nx Python plugin This project was generated using Nx. The nx-python plugin allows users to create a basic python application using nx command

StandUP Communications 74 Aug 31, 2022
CryptoCo-py is a Python CLI application that uses CoinGecko API to allow the user to query cryptocurrency information by typing simple commands.

CryptoCo-py is a Python CLI application that uses CoinGecko API to allow the user to query cryptocurrency information by typing simple com

null 1 Jan 10, 2022