ipython_blocking offers a context manager and IPython magic to capture cell execution.
Project description
ipython_blocking
A Python library that offers a context manager to turn on cell execution capture/blocking in Jupyter notebooks/IPykernel. Useful when you need a "blocking widget".
Use-case
The intended use-case of this library was to handle "blocking" until a widget value changed or was filled out to satisfy some validation function. Widgets are often used in notebooks to offer elegant and robust form input for queries to remote API's or other complex query inputs. Unfortunately, it's typical that the rest of the code in a "widget-based notebook" ends up being created as callbacks and is forced into a style that is hard to read, hard to debug, and hard to manipulate.
ipython_blocking
offers a way to capture cell execution requests and then replay them after a condition is met, such as a widget changing value or other validation function is met. That effectively "blocks" a notebook so that you can write regular non-callback code that expects to access a widget's value directly and will only run after an appropriate value is set.
Examples
See the demo notebook for an interactive example. The following gifs demonstrate the problem and the proposed solution in the ipython_blocking
package.
The problem
Solution -- magic for widget change
If the argument in the %block
line magic is a Widget instance, then the cell execution capture contex will stop when that widget has changed value.
Solution -- magic for an arbitrary break function
If the argument in the %block
line magic is a function or class method, then the cell execution capture context will stop when that function or method evaluates to True.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file ipython_blocking-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: ipython_blocking-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.19.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 968b10d34c00ee8975a6cf77eb9c645c9f55743cef1579ea8af74755ddf1f3d0 |
|
MD5 | 481570c9b11decd4ffafee7c852ed1ef |
|
BLAKE2b-256 | 23f7afb602911486afb741a58dd55b0344766100747c7b67dda90b953eda66d2 |