Skip to main content

The library for creating nested environ configuration through composition

Project description

environ composition

The library for parsing environ configuration and creating nested configuration classes through composition.

  • EnvConfigParser is designed to parse environment variables and a .env file to create a structured configuration.
  • EnvConfig takes the parsed environment variables (a dictionary) and creates an object with attributes matching the keys.

Installation

pip install environ-composition

Import

from environ_composition import EnvConfigParser

Usage

config = EnvConfigParser(dotenv_path='path_to/.env', separator='__').parse()

In EnvConfigParser each environment variable name goes into a lowercase attribute of EnvConfig instance.

Adding some separator (i.g. double underscores "__") to the variable name adds a level of nesting to the config.

VAR1=value1
VAR2__NESTED_VAR1=nested_value1
config.var1 = "value1" 
config.var2.nested_var1 = "nested_value1"

When specifying a template, the parser updates the values in the template.

Without a template, the parser returns the config in EnvConfig instance.

class NestedTemplate:
    def __init__(self):
        self.nested_var1 = None

class Template:
    def __init__(self):
        self.var1 = None
        self.var2 = NestedTemplate()

template = Template()

parser = EnvConfigParser('path_to/.env')

config = parser.parse(template)

The structure and nesting levels of the template must match the names in the environment variable.

Mismatched names of attributes and private attributes in the template are not updated.

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

environ_composition-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

environ_composition-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file environ_composition-1.0.0.tar.gz.

File metadata

  • Download URL: environ_composition-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for environ_composition-1.0.0.tar.gz
Algorithm Hash digest
SHA256 781c2b4daf2e2e961961f693929ebf8ca1ab8adeafe32564ceef0a6f8bd7c41a
MD5 ffc289e5531509e82e411f964ec1178e
BLAKE2b-256 27e4fff87d8c556f4de39a6d82565c14d950cbc82a0a98ca5ded911b0610a763

See more details on using hashes here.

File details

Details for the file environ_composition-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for environ_composition-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e4d9fce981d5c39102c5b2640485d449f43dc9cd86932062ffd91927c8a4854
MD5 0542ef5523b00047c72b91e62dd5642a
BLAKE2b-256 2afcc3d3645b3fdb38cbc9277c92eebe9a77ef579f35251c077bdfad764f9b88

See more details on using hashes here.

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