Skip to main content

Java application properties for Python

Project description

Python Application Properties

PyPI - Python Version PyPI - Package Version PyPI - License Build Status Coverage Status Code style: black Checked with mypy Imports: isort

What is this

This is a simple library to inject non-sensitive configurations into class variables.

How to install

To install this library just enter:

pip install py-app-properties

How To Use

The main purpose of this library is to simplify work with an application config. Using decorator @properties with all required params and type hinting you can inject required settings from *.yml or *.json formats.

Example:

# my_app_properties.yml
my_class:
  int_var: 10
  list_int_var:
    - 12
    - 14
  dict_with_list_var:
    key1:
      - val1
      - val2
    key2:
      - val3
      - val4
  bool_var: true
from app_properties import properties

@properties(filename="my_app_properties.yml", root="my_class")
class MyClass:
    int_var: int
    list_int_var: list[int]
    dict_with_list_var: dict[str, list[str]]
    bool_var: bool
    
    def __init__(self, param1: int, param2: str) -> None:
        self._param1 = param1
        self._param2 = param2
    
    def some_method(self) -> None:
        ...  # using class variables and instance variables here

About params:

  • filename - the name of a file with config. By default, it is application.yml which is located in the same directory as a file with a used decorator. Use a relative path with ../ to read the file from a parent directory.
  • type_cast - used to know whether you want to cast config values to field type. By default, it's True, which means values in a config file will be cast according to the type hints. If False, type hinting is ignored, and available types are limited by a file format - only list, dict, int, str, float, bool, and none are available. If True - set, frozenset, tuple, NamedTuple, TypedDict, and dataclass will be available additionally to types above. Also nested types will be recursively cast.
  • override_default - used to know whether you want to override default values of class variables. By default, it is False.
  • root - root key in the config. Could be a nested value with separation by dots, for example:
# example.yml
some:
  nested:
    config:
      key: value
@properties(filename="example.yml", root="some.nested.config")
class MyClass:
    key: str

About contributing

You will make this library better if you open issues or create pull requests with improvements.

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

py-app-properties-1.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

py_app_properties-1.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file py-app-properties-1.1.0.tar.gz.

File metadata

  • Download URL: py-app-properties-1.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for py-app-properties-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3dbe0211ec5694ce5fce7c66679695fe3a7671057d43c67f9980e49f77bc7dc6
MD5 40335328305e21cdac04f52b43d74f37
BLAKE2b-256 749e4cfb446e6df81f1ba17826991eec82e656f12a6c56b21f1d68c646f8716e

See more details on using hashes here.

File details

Details for the file py_app_properties-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_app_properties-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81a6a7124cc585b87cbeeff1fcf4513bf1130e832f4679e7654b04cf97611c0b
MD5 ae466caba97a9c997969ce0695a6fe9b
BLAKE2b-256 94c83aec0f10dd88e7cca13359b630a65361b0131ea8db2d5c15e0189af1b469

See more details on using hashes here.

Supported by

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