Metadata-Version: 2.3
Name: jupyter-io
Version: 2.0.0
Summary: Saving and loading files directly into Jupyter notebooks
Project-URL: homepage, https://astropenguin.github.io/jupyter-io/v2.0.0
Project-URL: repository, https://github.com/astropenguin/jupyter-io
Author-email: Akio Taniguchi <taniguchi.akio@gmail.com>
License: MIT License
        
        Copyright (c) 2020-2024 Akio Taniguchi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Keywords: io,jupyter,python
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: <3.14,>=3.9
Requires-Dist: ipython<9.0,>=7.0
Requires-Dist: matplotlib<4.0,>=3.0
Requires-Dist: pandas-stubs<3.0,>=1.5
Requires-Dist: pandas<3.0,>=1.5
Description-Content-Type: text/markdown

# jupyter-io

[![Release](https://img.shields.io/pypi/v/jupyter-io?label=Release&color=cornflowerblue&style=flat-square)](https://pypi.org/project/jupyter-io/)
[![Python](https://img.shields.io/pypi/pyversions/jupyter-io?label=Python&color=cornflowerblue&style=flat-square)](https://pypi.org/project/jupyter-io/)
[![Downloads](https://img.shields.io/pypi/dm/jupyter-io?label=Downloads&color=cornflowerblue&style=flat-square)](https://pepy.tech/project/jupyter-io)
[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.14379974-cornflowerblue?style=flat-square)](https://doi.org/10.5281/zenodo.14379974)
[![Tests](https://img.shields.io/github/actions/workflow/status/astropenguin/jupyter-io/tests.yaml?label=Tests&style=flat-square)](https://github.com/astropenguin/jupyter-io/actions)

Saving and loading files directly into Jupyter notebooks

## Installation

```shell
pip install jupyter-io
```

## File saving

jupyter-io provides the `in_notebook` function to directly save (i.e. embed) files to Jupyter notebooks.
Suppose you create a Matplotlib figure want to save it as a PDF file.
The following code will save the PDF file into your local environment:
```python
import matplotlib.pyplot as plt

plt.plot([1, 2, 3])
plt.savefig("figure.pdf")
```
This should work in many cases, however, in a virtual environment like [Google Colaboratory](https://colab.research.google.com/), you will not be able to get the file once the Jupyter server is stopped.
By wrapping the file path by `in_notebook`, the PDF file will be directly saved to the Jupyter notebook and you will get a download link instead:
```python
import matplotlib.pyplot as plt
from jupyter_io import in_notebook

plt.plot([1, 2, 3])
plt.savefig(in_notebook("figure.pdf"))
```
The download link works when the Jupyter server is stopped, and even when it does not exist.
This makes Jupyter notebooks more portable, for example, to share the output data other than images together with them.

### More examples

To save a pandas series into a notebook:

```python
import pandas as pd
from jupyter_io import in_notebook

ser = pd.Series([1, 2, 3])
ser.to_csv(in_notebook("series.csv"))
```

To save a general text into a notebook:

```python
from jupyter_io import in_notebook

with open(in_notebook("output.txt"), "w") as f:
    f.write("1, 2, 3\n")
```

## File loading

The file loading feature has not been implemented yet.
