damienmarlier51 / Junix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pypi pytest

Junix (JUpyter Notebook Image eXporter)

Junix is a simple python package to export images from a Jupyter Notebook.

Given a notebook like the one below, Junix can export its images into separate files.
Alternatively, it can extract notebook images alongside their associated context and store them into a dictionary list leaving further processing in the hands of the user.

Input
Screenshot 2019-09-15 at 2 06 49 PM

Output
Screenshot 2019-09-15 at 1 52 45 PM

Installation

Using pip

pip install junix

Using source code

git clone https://github.com/damienmarlier51/JupyterNotebookImageExporter.git
cd JupyterNotebookImageExporter; python setup.py install

Getting started

From Python

Export images as files

junix.export_images(filepath=filepath, output_dir=output_dir, prefix=prefix)

Parameters:

filepath: Notebook filepath
output_dir (Optional): Default value is current directory (pwd)
prefix (Optional): Default value is notebook filename

Extract images into dictionary list

images = junix.get_images(filepath=filepath)

Parameters:

filepath: Notebook filepath

images will have the following schema:

images = [{
    "cell_idx": cell_idx,  # Cell index
    "output_idx": output_idx,  # Output index
    "content_type": content_type,  # Content type
    "img_data": img_data  # Image data
}, ...]

From command line

junix --filepath /path/to/notebook --output_dir path/to/output/directory --prefix my_prefix
junix -f /path/to/notebook -o path/to/output/directory -p my_prefix

Example

Example can be found example/example.ipynb.

You can test the python API by running the following command from root directory:
python -m example.export_example

It will export images into folder example/example_images_1.

You can test as well the CLI by running the following command from root directory:
junix -f example/example.ipynb -o example/example_images_2 -p nb

It will export images into folder example/example_images_2.

Test

Run pytest from root directory

References

Medium blog post: https://medium.com/analytics-vidhya/export-images-from-jupyter-notebook-with-a-single-command-422db2b66e92

About

License:MIT License


Languages

Language:Jupyter Notebook 98.7%Language:Python 1.3%Language:Shell 0.0%