Application Properties

0.9.2 · active · verified Sat Apr 11

Application-properties is a Python library (current version 0.9.2) that provides a simple, unified manner of accessing program properties. It supports loading configuration from various formats including JSON, TOML, YAML, JSON5, and traditional .properties files. The library emphasizes ease of use, testability, extensibility, and hierarchical property access, releasing frequently with new features and fixes.

Warnings

Install

Imports

Quickstart

Demonstrates how to load properties from a simple `.properties` file and access values. The example creates a temporary `config.properties` file and cleans it up afterwards.

import os
from application_properties import ApplicationProperties

# Create a dummy config file for demonstration
config_content = """
my.setting = some_value
another.setting = 123
"""
with open("config.properties", "w") as f:
    f.write(config_content)

try:
    # Load properties from a file named config.properties
    app_props = ApplicationProperties("config.properties")

    # Access a property
    value = app_props.get_string_property("my.setting")
    print(f"Value of 'my.setting': {value}")

    # Access a property with a default value if not found
    not_found_value = app_props.get_string_property("non.existent", "default_value")
    print(f"Value of 'non.existent' (with default): {not_found_value}")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists("config.properties"):
        os.remove("config.properties")

view raw JSON →