Java application properties for Python
Project description
Python Application Properties
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 isapplication.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'sTrue
, which means values in a config file will be cast according to the type hints. IfFalse
, type hinting is ignored, and available types are limited by a file format - onlylist
,dict
,int
,str
,float
,bool
, andnone
are available. IfTrue
-set
,frozenset
,tuple
,NamedTuple
,TypedDict
, anddataclass
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 isFalse
.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py-app-properties-1.0.0.tar.gz
.
File metadata
- Download URL: py-app-properties-1.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58fae192bcca7c173a91e54a1f886410f7cf024b87897e4323a8c561b3bf5779 |
|
MD5 | 7911964d93613554702c0959300b3ed9 |
|
BLAKE2b-256 | 95846599fb46cfac929ecb034ca64171b51ec26f58b86b2a2da8e522ff026f90 |
File details
Details for the file py_app_properties-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: py_app_properties-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ccc7352f5cf98b83c24522167c4bf9154e2a106b91b7681d7f4062ba480e2a9 |
|
MD5 | b6a4989db172caa52aeee010364d1755 |
|
BLAKE2b-256 | d46a5a8a003feadb4802374bc5a843c52dab4948f457a7292b466a0060a285c0 |