Skip to main content

Execution-context detection (script vs Jupyter vs IPython) + stdout/stderr suppression — standalone module from the SciTeX ecosystem

Project description

scitex-context

SciTeX

Execution-context detection (script vs Jupyter vs IPython) and output suppression helpers.

Full Documentation · uv pip install scitex-context[all]

PyPI Python Tests Coverage Docs License: AGPL v3


Installation

pip install scitex-context

Architecture

scitex_context/
├── __init__.py                 ← Public API (env detection + suppress helpers)
├── _detect_environment.py      ← script / notebook / ipython detector
├── _get_notebook_path.py       ← Jupyter notebook path & metadata helpers
└── _suppress_output.py         ← suppress_output() / quiet() context managers

Pure-stdlib, zero-dep helpers. The umbrella scitex.context import path is preserved via a sys.modules-alias bridge installed at import time.

Quick Start

import scitex_context as ctx

if ctx.is_notebook():
    print("Running inside Jupyter")

with ctx.suppress_output():
    noisy_function()

1 Interfaces

Python API
import scitex_context as ctx

# Environment detection
ctx.detect_environment()       # "script" | "notebook" | "ipython"
ctx.is_script()                # True if running under `python foo.py`
ctx.is_notebook()              # True under Jupyter
ctx.is_ipython()               # True under bare IPython
ctx.get_output_directory()     # Conventional output dir for current context

# Notebook helpers (no-op outside a notebook)
ctx.get_notebook_path()
ctx.get_notebook_directory()
ctx.get_notebook_name()
ctx.get_notebook_info_simple()

# Output suppression
with ctx.suppress_output():
    noisy_function()

with ctx.quiet():               # alias
    chatty_lib_call()

Demo

flowchart LR
    A["import scitex_context as ctx"] --> B{ctx.detect_environment()}
    B -- "python foo.py" --> S["script"]
    B -- "jupyter" --> N["notebook"]
    B -- "ipython REPL" --> I["ipython"]
    S & N & I --> O["ctx.get_output_directory()"]
    N --> P["ctx.get_notebook_path()"]
    A --> Q["with ctx.suppress_output():<br/>    noisy_call()"]

Status

Standalone fork of scitex.context. Pure stdlib — zero deps. The umbrella package's scitex.context import path is preserved via a sys.modules-alias bridge.

Part of SciTeX

scitex-context is part of SciTeX. Install via the umbrella with pip install scitex[context] to use as scitex.context (Python) or scitex context ... (CLI).

Four Freedoms for Research

  1. The freedom to run your research anywhere — your machine, your terms.
  2. The freedom to study how every step works — from raw data to final manuscript.
  3. The freedom to redistribute your workflows, not just your papers.
  4. The freedom to modify any module and share improvements with the community.

AGPL-3.0 — because we believe research infrastructure deserves the same freedoms as the software it runs on.

License

AGPL-3.0-only (see LICENSE).


SciTeX

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

scitex_context-0.1.4.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

scitex_context-0.1.4-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file scitex_context-0.1.4.tar.gz.

File metadata

  • Download URL: scitex_context-0.1.4.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_context-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ca2fe094e32fb1cf045bab5dfc72aa7c47d97fdd97d7085b14fdf795506579f0
MD5 73eeef601bff33a7b24b744acea113c2
BLAKE2b-256 090d59ca4bbc75249bc67eadeb903d40364225ef9eccff82f1c57eaba6a06f97

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_context-0.1.4.tar.gz:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-context

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

File details

Details for the file scitex_context-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: scitex_context-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_context-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c65ba27b97df31eb34990c5e8a7895257d43183e90f15e3cfa163d8198e2c8de
MD5 eb6bfc32d37239289d3ddfbf1f935947
BLAKE2b-256 15ad4912bc8777bd31254bdc7e221ec406112937ef60695c7814d7ff93af43fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_context-0.1.4-py3-none-any.whl:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-context

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