Skip to main content

This general purpose configuration utility library allows your code to use YAML as a configuration language for internal and external parties, allowing configuration to be crafted from multiple sources and merged just before use, using YAML Tags for additional functionality.

Project description

granular-configuration-language – A General Purpose Configuration Utility Library

Coverage badge Testing workflow codeql workflow
pypi pypi pypi pypi

⚠️ This library is meant for trusted configuration files. ⚠️

How to get started?

See Documentation - Getting Started.

How to install?

From PyPI:

pip install granular-configuration-language

Why does this exist?

This library exists to allow your code to use YAML as a configuration language for internal and external parties, allowing configuration to be crafted from multiple sources and merged just before use, using YAML Tags for additional functionality, and plugin support for creating custom YAML Tags.

Some use cases:

  • You are writing a library to help connect to some databases. You want users to easily changes settings and defined databases by name.
    • Conceptual Example:
      • Library Code:
        # database_util/config/config.py
        CONFIG = LazyLoadConfiguration(
            Path(__file___).parent / "config.yaml",
            "./database-util-config.yaml",
            "~/configs/database-util-config.yaml",
            base_path="database-util",
            env_location_var_name="ORG_COMMON_CONFIG_LOCATIONS",
        )
        
      • Library configuration:
        # database_util/config/config.yaml
        database-util:
          common_settings:
            use_decimal: true
            encryption_type: secure
          databases: {} # Empty mapping, for users define
        
      • User application configuration:
        # ~/configs/database-util-config.yaml
        database-util:
          common_settings:
            use_decimal: false
          databases:
            datebase1:
              location: http://somewhere
              user: !Mask ${DB_USERNAME}
              password: !Mask ${DB_PASSWORD}
        
      • Library Code with type annotations:
        class CommonSettings(Configuration):
            use_decimal: bool
            encryption_type: str
        #
        class DatabaseSettings:
            location: str
            user: str
            password: str
        #
        class Settings(Configuration):
            common_settings: CommonSettings
            databases: Configuration[str, DatabaseSettings]
        #
        CONFIG = LazyLoadConfiguration(
            Path(__file___).parent / "config.yaml",
            "./database-util-config.yaml",
            "~/configs/database-util-config.yaml",
            base_path="database-util",
            env_location_var_name="ORG_COMMON_CONFIG_LOCATIONS",
        ).as_typed(Settings)
        
  • You are deploying an application that has multiple deployment types with specific settings.
    • Conceptual Example:
      • Library Code:
        # app/config/config.py
        CONFIG = LazyLoadConfiguration(
            Path(__file___).parent / "config.yaml",
            "./database-util-config.yaml",
            base_path="app",
        )
        
      • Base configuration:
        # app/config/config.yaml
        app:
          log_as: really cool app name
          log_to: nowhere
        
      • AWS Lambda deploy:
        # ./database-util-config.yaml
        app:
          log_to: std_out
        
      • Server deploy:
        # ./database-util-config.yaml
        app:
          log_to: !Sub file://var/log/${$.app.log_as}.log
        
  • You are writing a pytest plugin that creates test data using named fixtures configured by the user.
    • Conceptual Examples:
      • Library Code:
        # fixture_gen/config/config.py
        CONFIG = LazyLoadConfiguration(
            Path(__file___).parent / "fixture_config.yaml",
            *Path().rglob("fixture_config.yaml"),
            base_path="fixture-gen",
        ).config
        #
        for name, spec in CONFIG.fixtures:
            generate_fixture(name, spec)
        
      • Library configuration:
        # fixture_gen/config/fixture_config.yaml
        fixture-gen:
          fixtures: {} # Empty mapping, for users define
        
      • User application configuration:
        # fixture_config.yaml
        fixture-gen:
          fixtures:
            fixture1:
              api: does something
        

Why the long name?

  • It's "granular" because you can specify settings across multiple files at a fine granularity for overriding values.
  • It is meant for trusted "configuration" files.
  • Including "language" makes it clear that this is not the source of configuration, but a library for processing generic configuration files.
    • Feedback was that "granular-configuration" sounded like it was the source for configuration.
    • "Format" sounded weirder than "language".
    • Including "YAML" sounded like this was trying to be more than YAML, rather than just using YAML.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

granular_configuration_language-2.4.2.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

granular_configuration_language-2.4.2-py3-none-any.whl (69.9 kB view details)

Uploaded Python 3

File details

Details for the file granular_configuration_language-2.4.2.tar.gz.

File metadata

File hashes

Hashes for granular_configuration_language-2.4.2.tar.gz
Algorithm Hash digest
SHA256 7f1cc829cb66a55e1b9e3586e3dfe45aa5fff9a7f18d19676cedda642297508e
MD5 a56b38c5f6d4fe512296352e16085c03
BLAKE2b-256 48a72dfcbe601b1143c09eafc91fccfac3df670f68df3f70555599a9455730a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for granular_configuration_language-2.4.2.tar.gz:

Publisher: release.yaml on lifedox/granular-configuration-language

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file granular_configuration_language-2.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for granular_configuration_language-2.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 572573bc1b38023b3dcf6e1bc57a1e8c0179fc6a4cf14adac23f4a5b44ac8f1d
MD5 ea67d0333a82c531d90f6c5c4d07be60
BLAKE2b-256 6d78dde1a30c3f3bf405fd0c909f7d1d3b09443ae07f4f4bb65e134b19538e7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for granular_configuration_language-2.4.2-py3-none-any.whl:

Publisher: release.yaml on lifedox/granular-configuration-language

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page