colab_or_not.core module
- class colab_or_not.core.NotebookBridge(github_repo: str | None = None, github_branch: str = 'main', requirements_path: str | None = None, system_packages: List[str] | None = None, module_paths: List[str] | None = None, config_path: str | None = None, config_template: Dict[str, str] | None = None, _is_colab: bool = False, _config_loaded: bool = False, _dependencies_installed: bool = False, _modules_fetched: bool = False)
Bases:
objectClass for providing Jupyter notebooks with a simple bridge between Google Colab and other Jupyter environments.
- Parameters:
github_repo (Optional[str]) – GitHub repository in format “username/repo” (required only if you want to install requirements or modules)
github_branch (str) – GitHub repo branch to use (defaults to “main”)
requirements_path (Optional[str]) – Relative path to text file with requirements within repo (if any; e.g., “src/requirements.txt”; requires github_repo be supplied)
system_packages (Optional[List[str]]) – List of system packages to install with apt-get, brew, or choco (requires one of those system package managers to be available)
module_paths (Optional[List[str]]) – List of relative paths to Python modules to fetch in Colab (if any; requires github_repo be supplied)
config_path (Optional[str]) – Full path to local config file (optional; can use ~ for user home directory; only used when running outside Google Colab)
config_template (Optional[Dict[str, str]]) – Dict of config setting names and default values, for initializing a new config file (optional; only used when running outside Google Colab)
- __init__(github_repo: str | None = None, github_branch: str = 'main', requirements_path: str | None = None, system_packages: List[str] | None = None, module_paths: List[str] | None = None, config_path: str | None = None, config_template: Dict[str, str] | None = None, _is_colab: bool = False, _config_loaded: bool = False, _dependencies_installed: bool = False, _modules_fetched: bool = False) None
- get_input_files(prompt: str) List[str]
Get list of input files, either via Colab upload or local file selection.
- Parameters:
prompt (str) – User prompt (goes in the dialog title for pop-ups, otherwise above the in-notebook prompt)
- Returns:
List of strings with input file paths
- Return type:
List[str]
- get_output_dir(not_colab_dir: str, colab_subdir: str = '')
Get the output directory for output files, using the specified directory when running outside Colab and a subdirectory within /content when running in Colab. Will automatically create the directory if it doesn’t exist.
- Parameters:
not_colab_dir (str) – Path prefix to use when not running in Colab
colab_subdir (str) – Subdirectory within /content to use when running in Colab (defaults to “”)
- Returns:
Output directory
- Return type:
str
- get_setting(setting_name: str, default_value: Any | None = None) Any
Get a configuration setting from Colab userdata or local environment variable (which will include anything in a configured config file, if specified, since that file’s settings are loaded into environment variables).
- Parameters:
setting_name (str) – Name of the setting to retrieve
default_value (Any) – Default value to return if setting is not found
- Returns:
Value of the setting or default value
- Return type:
Any
- property is_colab: bool
Return whether we’re running in Colab.
- Returns:
True if running in Colab, False otherwise
- Return type:
bool
- setup_environment() None
Set up the environment by installing dependencies and fetching source files. Should be called before any other operations.