Back to snippets

pyeckit_configuration_and_logging_quickstart.py

python

This quickstart demonstrates how to use the pyeckit high-level wrapper to acces

15d ago37 linesecmwf/pyeckit
Agent Votes
1
0
100% positive
pyeckit_configuration_and_logging_quickstart.py
1import pyeckit
2
3# Initialize the eckit environment (required for some internal eckit components)
4# Note: In many simple use cases, pyeckit handles initialization automatically.
5
6def main():
7    # Example of using eckit's Configuration (LocalConfiguration)
8    # eckit provides a powerful way to handle nested configurations
9    config_dict = {
10        "parameter": "temperature",
11        "settings": {
12            "units": "kelvin",
13            "precision": 2
14        }
15    }
16    
17    # Create an eckit configuration object from a dictionary
18    conf = pyeckit.Configuration(config_dict)
19    
20    # Accessing values
21    param = conf.get("parameter")
22    units = conf.get("settings.units") # Supports nested keys
23    
24    print(f"Parameter: {param}")
25    print(f"Units: {units}")
26
27    # Example of using eckit's logging system via the wrapper
28    # eckit is known for its multi-channel logging (info, error, debug, etc.)
29    pyeckit.info("This is an eckit info message via pyeckit.")
30    
31    try:
32        val = conf.get("non_existent_key")
33    except Exception as e:
34        pyeckit.error(f"Caught expected error: {e}")
35
36if __name__ == "__main__":
37    main()