Skip to main content

layered-settings

layered-settings is a simple and configurable hierarchical settings library for Python, including Django, Flask, or any other scripts that need settings from potentially a variety of sources. With it you can load settings from the environment, Amazon's SSM, Amazon's Secrets Manager, local configparser .ini files, and more.

Installation

The package is available on pip as layered-settings. Run:

pip install layered-settings

If you want to use the AWS SSM layer or Secrets Manager layer, include the [aws] extra:

pip install layered-settings[aws]

then import via:

from layered_settings import initialize_settings, loaders

Example Usage

import os
from layered_settings import initialize_settings
from layered_settings import loaders

get_setting = initialize_settings(
    sources=[
        # Lowest priority is setting-defaults.ini.  All configuration values should be defaulted in here.
        # The `loaders.ConfigParserLoader` is optional - if you pass a string ending in .ini, it wraps it in
        # a `loaders.ConfigParserLoader` for you.
        loaders.ConfigParserLoader(os.path.join(SCRIPT_DIR, "setting-defaults.ini")),

        # Next priority is a "user" settings file.
        os.path.expanduser("~/.app-settings.ini"),

        # You can include a dictionary in the sources too...
        {
            "general": {"CLIENT_NAME": "client"},
            "email": {"EMAIL_HOST": "smtp.example.com", "EMAIL_PORT": 25},
        },

        # Secrets Manager works similar to SSM. If the secret is a json object, the object's keys will be the layered setting "key"
        # If the secret is just plain text, the secret's name will be used as the key
        loaders.SecretsManagerLoader(f"/app/stage/", aws_region="us-east-1") if ALLOW_SSM_CONFIGURATION else None,

        # If we are able/willing to reach out to AWS, do so.  A `None` in the initialize_settings sources
        # will simply be ignored.
        loaders.SSMLoader(f"/app/stage/", aws_region="us-east-1") if ALLOW_SSM_CONFIGURATION else None,

        # Top priority -- env var in the format APP__section__key.
        loaders.EnvLoader("APP__{section}__{key}"),
    ]
)

DATABASE_HOST = get_setting("database", "DATABASE_HOST")
AWS_SECRET_KEY = get_setting("aws", "AWS_SECRET_KEY")
...

Frameworks Supported

This library is tested using Python 3.x.

Metadata

Release files for layered-settings 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for layered-settings 1.1.1
File Size Uploaded Provenance Actions
layered_settings-1.1.1.tar.gz 7.1 kB Without provenance Details for layered_settings-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for layered-settings 1.1.1
File Interpreter ABI Platform Actions
layered_settings-1.1.1-py3-none-any.whl Python 3 none any Details for layered_settings-1.1.1-py3-none-any.whl

Total release size: 16.8 kB

Release files / layered_settings-1.1.1.tar.gz

Download URL layered_settings-1.1.1.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8c63867ade4c4473e4c91db96b7c1a0065ee88907399e9575c8b42b6a9b4a95b
BLAKE2b-256 checksum
How to use checksums
9c873ed2e1c5fc9427051b4c12c98010876db6729d9a041524fb1fcfb0bf7b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / layered_settings-1.1.1-py3-none-any.whl

Download URL layered_settings-1.1.1-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
417b7053dc6ca2f82a0337f06214b53c072dd143be7ebe3bcd3bb1ae97727eb3
BLAKE2b-256 checksum
How to use checksums
b735a97726d5b0c9402a90b58c4b9627b1e25aa5efc3e6301a4f605abd0813df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for layered-settings 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page