pyenvprops 0.4.4
define and set application properties using a file and enviornment variables
Requires Python: >=3.6,<4.0

#  pyenvprops

[![PyPI version](https://img.shields.io/pypi/v/pyenvprops)](https://pypi.org/project/pyenvprops/)
[![Python Versions](https://img.shields.io/pypi/pyversions/pyenvprops)](https://pypi.org/project/pyenvprops/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![](https://github.com/smithk86/pyenvprops/workflows/pytest/badge.svg)](https://github.com/smithk86/pyenvprops/actions?query=workflow%3Apytest)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

## Description

This module offers the ability to define and set application properties using both a property file and enviornment variables. It was originally intended to ease application configuration for apps running in Docker containers.

The property file can be formatted in JSON, TOML, or YAML. A `properties` object is defined in the file. Each entry should be an object with at least a `type` field. The supported types are defined in `envprops.Parsers`. EnvProps inherits `collections.abc.Mapping` so the final values can be accessed like a dictionary.

## Property Definition

* type: str (required)
* required: bool (default = true)
* sensitive: boot (default = false)
* default: Any (default = None)

## Property Redaction

EnvProps saves all the parsed property data to `EnvProps().properties` as `envprops.Property` objects. These normally stay behind the scenes but can be accessed directly. `Property().redact()` will return either itself when `sensitive is False` or an `envprops.RedactedProperty` object when `sensitive is True`. Using `redact()` will ensure sensitive information is hidden when printing or logging the available properties.

## Property File Examples

* JSON: [properties.json](https://github.com/smithk86/pyenvprops/blob/main/test/files/properties.json)
* TOML: [properties.toml](https://github.com/smithk86/pyenvprops/blob/main/test/files/properties.toml)
* YAML: [properties.yaml](https://github.com/smithk86/pyenvprops/blob/main/test/files/properties.yaml)
* pyproject.toml: [pyproject.toml](https://github.com/smithk86/pyenvprops/blob/main/pyproject.toml)

## Using with Flask/Quart

`EnvProps().init_app()` will load all property values into a
Flask or Quart application and will be accessible via `app.config`.

```python
from envprops import EnvProps
from flask import Flask

app = Flask(__name__)
eprops = EnvProps("properties.json")
eprops.init_app(app)
```

## Change Log

### [0.4.4] - 2022-04-21
- toml parsing is done with tomllib in Python 3.11 and up

### [0.4.3] - 2022-03-31
- property definitions can now be defined in [pyproject.toml](https://github.com/smithk86/pyenvprops/blob/main/pyproject.toml)
- fixed issue when yaml support is disabled

### [0.4.1] - 2022-03-30

- [Poetry](https://python-poetry.org/) is used as the build system
- .py files are now formatted with [Black](https://pypi.org/project/black/)
- [pathlib](https://docs.python.org/3/library/pathlib.html) is now used to manage file operations
- support has been added for [toml](https://pypi.org/project/toml/)