semantica.utils provides shared infrastructure used throughout Semantica:
- Structured logging:
setup_logging(),get_logger(),log_execution_timedecorator - Validation helpers:
validate_entity()andvalidate_config()return(bool, Optional[str])without raising - Progress tracking:
ProgressTrackerclass andtrack_progress()iterable wrapper with ETA - Typed exceptions:
SemanticaError,ValidationError,ProcessingError,ConfigurationError,QualityError
Exported Classes
What You Get
- Logging — Structured logging with
@log_execution_timedecorator and quality metrics via environment variables. - Validation —
validate_entityandvalidate_configwith a typedValidationErrorcarrying field and value context. - Progress Tracking —
track_progresswraps any iterable: auto-detects console vs Jupyter for the right renderer. - Helper Functions —
clean_text,hash_data,safe_filename, and nested dict utilities used throughout the framework. - Exception Hierarchy —
SemanticaError→ValidationError,ProcessingError: typed exceptions for targeted recovery. - File Utilities —
read_json_fileraisesFileNotFoundErrororjson.JSONDecodeErroron failure: no boilerplate try/except around JSON I/O.
Logging
1
Initialize logging at application startup
2
Instrument expensive functions with the performance decorator
3
Configure via environment variables
Validation
Progress Tracking
- Console: tqdm progress bar with ETA
- Jupyter: notebook-compatible widget (auto-detected)
- File: write progress to a log file
Helper Functions
Nested Dict Utilities
Helper functions for deep configuration access: used extensively insideConfig and ConfigManager:
Exception Hierarchy
Exception types and when they're raised
Exception types and when they're raised
