Skip to main content

EasyJupyter allows you to effortlessly integrate your Jupyter Notebook code into any Python project or other notebooks.

Project description

EasyJupyter

EasyJupyter allows you to effortlessly integrate your Jupyter Notebook code into any Python project or other notebooks. It intelligently transforms your notebooks into standard Python modules, allowing you to import functions, classes, and variables as if they were regular .py files. This seamless process, managed by a background caching mechanism, lets you leverage the interactive development environment of notebooks for rapid prototyping and analysis, while ensuring your code is modular and reusable.

This is particularly useful for AI/Data science projects. For example, if you are building out a Transformer architecture, you could code and write notes for each layer of the model in its own notebook, and then seamlessly import them into your main project or another notebook.

Key Benefits:

  • Native GitHub Rendering: Keep your code in notebooks so plots and markdown render natively on GitHub.
  • Zero Clutter: Generated cache files are stored in a hidden .easyJupyter_cache directory, keeping your workspace clean.
  • Custom ignore syntax to ignore exploratory cells, or lines of code.

How It Works: When EasyJupyter is first imported within a project, it initiates a single, detached background daemon for that specific project. This daemon is tied to your project's root (specifically, the generated .easyJupyter_cache/watcher.pid file) and monitors only the notebooks within it. This per-project design ensures that different projects can have their own daemons completely isolated and do not interfere with each other. If the daemon for a project is not already running, it will be started automatically the next time you import EasyJupyter within that project's environment.

Table of Contents

Ignore Notebook Commands

Use these commands inside notebooks to control what gets compiled into the cache.

  • Markdown Cells: Ignored by default.
  • Ignore An Entire Cell:
    • Add # @i-c to the very top of the cell.
  • Ignore One Line In A Cell:
    • Add # @i-l above the line you want to ignore.

Getting Started

Installation

pip install easyjupyter

Usage

In your project's entry point (e.g., main.py) and in any Jupyter Notebooks where you want the daemon to be active or when importing from other notebooks, import the library at the very top of the file:

import EasyJupyter # Import at the very top of the file
from my_notebook import Class, Function_name
  • Importing EasyJupyter in many files is not a problem, as only one daemon can run at a time per project, you could import it in all your files if you want.

[!important] ⭐️ Never edit the cache files directly, only edit the notebooks!

⭐️ If your project has nested folders, and does contain a .git or pyproject.toml. Create a .easyJupyterConfig file in the root of your project, run:

# cd into your project root
touch .easyJupyterConfig 
echo "EasyJupyter: The file tells the daemon that this directory is the root of your project." > .easyJupyterConfig

[!NOTE]

  • You should use Notebook automatic reloading if you are simultaneously working with many notebooks that import each other. Add the following to a cell at the top of notebooks!

    # @i-c
    %load_ext autoreload
    %autoreload 2
    
  • Examples:

    • example_nested_project. Note run main.py from inside ./example_nested_project, also for VSC's Pylance to kick in, open a new VSC window with ./example_nested_project as root, and follow VSC Pylance Intellisense Setup below.
    • A larger project example

Arguments

  • Always run easyjupyter --<argument> from somewhere in a project, where the daemon lives.

Sync All Notebooks

  • Sync all notebooks to the cache, run:
    • Do this only if your cache is empty and you have existing notebooks, not every time you update a notebook.

      easyjupyter --sync
      

Cache Cleanup

  • If you rename, move, or delete a notebook, the old cache file will remain in the hidden cache directory. To clean up the cache, run:

    easyjupyter --clean
    

Watch Daemon Logs

  • If you incorrectly use EasyJupyter in a notebook (e.g., redundant ignore comments), warnings will be embedded directly into the generated cache file. These warnings will be printed to the console (or notebook output) whenever the cached module is imported and executed, even when importing from another notebook. However, if you want to view the live warnings as the daemon runs, run:

    easyjupyter --watch
    

Stop Daemon

  • The daemon process will terminate by itself, however, if you need to gracefully stop the background daemon process, run:

    easyjupyter --stop
    # Or hard stop: `pkill -f EasyJupyter.watcher`
    

VSC Pylance Intellisense Setup

VS Code's Pylance intellisense will not natively work with notebooks, or the hidden cache files generated for the notebooks. But you can tell it where to look for the cache files. Run one of the following commands in the root of your project:

  1. If you don't have a .vscode/settings.json file yet, run:

    mkdir -p .vscode && echo '{
        "python.analysis.extraPaths": [
            "./.easyJupyter_cache"
        ]
    }' > .vscode/settings.json
    
  2. If you already have a .vscode/settings.json file, add the following inside the {} brackets:

    "python.analysis.extraPaths": [
        "./.easyJupyter_cache"
    ]
    
  3. Make sure that in VSC you are selecting the environment that has EasyJupyter installed. For notebooks, VSC will prompt you to select the environment when you run a cell in a notebook. For .py files, you can manually select the environment in the bottom right corner of VSC.

Resolving Errors

If any issues occur with the watcher daemon, manually run it with: python -m EasyJupyter.watcher (note that this spawns the daemon in the foreground for debugging). If the daemon is already running in the background, you will need to delete the .easyJupyter_cache/watcher.pid file first.

You can always check the background daemon logs inside .easyJupyter_cache/watcher.log.

FAQ: #TODO add more things

  • Import Issues:
    • Did you add the .easyJupyterConfig file to the root of your project?
    • Did you name the notebook with a - instead of a _?
    • Did you add EasyJupyter to the notebook to be imported and run it?
  • Errors:
    • Did you forget to use ignore syntax in the notebook that you are trying to import?
  • For VSC intellisense, did you add the extraPaths to your settings.json
  • If AI coding assistants are suggesting edits in the hidden cache files, add .easyJupyter_cache/ to that AI's config ignore files e.g., .cursorignore..

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

easyjupyter-0.1.8.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

easyjupyter-0.1.8-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file easyjupyter-0.1.8.tar.gz.

File metadata

  • Download URL: easyjupyter-0.1.8.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for easyjupyter-0.1.8.tar.gz
Algorithm Hash digest
SHA256 e9a182760d9a510a5346e901613756c1a7a83b91f7dbf4437ab07e9e55bbf1e6
MD5 ab006f54187b92e9517edbaa9f7d6940
BLAKE2b-256 147ea0d205b856ee91a8be6b60faaf5b906abfdbc97cd54018ffdaf1b66970b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for easyjupyter-0.1.8.tar.gz:

Publisher: release.yaml on t20e/EasyJupyter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file easyjupyter-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: easyjupyter-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for easyjupyter-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 18bf8d049c97f9bf78e075dda682cdf9f8decfaed8075e6b6b4546ea50dfc711
MD5 8529e2407b769e197da16c8401993c43
BLAKE2b-256 d03a80f98ff59b8cdf7aa8b897f50cc8e1e96cb6b39e0db41defff5d7ed8cadf

See more details on using hashes here.

Provenance

The following attestation bundles were made for easyjupyter-0.1.8-py3-none-any.whl:

Publisher: release.yaml on t20e/EasyJupyter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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