Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

1.0 KB
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */
class URLPyodideRouter {
  public getFilename(): string | null {
    return this.getSearchParam("filename");
  }
  public setFilename(filename: string) {
    this.setSearchParam("filename", filename);
  }

  public getCodeFromSearchParam(): string | null {
    return this.getSearchParam("code");
  }

  public getCodeFromHash(): string | null {
    const hash = window.location.hash;
    const prefix = "#code/";
    if (!hash.startsWith(prefix)) {
      return null;
    }
    return hash.slice(prefix.length);
  }

  public setCodeForHash(code: string) {
    window.location.hash = `#code/${code}`;
  }

  private setSearchParam(key: string, value: string) {
    const url = new URL(window.location.href);
    url.searchParams.set(key, value);
    window.history.replaceState({}, "", url.toString());
  }

  private getSearchParam(key: string): string | null {
    const url = new URL(window.location.href);
    return url.searchParams.get(key);
  }
}

export const PyodideRouter = new URLPyodideRouter();