Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rossant/ipycache
Defines a %%cache cell magic in the IPython notebook to cache results of long-lasting computations in a persistent pickle file
https://github.com/rossant/ipycache
Last synced: 25 days ago
JSON representation
Defines a %%cache cell magic in the IPython notebook to cache results of long-lasting computations in a persistent pickle file
- Host: GitHub
- URL: https://github.com/rossant/ipycache
- Owner: rossant
- License: bsd-3-clause
- Created: 2013-10-08T13:16:17.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-08-22T19:50:43.000Z (over 2 years ago)
- Last Synced: 2024-11-10T01:12:58.577Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 135 KB
- Stars: 138
- Watchers: 10
- Forks: 35
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- best-of-jupyter - GitHub - 43% open · ⏱️ 21.11.2024): (Jupyter Magic)
README
# ipycache
[![Build Status][github-ci-badge]][github-ci-url]
[![Latest PyPI version][pypi-badge]][pypi-url][github-ci-badge]: https://github.com/rossant/ipycache/actions/workflows/master.yml/badge.svg
[github-ci-url]: https://github.com/rossant/ipycache/actions/workflows/master.yml
[pypi-badge]: https://img.shields.io/pypi/v/ipycache.svg
[pypi-url]: https://pypi.org/project/ipycache/Defines a `%%cache` cell magic in the IPython notebook to cache results and
outputs of long-lasting computations in a persistent pickle file. Useful when
some computations in a notebook are long and you want to easily save the results
in a file.## Examples
* [Sample usage](examples/example.ipynb)
* [Example with output](examples/example_outputs.ipynb)
* [Simultaneously printing and capturing output](examples/capture_output.ipynb)## Installation
Latest PyPI release:
pip install ipycache
Latest development version:
pip install git+https://github.com/rossant/ipycache.git
## Usage
In IPython, execute the following:%load_ext ipycache
Then, create a cell with:
%%cache mycache.pkl var1 var2
var1 = 1
var2 = 2When you execute this cell the first time, the code is executed, and the
variables `var1` and `var2` are saved in `mycache.pkl` in the current directory
along with the outputs. Rich display outputs are only saved if you use the
development version of IPython. When you execute this cell again, the code is
skipped, the variables are loaded from the file and injected into the namespace,
and the outputs are restored in the notebook.Alternatively use `$file_name` instead of `mycache.pkl`, where `file_name` is a
variable holding the path to the file used for caching.Use the `--force` or `-f` option to force the cell's execution and overwrite the
file.Use the `--read` or `-r` option to prevent the cell's execution and always load
the variables from the cache. An exception is raised if the file does not exist.Use the `--cachedir` or `-d` option to specify the cache directory. You can
specify a default directory in the IPython configuration file in your profile
(typically in `~\.ipython\profile_default\ipython_config.py`) by adding the
following line:c.CacheMagics.cachedir = "/path/to/mycache"
If both a default cache directory and the `--cachedir` option are given, the
latter is used.