Skip to main content

Jupyter notebooks as Markdown documents, Julia, Python or R scripts

Project description

CI Documentation Status codecov.io Language grade: Python Code style: black GitHub language count Conda Version Pypi pyversions Binder:notebook Binder:lab launch - renku

Have you always wished Jupyter notebooks were plain text documents? Wished you could edit them in your favorite IDE? And get clear and meaningful diffs when doing version control? Then... Jupytext may well be the tool you're looking for!

Jupytext is a plugin for Jupyter that can save Jupyter notebooks as either

Use cases

Common use cases for Jupytext are:

  • Doing version control on Jupyter Notebooks
  • Editing, merging or refactoring notebooks in your favorite text editor
  • Applying Q&A checks on notebooks.

Install

You can install Jupytext with

  • pip install jupytext
  • or conda install jupytext -c conda-forge.

Please note that Jupytext includes an extension for Jupyter Lab. In the latest version of Jupytext, this extension is compatible with Jupyter Lab >= 3.0 only. If you use Jupyter Lab 2.x, please either stay with Jupytext 1.8.2, or install, on top of the latest pip or conda version of Jupytext, a version of the extension that is compatible with Jupyter Lab 2.x:

jupyter labextension install jupyterlab-jupytext@1.2.2  # For Jupyter Lab 2.x

Then, restart your Jupyter server (for more installation details, see the install section in the documentation).

When Jupytext is installed, .py and .md files have a notebook icon. And you can really open and run these files as notebooks

    With a click on the text file in Jupyter Notebook

    (click on the image above to try this on Binder)

    With a click on the text file in JupyterLab (⭐New⭐) To do that, you will need to change the default viewer for text notebooks by copy-pasting the following settings (or the subset that matches your use case) in the `Document Manager` section:
    {
      "defaultViewers": {
        "markdown": "Jupytext Notebook",
        "myst": "Jupytext Notebook",
        "r-markdown": "Jupytext Notebook",
        "quarto": "Jupytext Notebook",
        "julia": "Jupytext Notebook",
        "python": "Jupytext Notebook",
        "r": "Jupytext Notebook"
      }
    }
    

    Here is a screencast of the steps to follow:

    (click on the image above to try this on Binder)

    Another possibility is to activate this with a default_setting_overrides.json file in the .jupyter/labconfig folder with e.g.

    wget https://raw.githubusercontent.com/mwouts/jupytext/main/binder/labconfig/default_setting_overrides.json -P  ~/.jupyter/labconfig/
    

    Note: to open links to .md files in notebooks with the Notebook editor, use jupyterlab>=4.0.0a16.

    With a right click and open with notebook in Jupyter Lab

    (click on the image above to try this on Binder)

Paired notebooks

The most convenient way to use Jupytext is probably through paired notebooks.

To pair a given .ipynb or text notebook to an additional notebook format, use either

    the "pair notebook with..." commands in Jupyter Lab

    the "pair notebook with..." menu entries in Jupyter Notebook

    jupytext at the command line

    with e.g.

    jupytext --set-formats ipynb,py:percent notebook.ipynb
    

    see the documentation.

    or a local or global jupytext.toml configuration file.

    with e.g. the following content:

    formats = "ipynb,py:percent"
    

    see the documentation.

When you save a paired notebook in Jupyter, both the .ipynb file and the text version are updated on disk.

When a paired notebook is opened or reloaded in Jupyter, the input cells are loaded from the text file, and combined with the output cells from the .ipynb file.

You can edit the text representation of the notebook in your favorite editor, and get the changes back in Jupyter by simply reloading the notebook (Ctrl+R in Jupyter Notebook, "reload notebook" in Jupyter Lab). And the changes are propagated to the .ipynb file when you save the notebook.

Alternatively, you can synchronise the two representations by running jupytext --sync notebook.ipynb at the command line.

Which text format?

Jupytext implements many text formats for Jupyter Notebooks. If your notebook is mostly made of code, you will probably prefer to save it as a script:

  • Use the percent format, a format with explicit cell delimiters (# %%), supported by many IDE (Spyder, Hydrogen, VS Code, PyCharm and PTVS)
  • Or use the light format, if you prefer to see fewer cell markers.

If your notebook contains more text than code, if you are writing a documentation or a book, you probably want to save your notebook as a Markdown document

More resources?

If you're new to Jupytext, you may want to start with the FAQ or with the Tutorials, or with this short introduction to Jupytext: .

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 Distribution

jupytext-1.13.8.tar.gz (742.8 kB view details)

Uploaded Source

Built Distribution

jupytext-1.13.8-py3-none-any.whl (297.6 kB view details)

Uploaded Python 3

File details

Details for the file jupytext-1.13.8.tar.gz.

File metadata

  • Download URL: jupytext-1.13.8.tar.gz
  • Upload date:
  • Size: 742.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.13

File hashes

Hashes for jupytext-1.13.8.tar.gz
Algorithm Hash digest
SHA256 60148537de5aa08bb9cbe8797500a49360b7a8eb6667736ae5b80e3ec7ba084d
MD5 2718888b346515cd7dd0ffb26bc73a46
BLAKE2b-256 0a71e9a9dca39ab6c211804f5672c6e70789d090f11220f545ad873c66fec16b

See more details on using hashes here.

File details

Details for the file jupytext-1.13.8-py3-none-any.whl.

File metadata

  • Download URL: jupytext-1.13.8-py3-none-any.whl
  • Upload date:
  • Size: 297.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.13

File hashes

Hashes for jupytext-1.13.8-py3-none-any.whl
Algorithm Hash digest
SHA256 625d2d2012763cc87d3f0dd60383516cec442c11894f53ad0c5ee5aa2a52caa2
MD5 5088a12da1eaa5f857673e434baff31b
BLAKE2b-256 f9e3538509410372acd6d41f12c028dfc75ebddfbc4f7544f933bff7b5cc3e97

See more details on using hashes here.

Supported by

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