Skip to main content

Saving and loading files directly into Jupyter notebooks

Project description

jupyter-io

Release Python Downloads DOI Tests

Saving and loading files directly into Jupyter notebooks

Installation

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 to your local environment:

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, 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:

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 to a notebook:

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 to a notebook:

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.

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

jupyter_io-2.0.1.tar.gz (83.3 kB view details)

Uploaded Source

Built Distribution

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

jupyter_io-2.0.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_io-2.0.1.tar.gz.

File metadata

  • Download URL: jupyter_io-2.0.1.tar.gz
  • Upload date:
  • Size: 83.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for jupyter_io-2.0.1.tar.gz
Algorithm Hash digest
SHA256 f1628da77450740fad7aa7a1ba5c46f66a93c4cc0e5f24656f43f784e93fedb3
MD5 a2af1a0443385729914f446a4f18fd3f
BLAKE2b-256 3513b7bc75c9afffa5451039c8cf145f9a2d0779fa73eedeac3f9995392acb0e

See more details on using hashes here.

File details

Details for the file jupyter_io-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: jupyter_io-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for jupyter_io-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c03b1f68ea696058aec19dd5a657d25f028957ac25743b3a732828a6b3555a1c
MD5 e9f0c95eeade417099f1bc90604f2928
BLAKE2b-256 b4b40ec6640f23781ca9f993fb308c126dab68e7acf9f3372c4a865dd6a65dda

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