context Module (stx.context)
scitex-context — execution-context detection (script vs notebook vs IPython) + output suppression.
- scitex.context.detect_environment()[source]
Detect the current execution environment.
- Returns:
One of: ‘script’, ‘jupyter’, ‘ipython’, ‘interactive’, ‘unknown’
- Return type:
EnvironmentType
Examples
>>> env = detect_environment() >>> print(f"Running in: {env}") Running in: script
- scitex.context.get_notebook_directory()[source]
Get the directory containing the current notebook.
- Returns:
Directory path, or None if not in a notebook
- Return type:
Optional[str]
- scitex.context.get_notebook_info_simple()[source]
Simple method to get notebook info using current working directory.
- scitex.context.get_notebook_name()[source]
Get just the name of the current notebook (without path).
- Returns:
Notebook filename, or None if not in a notebook
- Return type:
Optional[str]
Examples
>>> name = get_notebook_name() >>> if name: ... print(f"Notebook: {name}")
- scitex.context.get_notebook_path()[source]
Get the full path of the current Jupyter notebook.
- Returns:
Full path to the notebook file, or None if not in a notebook
- Return type:
Optional[str]
Examples
>>> path = get_notebook_path() >>> if path: ... print(f"Running in notebook: {path}")
- scitex.context.get_output_directory(specified_path, env_type=None)[source]
Get the appropriate output directory based on environment.
- Parameters:
specified_path (str) – The path specified by the user
env_type (EnvironmentType, optional) – Override environment detection
- Returns:
(output_directory, should_use_temp)
- Return type:
Examples
>>> output_dir, use_temp = get_output_directory("data.csv") >>> print(f"Save to: {output_dir}, Temp: {use_temp}") Save to: ./script_out/data.csv, Temp: False
- scitex.context.is_ipython()[source]
Check if running in IPython (console or notebook).
- Return type:
- scitex.context.quiet(suppress=True)
A context manager that suppresses stdout and stderr.
Example
- with suppress_output():
print(“This will not be printed to the console.”)