DiracX Core Library
DiracX Core Library (diracx-core) provides foundational utilities, data structures, and base classes shared across the DiracX ecosystem. Currently at version 0.0.12, it's in early development, implying a rapid release cadence with potential for frequent API changes.
Warnings
- breaking As a pre-1.0 version library (currently 0.0.12), diracx-core's API is subject to frequent and significant breaking changes without prior deprecation warnings. Users should pin exact versions and regularly review the GitHub repository for updates.
- gotcha DiracX Core is primarily designed as a foundational library to be extended by other DiracX packages, not necessarily for standalone complex application development. While it provides utilities, its core strength lies in providing base classes and structures for a larger ecosystem.
- gotcha The `BaseConfig` class, being a Pydantic `BaseModel`, relies on specific mechanisms for configuration loading and overriding (e.g., environment variables, `.env` files, or explicit instantiation). Misunderstanding the priority or source of configuration values can lead to unexpected behavior.
Install
-
pip install diracx-core
Imports
- BaseConfig
from diracx_core.config import BaseConfig
- DiracXError
from diracx_core.errors import DiracXError
- LoggableMixin
from diracx_core.logger import LoggableMixin
Quickstart
import os
from diracx_core.config import BaseConfig
from pydantic import Field
class AppConfig(BaseConfig):
app_name: str = Field('MyDiracXApp', description='Name of the application')
api_key: str = Field(os.environ.get('DIRACX_API_KEY', ''), description='API Key for DiracX services')
debug_mode: bool = Field(False, description='Enable debug logging')
# Example usage
# Set an environment variable for testing, e.g., export DIRACX_API_KEY="your_secret"
config = AppConfig()
print(f"Application Name: {config.app_name}")
if config.api_key:
print("API Key loaded successfully.")
else:
print("Warning: DIRACX_API_KEY environment variable not set. API services might not work.")
if config.debug_mode:
print("Debug mode is ON.")