Easy yaml based configuration for Python
Project description
EYConf
Easy yaml based configuration for Python
Features
- Generate: Automatically convert your schema to a yaml configuration file, including comments!
- Validate: Validate your a given configuration file against your schema and raise human readable errors!
- Extend: Introduce custom logic by extending the
EYConfclass! - Reload: Reload your configuration on the fly without restarting your application!
Installation
You can install EYConf from git directly using pip:
pip install git+https://github.com/semohr/eyconf.git
Quickstart
Define a configuration schema
from dataclasses import dataclass
from typing import Optional
@dataclass
class Transport:
"""Email transport configuration"""
host: str = 'imap.example.com'
port: int = 993
username: str = 'user'
password: str = 'password'
use_ssl: bool = False
@dataclass
class Other:
"""Other configuration options"""
bar: Optional[int]
@dataclass
class ConfigSchema:
"""My configuration schema
Docstrings are used as comments in the generated yaml file!
"""
transport: Transport
other: Other
We can now create a configuration using the EYConf class directly, if you need
more control it is also possible to extend the class.
# Using create_config_class helper function
from eyconf import EYConf
config = EYConf(ConfigSchema,'config.yaml')
This created the config.yaml file in your current working directory with the following content. Notice that the
docstrings are used as comments in the generated yaml file.
# My configuration schema
# Docstrings are used as comments in the generated yaml file!
transport:
# Email transport configuration
host: imap.example.com
port: 993
username: user
password: password
use_ssl: false
other:
# Other configuration options
bar: null
You can access your configuration directly as attributes of the config object.
assert type(config.transport) == Transport
assert config.transport.host == "imap.example.com"
If you want to change the configuration, you can do so by editing the config.yaml file directly and reloading the configuration.
...
transport:
host: changed.example.com
config.refresh()
assert config.transport.host == "changed.example.com"
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eyconf-0.0.1.tar.gz.
File metadata
- Download URL: eyconf-0.0.1.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d070c1b8fcf400971c0a977b6fd292d9b00897b3373a4f97ae2fa7de6570b9f
|
|
| MD5 |
d603addf23027fe9089d7bc5b237f71a
|
|
| BLAKE2b-256 |
987a39e5eb74778d17089e3bd28c8f3dda7a3876caf0fcbf155e4f94dc293c45
|
File details
Details for the file eyconf-0.0.1-py3-none-any.whl.
File metadata
- Download URL: eyconf-0.0.1-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddd9a572868880460173ba86c930ce2fb02e16b1e61f47ac91d01fadbdec563e
|
|
| MD5 |
3d2a4397a4563ae0c556fd5e14f785ad
|
|
| BLAKE2b-256 |
88939b6883e8588f0cb248cf045c5693167887455b6f4e93f16ad8b0b9fd36ff
|