ConfigModel
ConfigModel is a Python package that allows you create a config for your project quickly and easily.
- ?:
But why should I use ConfigModel instead of just using configparser?
ConfigModel offers several key advantages over the standard configparser:
Intellisense bonus: Your IDE will be able to autocomplete your config parameters, since they are defined as class attributes.
Structured Configuration: Define configurations as nested Python classes, allowing for clear, hierarchical organization.
Default Values: Specify default values within class definitions, ensuring consistency and allowing to generate “distro” configs.
Automatic File Generation: Automatically generate configuration files from class definitions, saving time and reducing manual errors.
Example
Here is a quick example of how to use ConfigModel.
First, define a config for your app:
from configmodel import ConfigModel, config_file, nested_field
# ============================
# define a config for your app
# ============================
@config_file("config.ini")
class AppConfig(ConfigModel):
color_scheme = "dark"
font_size = 12
class AccountInfo(ConfigModel):
username = "guest"
password = ""
last_login = ""
class GoogleApi(ConfigModel):
client_id = "<put your client id here>"
secret = "<put your secret here>"
photos_api = GoogleApi()
maps_api = GoogleApi()
Then, use your config:
# ============================
# use your config
# ============================
def main():
# get config parameter
print(AppConfig.AccountInfo.username)
# set config parameters
AppConfig.AccountInfo.last_login = "2024-01-01"
AppConfig.photos_api.client_id = "1234"
AppConfig.maps_api.client_id = "5678"
It will create a config file config.ini with the following content:
[Global]
color_scheme = dark
font_size = 12
[account_info]
username = guest
password =
last_login = 2024-01-01
[photos_api]
client_id = 1234
secret = <put your secret here>
[maps_api]
client_id = 5678
secret = <put your secret here>
Note that
You can specify config file name with @config_file decorator.
Section names ([account_password]) of nested classes are automatically generated from class names, if no instances of this class are created.
You can reuse nested classes (GoogleApi) in different places of your config.
Installation
You can install ConfigModel using pip:
pip install ConfigModel
Metadata
Release files for ConfigModel 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| configmodel-0.2.1.tar.gz | 32.9 kB | Without provenance | Details for configmodel-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ConfigModel-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for ConfigModel-0.2.1-py3-none-any.whl |
Total release size: 45.9 kB
Release files / configmodel-0.2.1.tar.gz
| Download URL | configmodel-0.2.1.tar.gz |
|---|---|
| Size | 32.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d26d8baf0d4af6980f23f2e86ea56cac0dfaeef120d0c339a2a307bc12e338b4
|
|
BLAKE2b-256 checksum How to use checksums |
194741cf0556c774f07c3daf508c84db8848dc763f3f72ef6cb7f703c08cf93d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / ConfigModel-0.2.1-py3-none-any.whl
| Download URL | ConfigModel-0.2.1-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6202aac405c07f503b8f597e1ab55307f73802f2c7c18d6188d897c29dfa1e85
|
|
BLAKE2b-256 checksum How to use checksums |
50fa86259409121a269c5ab9fde4d5f6d9d93c88051fb3af9bb061cd753d302b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for ConfigModel 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.