Skip to main content

Jupyter-like cell running in ipython

Project description

ipython-cells

This is an IPython extension for those who prefer to work in a terminal but still need the cell-by-cell execution provided by a Jupyter notebook.

Example Jupyter notebook:

Running exported notebook with ipython-cells:

Quickstart

Install the extension:

pip install ipython-cells

Convert an existing notebook to a Python file (In Jupyter):

Cell > Run All
File > Download As > python (.py)

Execute cells in iPython:

>>> %load_ext ipython_cells
>>> %load_file my_notebook.py
>>> %cell_run 1
>>> %cell_run 2
array([1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])

You can freely add/delete/rename cells in the downloaded my_notebook.py. my_notebook.py is automatically reloaded when changes are made.

Alternatively, you can create a new .py file from scratch without starting from a Jupyter notebook. See the cell delimiter syntax.

Other Features

Spyder cell delimiter syntax is also supported:

# %% cell1
print('hello')

# %% cell2
print('world')

Other commands:

# cell ranges - run all cells from beginning of file to cell2 (inclusive)
>>> %cell_run ^cell2
hello
world

# cell ranges - run all cells from cell1 (inclusive) to end of file
>>> %cell_run cell1$
hello
world

# list available cells for running
>>> %list_cells
['__first', 'cell1', 'cell2']

Automatically Load Extension

To load extension on IPython start, add this to ~/.ipython/profile_default/ipython_config.py

c.InteractiveShellApp.extensions = [
    'ipython_cells'
]

Autoreloading

# load example.py with autoreloading
%load_file example.py

%cell_run cell1
10
# example.py is modified by an external editor (e.g. `a = 10`  ->  `a = 20`)
# File change is detected and automatically reloaded
%cell_run cell1
20

Auto reloading can be disabled with %load_file example.py --noreload

Cell Delimiter Syntax

Cells are delimited by special comments. Both Jupyter and Spyder style cells are supported. Below are different variations of a cell called foobar_cell.

  • # %% foobar_cell
  • # In[foobar_cell]
  • # %% foobar_cell some extra text
  • # In[foobar_cell] some extra text

Running Exported Jupyter Notebooks

This extension can run exported Jupyter notebooks. (File > Download As > python (.py)).

Be sure to run all cells before exporting so they are assigned an index. (Cell > Run All).

Tests

cd tests
ipython3 tests.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipython_cells-5.2.2.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipython_cells-5.2.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file ipython_cells-5.2.2.tar.gz.

File metadata

  • Download URL: ipython_cells-5.2.2.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for ipython_cells-5.2.2.tar.gz
Algorithm Hash digest
SHA256 c430d3177a594cef730e88366435e3be4f800c31ca2f173fe6234d4c6b23cf46
MD5 995b4536d474dbfe338ad039bd999f82
BLAKE2b-256 8664d747a23056f779195f901c63b8a108a354af77dca1187fb8a7cd91625795

See more details on using hashes here.

File details

Details for the file ipython_cells-5.2.2-py3-none-any.whl.

File metadata

  • Download URL: ipython_cells-5.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for ipython_cells-5.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f5fe6eafe4f4190807d11da06b7a44c16742664c4fc8352b9fbf609a2ba0453
MD5 af565f51609448ec53ca31d90edc29f0
BLAKE2b-256 a2a07ee7894e53aa4222762cfa5181ea758e085b5f47d1293247dff3683d371f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page