scitex.config API Reference
scitex-config — configuration helpers (YAML + dotenv) — standalone.
Two distinct API surfaces:
Public (top-level scitex_config.*) — convention-free generic
primitives usable by any Python project:
PriorityConfig— direct → config_dict → env → default cascadeScitexConfig,get_config,load_yaml— YAML-based configScitexPaths,get_paths— centralized path managerload_dotenv,get_scitex_dir— utilitiesparse_src_file,load_env_from_path,load_scitex_env— bash-style.src/.envparsing (canonical line/value parser;load_dotenvdelegates)
SciTeX-ecosystem internals (scitex_config._ecosystem.*) — helpers
that embed SciTeX conventions (pkg-short naming, project-scope walk to
.git/, _skills/<pkg>/ layout, SCITEX_<MODULE>_* env prefix).
For scitex-* package authors only; not a stable public API:
from scitex_config._ecosystem import local_state, env_registry
- Priority Order (same for
PriorityConfigandScitexConfig): direct → config (YAML/dict) → env → default
- Usage:
from scitex_config import ScitexConfig, ScitexPaths, get_config, get_paths
# YAML-based configuration (Scholar pattern) config = get_config() log_level = config.resolve(“logging.level”, default=”INFO”)
# Centralized path manager paths = get_paths() print(paths.logs) # ~/.scitex/logs print(paths.cache) # ~/.scitex/cache
# Use resolve() pattern in modules cache_dir = paths.resolve(“cache”, user_provided_path)
- class scitex.config.ScitexConfig(config_path=None, env_prefix='SCITEX_')[source]
Bases:
objectYAML-based configuration manager for SciTeX.
Loads configuration from YAML files with environment variable substitution. Values can be resolved with priority: direct → config → env → default.
Examples
>>> from scitex.config import ScitexConfig >>> config = ScitexConfig() >>> config.resolve("logging.level", default="INFO") 'INFO' >>> config.get("debug.enabled") False
- get(key, default=None)[source]
Get value from config directly (no precedence resolution).
Supports dot notation for nested keys.
- Parameters:
key (str) – Configuration key (e.g., “logging.level” or “debug.enabled”)
default (Any) – Default value if key not found
- Returns:
Configuration value
- Return type:
Any
- resolve(key, direct_val=None, default=None, type=<class 'str'>)[source]
Resolve value with precedence: direct → config → env → default.
This follows the Scholar module’s CascadeConfig pattern where YAML config takes higher priority than environment variables.
- Parameters:
key (str) – Configuration key (e.g., “logging.level”)
direct_val (Any) – Direct value (highest precedence)
default (Any) – Default value (lowest precedence)
type (Type) – Type conversion (str, int, float, bool, list)
- Returns:
Resolved value
- Return type:
Any
- scitex.config.get_config(config_path=None)[source]
Get ScitexConfig instance.
- Parameters:
config_path (str or Path, optional) – Path to custom config. If None, returns cached default instance.
- Returns:
Configuration instance
- Return type:
- scitex.config.load_yaml(path)[source]
Load YAML file with environment variable substitution.
Supports ${VAR:-default} syntax for environment variable expansion.
- Parameters:
path (Path) – Path to YAML file
- Returns:
Parsed YAML with environment variables substituted
- Return type:
- class scitex.config.ScitexPaths(base_dir=None)[source]
Bases:
objectCentralized path manager for SciTeX directories.
All paths are derived from SCITEX_DIR (default: ~/.scitex). Priority: direct_val → SCITEX_DIR env → .env file → default
- Directory Structure:
$SCITEX_DIR/ ├── browser/ # Browser profiles and data │ ├── screenshots/ # Browser debugging screenshots │ ├── sessions/ # Shared browser sessions │ └── persistent/ # Persistent browser profiles ├── cache/ # General cache │ └── functions/ # Function cache (joblib) ├── capture/ # Screen captures ├── impact_factor_cache/ # Impact factor data cache ├── logs/ # Log files ├── openathens_cache/ # OpenAthens auth cache ├── rng/ # Random number generator state ├── scholar/ # Scholar module data │ ├── cache/ # Scholar-specific cache │ └── library/ # PDF library ├── screenshots/ # General screenshots ├── test_monitor/ # Test monitoring screenshots └── writer/ # Writer module data
- __init__(base_dir=None)[source]
Initialize ScitexPaths.
- Parameters:
base_dir (str, optional) – Explicit base directory. If None, uses SCITEX_DIR env var or falls back to ~/.scitex.
- resolve(path_name, direct_val=None)[source]
Resolve a path with priority: direct_val → default from SCITEX_DIR.
This is the recommended method for modules that accept optional path parameters. It follows the same pattern as PriorityConfig.resolve().
- Parameters:
- Returns:
Resolved path
- Return type:
Path
Examples
>>> paths = ScitexPaths() >>> # User didn't provide path -> use default >>> cache_dir = paths.resolve("cache", None) >>> # User provided custom path -> use it >>> cache_dir = paths.resolve("cache", "/custom/cache")
Usage in modules: >>> class MyModule: … def __init__(self, cache_dir=None): … self.cache_dir = get_paths().resolve(“cache”, cache_dir)
- scitex.config.get_paths(base_dir=None)[source]
Get ScitexPaths instance.
- Parameters:
base_dir (str, optional) – Explicit base directory. If None, returns cached default instance.
- Returns:
Path manager instance.
- Return type:
- class scitex.config.PriorityConfig(config_dict=None, env_prefix='', auto_uppercase=True)[source]
Bases:
objectUniversal config resolver with precedence: direct → config_dict → env → default
Config dict (from YAML or passed dict) takes priority over env variables. This follows the Scholar module’s CascadeConfig pattern.
Examples
>>> from scitex_config import PriorityConfig >>> config = PriorityConfig(config_dict={"port": 3000}, env_prefix="SCITEX_") >>> port = config.resolve("port", None, default=8000, type=int) 3000 # from config_dict (highest after direct) >>> # With env: SCITEX_PORT=5000 python script.py >>> port = config.resolve("port", None, default=8000, type=int) 3000 # config_dict takes precedence over env >>> port = config.resolve("port", 9000, default=8000, type=int) 9000 # direct value takes highest precedence
- SENSITIVE_EXPRESSIONS = ['API', 'PASSWORD', 'SECRET', 'TOKEN', 'KEY', 'PASS', 'AUTH', 'CREDENTIAL', 'PRIVATE', 'CERT']
- resolve(key, direct_val=None, default=None, type=<class 'str'>, mask=None)[source]
Get value with precedence hierarchy.
Precedence: direct → config_dict → env → default
This follows the Scholar module’s CascadeConfig pattern where config dict takes higher priority than environment variables.
- Parameters:
- Returns:
Resolved configuration value
- Return type:
Any
- scitex.config.get_scitex_dir(direct_val=None)[source]
Get SCITEX_DIR with priority: direct → env → default.
This is a convenience function for the most common use case.
- Parameters:
direct_val (str, optional) – Direct value (highest precedence)
- Returns:
Resolved SCITEX_DIR path
- Return type:
Path
- scitex.config.load_dotenv(dotenv_path=None, *, walk_up=False, stop_at=None)[source]
Load environment variables from .env file(s).
- Default behavior (
walk_up=False, backward compatible): Searches for .env file in the following order, loading the first match: 1. Explicit
dotenv_pathif provided 2. Current working directory (cwd/.env) 3. User home directory ($HOME/.env)- Parent-walking behavior (
walk_up=True, opt-in): Walks parent directories starting from
cwd, looking for.envat each level. Stops when reachingstop_at(or$HOMEif not given) or the filesystem root. All.envfiles found are loaded, with the most-distant parent loaded first so that closer-to-cwd values take precedence (closer .env wins). An existing process env var is never overridden by any .env (process env > closest .env > … > root .env).Note:
walk_up=Trueis ignored ifdotenv_pathis explicitly given.
- Parameters:
dotenv_path (str, optional) – Path to .env file. If None, searches default locations.
walk_up (bool, optional) – If True (and
dotenv_pathnot given), walk parent dirs from cwd. Default False for backward compatibility — new callers should pass True.stop_at (str or Path, optional) – Directory at which to stop the upward walk (inclusive — its
.envis considered). If None, stops at$HOME(or filesystem root if$HOMEis not a parent of cwd). Only used whenwalk_up=True.
- Returns:
True if at least one .env file was found and loaded, False otherwise.
- Return type:
- Default behavior (
- scitex.config.parse_src_file(filepath)[source]
Parse a bash-compatible
.src/.envfile and extract env variables.- Parameters:
filepath (Path) – Path to the file.
- Returns:
Dictionary of variable names to values.
- Return type: