Skip to main content

A JupyterLab extension

Project description

jupyterlab-env-sync

Build PyPI Binder

A JupyterLab 4.x extension that provides a shared service for propagating environment variables to running kernels (Python, R, Julia) and terminals.

Other extensions consume jupyterlab-env-sync via the IEnvSync token to set, reset, and query environment variables without dealing with kernel injection or terminal lifecycle directly.

Features

  • Kernel propagation — injects env var changes into all running Python, R, and Julia kernels
  • Terminal restart — restarts open terminals so they inherit updated variables, with a toast notification
  • Startup hooks — new kernels and terminals automatically pick up overrides via IPython/R/Julia startup scripts
  • Multi-extension support — multiple consumer extensions can set variables independently; ownership is tracked per key
  • Spawner-aware reset — resetting a variable restores the original spawner value (or deletes it if none existed)

Requirements

  • JupyterLab >= 4.0.0
  • Python >= 3.8

Installation

pip install jupyterlab-env-sync

API

Consumer extensions depend on the IEnvSync token:

import { IEnvSync } from 'jupyterlab-env-sync';

const plugin: JupyterFrontEndPlugin<void> = {
  id: 'my-extension:plugin',
  autoStart: true,
  requires: [IEnvSync],
  activate: async (app: JupyterFrontEnd, envSync: IEnvSync) => {
    await envSync.setVar(
      'my-extension',
      'DATABASE_URL',
      'postgres://localhost/mydb'
    );
  }
};

Methods

Method Signature Description
setVar (extId, key, value) → Promise<void> Set a variable. Propagates to all kernels and restarts terminals.
resetVar (extId, key, force?) → Promise<void> Reset to spawner value. Only the owner can reset unless force=true.
getAll () → Promise<Record<string, IEnvEntry>> All overrides with metadata (value, spawner_value, set_by, set_at).
getByExtension (extId) → Promise<Record<string, string>> Variables owned by a specific extension (key-value pairs).
resetAllByExtension (extId) → Promise<void> Reset all variables owned by an extension.

Example: MinIO credentials

import { IEnvSync } from 'jupyterlab-env-sync';

const plugin: JupyterFrontEndPlugin<void> = {
  id: 'my-minio-extension:plugin',
  autoStart: true,
  requires: [IEnvSync],
  activate: async (app: JupyterFrontEnd, envSync: IEnvSync) => {
    await envSync.setVar(
      'my-minio-extension',
      'MINIO_ENDPOINT',
      'https://minio.example.com'
    );
    await envSync.setVar(
      'my-minio-extension',
      'MINIO_ACCESS_KEY',
      'my-access-key'
    );
    await envSync.setVar(
      'my-minio-extension',
      'MINIO_ACCESS_SECRET',
      'my-secret-key'
    );

    // All running kernels now have these variables in os.environ.
    // New kernels pick them up automatically via the IPython startup hook.
    // Secret values (keys matching SECRET, PASSWORD, TOKEN, PRIVATE_KEY)
    // are masked in kernel startup log output.
  }
};

Consumer package.json

{
  "dependencies": {
    "jupyterlab-env-sync": "^1.0.0"
  },
  "jupyterlab": {
    "sharedPackages": {
      "jupyterlab-env-sync": { "bundled": false, "singleton": true }
    }
  }
}

bundled: false and singleton: true are required so all extensions share the same IEnvSync token instance.

Development

Development Installation

# Clone the repository
git clone https://github.com/aristide/jupyterlab-env-sync.git
cd jupyterlab-env-sync

# Set up a virtual environment
virtualenv .venv
source .venv/bin/activate

# Install in development mode
pip install -e ".[test]"

# Link the extension with JupyterLab
jupyter labextension develop . --overwrite

# Enable the server extension
jupyter server extension enable jupyterlab-env-sync

# Build the TypeScript source
jlpm build

Running Tests

# Python tests (env store + REST handlers)
pytest jupyterlab-env-sync/tests/ -v

# TypeScript tests (kernel injection snippets)
jlpm test

# UI tests (requires Playwright)
cd ui-tests && jlpm install && npx playwright test

Development Uninstallation

jupyter server extension disable jupyterlab-env-sync
pip uninstall jupyterlab-env-sync

License

BSD-3-Clause

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

jupyterlab_env_sync-1.1.1.tar.gz (848.2 kB view details)

Uploaded Source

Built Distribution

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

jupyterlab_env_sync-1.1.1-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlab_env_sync-1.1.1.tar.gz.

File metadata

  • Download URL: jupyterlab_env_sync-1.1.1.tar.gz
  • Upload date:
  • Size: 848.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jupyterlab_env_sync-1.1.1.tar.gz
Algorithm Hash digest
SHA256 79d897600745ee0a35a55702b0503aad1b29cfc0236e65c469d3aefc2b9e632f
MD5 5e65020ca7f29b2c164a6a26b90cfc08
BLAKE2b-256 da9dbac821c331313dd94364913f1e1dddac74f2188d2b8830af4a4d72484dbd

See more details on using hashes here.

File details

Details for the file jupyterlab_env_sync-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyterlab_env_sync-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a495ea1504738cba312f3fa029c22ca3f3ddcc074676bd322015d02f9611037
MD5 2d4c4ad1ed77bbcbfd56e2742afe130c
BLAKE2b-256 f205f8762eeab4d32119d990a66e7b1b5f2843bcc1bab5683c12f8596919fed4

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