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.3.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.3-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scitex_context-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 c30b78fa4e354dd060e7fc6f4d3f76f1f5b2c64e42a065301be1229a10617e63
MD5 994a07194d6f7b16ddef573975720487
BLAKE2b-256 9c33586887b6f8172deb59e0b4653d773c6e308579f60be33832e84a494f29ed

See more details on using hashes here.

Provenance

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

Publisher: publish-pypi.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.3-py3-none-any.whl.

File metadata

  • Download URL: scitex_context-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3ad5bdf4f7220f303d2e856324271e537bba0cbe09775a0ca24a91231faee5d9
MD5 0c541c33b28957cc57848022a0b77f38
BLAKE2b-256 c53957c0f48f2eaa7a4388c1b57a45d2352a76bd87e1a11443ac1633e2dd1066

See more details on using hashes here.

Provenance

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

Publisher: publish-pypi.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