Skip to content

grst/nbwrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nbwrapper

toolbox to run ipython notebooks as command line script with parameters

When working on bioinformatics projects, I often start off trying out stuff in a ipython notebook. I usually end up having a whole data-processing pipeline in the notebook. To run this pipeline on a cluster or on different datasets, it would be nice to have it as a command line script with input parameters.

Based on runipy this toolbox helps building such command line wrapper scripts.

Installation

Simply pip install nbwrapper. python setup.py install also works.

Build the wrapper script

Use e.g. argparse to parse the command line arguments, use nbwrapper to run the notebook.

test-wrapper.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from nbwrapper import Nbwrapper
import argparse


argp = argparse.ArgumentParser()
argp.add_argument("--foo", '-a', help="foo arg")
argp.add_argument("--bar", '-b', help="bar arg")

args = argp.parse_args()
nb = Nbwrapper(args, "test.ipynb")
nb.run()

Retrieve arguments in the notebook

nbwrapper.getargs() returns a dict containing the arguments.

test.ipynb

# IN[0]:
    from nbwrapper import getargs
    args = getargs()
    print(args)

About

toolbox to run ipython notebooks as command line script with parameters

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published