Skip to main content

Harmonises Jupyter and Colab notebook environments for consistent paths, imports, and working directories

Project description

colocal

Colab or local — same behaviour, same results.

colocal is a lightweight utility that harmonises notebook environments across Google Colab and local Jupyter.

It automatically ensures your repository structure, imports, and working directory are consistent — so your notebooks run the same everywhere.


✨ Features

  • Seamless dual support → Detects Colab vs Jupyter automatically.
  • Clean imports → Adds your repository root to sys.path.
  • Consistent working directory → Sets cwd to the notebook’s folder, avoiding fragile ../../ paths.
  • Branch-aware in Colab → Parses the Colab badge, checks out the correct branch, and mirrors your local repo structure.
  • Fallback support → If the notebook has no badge, you can specify the GitHub URL directly.
  • Reproducibility → Run the same notebook in Colab or locally with identical results.

🚀 Usage

🟢 Running in Colab

If your notebook has a Colab badge that points to a Github repo like:

<a href="https://colab.research.google.com/github/org/repo/blob/main/notebooks/demo.ipynb">
  <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>

just run:

import colocal
colocal.setup()

colocal will:

  • Clone the correct repo and branch into /content/
  • Add it to sys.path
  • Set the working directory to match the notebook’s location in the repo

🟡 No badge? Specify the repo manually

If the notebook doesn’t include a Colab badge, just provide the repository URL:

import colocal
colocal.setup("https://github.com/org/repo")

This clones the repo’s default branch, adds it to sys.path, and sets the working directory to the repo root.


⚪ Running locally

If you’re in a local Jupyter environment, colocal:

  • Detects the current notebook’s location
  • Finds the repository root (via .git)
  • Adds it to sys.path
  • Changes directory to the notebook’s folder

That’s it — your imports and paths are now consistent with the Colab version.


🧩 Return values

repo_root, branch, cwd = colocal.setup(...)
  • repo_root → path to the repository root
  • branch → current branch name (if known)
  • cwd → current working directory after setup

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

colocal-2025.11.6.1340.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

colocal-2025.11.6.1340-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file colocal-2025.11.6.1340.tar.gz.

File metadata

  • Download URL: colocal-2025.11.6.1340.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for colocal-2025.11.6.1340.tar.gz
Algorithm Hash digest
SHA256 26632d00a47434a834ce3dbb4195c90a357bc8cff892c2295aebee058b2584fa
MD5 9d0c24603fa9d92b89ec8197e40ddffb
BLAKE2b-256 abeb271681deff5d74941bcb7a4312523eb4c45e8f055b047e34e72552887412

See more details on using hashes here.

Provenance

The following attestation bundles were made for colocal-2025.11.6.1340.tar.gz:

Publisher: publish.yml on project-ida/colocal

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

File details

Details for the file colocal-2025.11.6.1340-py3-none-any.whl.

File metadata

File hashes

Hashes for colocal-2025.11.6.1340-py3-none-any.whl
Algorithm Hash digest
SHA256 8b91d653db03329de67fa7e3fe83dd6177d6ad1a00371e6137315bfb7eb345a4
MD5 c0a9c95e15417124d62fe4083a594f74
BLAKE2b-256 1fbca9c211f630491a6bb528d0462bf4c3726ae1745ca4fcd6edb8fa8e02a6a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for colocal-2025.11.6.1340-py3-none-any.whl:

Publisher: publish.yml on project-ida/colocal

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