Describe config, i'll create it
Project description
Hello, config!
So, what's the plan?
- You are describing config as dataclass
- I'm making sample file with needed fields
- You're filling them in
- ???????
- App is good to go
What's was not mentioned:
nested fields supported cherez zhopu (are not supported)
cause it's too complicated for me, i'll try to do it again later
you can try nested fields, but updating existing config will not work
also there is some problem (idfk what) with dataclass fields
defined as class variables (not annotations)
About
Available on PyPI, so can be installed with pip install helloconfig
Supports Python, YAML, JSON and .env configuration files
Main feature (and why i made this library) is creating config file if it's not exists. If config class was updated and existing config misses any field, file will be updated with fields needed.
Data loaded with dataclass-factory library,
so also value validation should be supported, but this require additional meta programming,
which... i also will do later.
(unfortunately, DF didn't support validators in
dataclasses by design, so it's not ready out of the box)
Usage
On first run last line will raise helloconfig.FieldsMissing
exception
and create file with zero (or default, if specified in class) values.
from helloconfig import PythonConfig
class Config(PythonConfig):
host: str
port: int = 8080
config = Config.from_file('config.pyi')
About formats
PythonConfig
, YamlConfig
, DotEnvConfig
preserve existing comments when updating fields.
(new fields are appending to the end of file)
JsonConfig
does not support comments, and even order of fields
may change.
what is nested fields
class Config(PythonConfig):
a: str
class some_field:
nested_field: int
it will result in following python file
a = ''
class some_field:
nested_field = 0
and only PythonConfig tested such way, other types don't know anything about nesting
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 helloconfig-0.1.0.post1.tar.gz
.
File metadata
- Download URL: helloconfig-0.1.0.post1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.27.1 setuptools/60.5.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcfe03dffab63ca870bb635d15ebf15544a9e7bd977f3c3b441a82290b90b332 |
|
MD5 | a0dfff05e19807f58bd03d89af24b35b |
|
BLAKE2b-256 | c7178b5ef017e8cb8d69dcb248ac14dbbc6fd1ce6e7878dff9994440f158c4a3 |
File details
Details for the file helloconfig-0.1.0.post1-py3-none-any.whl
.
File metadata
- Download URL: helloconfig-0.1.0.post1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.27.1 setuptools/60.5.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfe265a6f22df4b6c31477abfb94f82d66455d698a881b76eaae0d2d206d75f5 |
|
MD5 | 7c3b6677cd808ea02def15cfaafe9523 |
|
BLAKE2b-256 | e47f4666ed3c55d23a3c1818f259d8054b7119888cd52ac73793440fb2e22788 |