The simplest interface for working with configuration files
Project description
dataclassconfig
Installation
pip install dataclassconfig
Usage
Describe the structure of your config file like a dataclass
and inherit it from Сonfig
For example:
from dataclassconfig import Config
class Socket(Config):
host: str
port: int
class DatabaseConnection(Socket):
database: str
username: str
password: str
class ServerConfig(Config):
root: str
db: DatabaseConnection
Create a configuration file according to the described structure in YML or JSON format
For example:
# server-config.yml
root: ~/server
db:
host: localhost
port: 1234
database: database
username: demouser
password: demopassword
# server-config.json
{
"root": "~/server",
"db": {
"host": "localhost",
"port": 1234,
"database": "database",
"username": "demouser",
"password": "demopassword",
},
}
Load the config file using your class.
config = ServerConfig.load("server-config.yml")
or
config = ServerConfig.load("server-config.json")
The load
method will check the completeness of the provided data in the configuration file and strictly match the data types. The result will be the same in both cases, the config object contains fields defined in the class
config :- ServerConfig(
root='~/server',
db=DatabaseConnection(
host='localhost',
port=1234,
database='database',
username='demouser',
password='demopassword'
)
)
config.db.username :- 'demouser'
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
dataclassconfig-0.0.1.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for dataclassconfig-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c77c79a4ab1fceb45d1a6fb6674edb4f27e4d9a3b58f6d7ae1649dd476876eb |
|
MD5 | 19413a0bc291107dd37f391dd6de4b27 |
|
BLAKE2b-256 | 256a76d348f6855b2b8015e81c153a17f18adc9394455a6688c29d8cf415e018 |