Plaster

1.1.2 · active · verified Sat Apr 11

Plaster is a loader interface designed to abstract away multiple configuration file formats. It provides a common API for applications to load settings, supporting pluggable loaders discovered via entrypoints. The library focuses on providing a basic interface, leaving specific constraints and implementations to these pluggable loaders. The current version is 1.1.2, released in November 2022, and it is actively maintained by the Pylons Project.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load configuration settings from a URI and configure standard logging using `plaster.get_settings()` and `plaster.setup_logging()`. It shows how to specify a configuration file (like 'development.ini') and a specific section ('myapp') to retrieve settings. To run this, you would typically need a loader plugin (e.g., `pip install plaster_pastedeploy`) and a corresponding config file.

import plaster
import sys

# Example config_uri. In a real app, this might come from command line args or an environment variable.
# For demonstration, we'll use a placeholder. Replace 'development.ini#myapp' with your actual config URI.
# You might need a loader like 'plaster_pastedeploy' installed for .ini files.
config_uri = 'development.ini#myapp'

try:
    # Load settings for a specific section (e.g., 'myapp')
    settings = plaster.get_settings(config_uri, section='myapp')
    print("Loaded settings:", settings)

    # Optionally configure logging based on the config file
    plaster.setup_logging(config_uri)
    print("Logging configured.")

    # Example: Accessing a specific setting
    if 'my_setting_key' in settings:
        print(f"Value of 'my_setting_key': {settings['my_setting_key']}")
    else:
        print("No 'my_setting_key' found in settings.")

except plaster.LoaderNotFound:
    print(f"Error: No loader found for URI '{config_uri}'. Make sure the appropriate plaster plugin (e.g., plaster_pastedeploy) is installed.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →