semantica.utils provides shared infrastructure used throughout Semantica:
  • Structured logging: setup_logging(), get_logger(), log_execution_time decorator
  • Validation helpers: validate_entity() and validate_config() return (bool, Optional[str]) without raising
  • Progress tracking: ProgressTracker class and track_progress() iterable wrapper with ETA
  • Typed exceptions: SemanticaError, ValidationError, ProcessingError, ConfigurationError, QualityError
Most users won’t call utils directly: it’s the shared foundation for all modules.

Exported Classes

What You Get

  • Logging — Structured logging with @log_execution_time decorator and quality metrics via environment variables.
  • Validationvalidate_entity and validate_config with a typed ValidationError carrying field and value context.
  • Progress Trackingtrack_progress wraps any iterable: auto-detects console vs Jupyter for the right renderer.
  • Helper Functionsclean_text, hash_data, safe_filename, and nested dict utilities used throughout the framework.
  • Exception HierarchySemanticaErrorValidationError, ProcessingError: typed exceptions for targeted recovery.
  • File Utilitiesread_json_file raises FileNotFoundError or json.JSONDecodeError on failure: no boilerplate try/except around JSON I/O.

Logging

1

Initialize logging at application startup

Call setup_logging(level="INFO") once at application startup. Without it, Semantica falls back to Python’s root logger, which may be silent or misconfigured. Call it before importing other Semantica modules to capture initialization messages.
2

Instrument expensive functions with the performance decorator

@log_execution_time is the performance decorator. Apply it to any function to automatically log its name, execution time, and success/failure. log_performance is a lower-level function for logging metrics you’ve already collected: it is not a decorator.
3

Configure via environment variables

Validation

Progress Tracking

Supports:
  • Console: tqdm progress bar with ETA
  • Jupyter: notebook-compatible widget (auto-detected)
  • File: write progress to a log file
track_progress auto-detects Jupyter. In a terminal it renders a tqdm progress bar; in a Jupyter notebook it renders an interactive widget. You don’t need to check the environment: the same call works in both.

Helper Functions

hash_data() is deterministic across runs. Given the same input dict (any JSON-serializable object), hash_data() always returns the same SHA-256 hex string: suitable as a cache key or idempotency token in pipeline steps.

Nested Dict Utilities

Helper functions for deep configuration access: used extensively inside Config and ConfigManager:

Exception Hierarchy

Catch SemanticaError as the broadest exception net. All framework errors inherit from SemanticaError, so except SemanticaError catches validation failures, processing errors, and everything in between. Use specific subclasses for targeted recovery logic.

File Utilities

  • Core — Framework orchestration that uses Utils internally.
  • Pipeline — Uses ProgressTracker for per-step tracking.