Super easy access to configuration file, by pretty interface
Project description
ezconfig
is a Python library for easy formatting config file right from the terminal.
Press ENTER
and run your code, or change varialables right there!
ezconfig can also use different variable types, use different styles, and highlight mistakes, if there are any.
Installing
Requires Python 3.7 or later.
Install with pip or your favorite PyPI package manager.
pip install python-ezconfig
Get started with 2 lines of code
from ezconfig import EzConfig
ez = EzConfig("VAR1", "VAR2", ...)
ez.configure()
print(ez.config)
# {'VAR1': ..., 'VAR2': ...}
Advanced usage
If you want to set default value, or prevent the user from leaving the variable empty, or set value type (instance) - use KeyPrompt
from ezconfig import EzConfig, KeyPrompt
ez = EzConfig(
KeyPrompt("DELAY", value_type=float, default_value=5),
KeyPrompt("LINK", value_type=str, can_be_empty=False),
KeyPrompt("USE_PROXY", value_type=bool, can_be_empty=False),
KeyPrompt("USE_CACHE", value_type=bool, can_be_empty=False, default_value=False),
)
ez.configure()
If user will input string value in DELAY, then he will get this warning:
And it works with many other types, such as int
, bool
, float
, str
...
As well, if you pass argument can_be_empty=False
, the user will not be able to run your script without filling this field.
Then you can access this variables
print(ez.config['DELAY'])
# 28 # Note, you get a right types, int, not "28"
print(ez.config['USE_PROXY'])
# False
print(type(ez.config['USE_PROXY']))
# bool
Note: You always able to access configuration from config file as well
you can change this file by passing saving_json={file}
to EzConfig()
Documentation
class - ezconfig.EzConfig
Allows super easy access to configuration file
To user, using easy interface,
and to you, just by 'EzConfig.config' dictionary <3
Arguments:
*key_prompts (KeyPrompt | str), Prompts, to ask user for. Required.
saving_json (Path | str, optional): path to json file to save config into. Defaults to "config.json".
show_index (bool, optional): True/False to show numbers column for rows. Defaults to True.
show_lines (bool, optional): True/False to show separation horizontal lines. Defaults to False.
clean_console (bool, optional): True/False to clean up console between printing. Defaults to True.
title (str, optional): The title of the table rendered at the top.. Defaults to None.
caption (str, optional): The table caption rendered below.. Defaults to None.
headers (Union[str, str], optional): Column headers, example: ("Key", "Value"). Defaults to None.
box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.ROUNDED.
style (StyleType, optional): Default style for the table. Defaults to "bold white".
column_styles (Union[StyleType, StyleType], optional): Union of 2 row styles. Defaults to ("bold cyan", "bold green").
console (Console, optional): Optional <rich.console.Console> object, if you want to use your custom rich console. Defaults to None.
configure_text (str, optional): Text that shows up when the configure method is used. Defaults to None.
EzConfig class methods:
ezconfig.EzConfig.configure()
- Main method, prints configuration table and enables editing mode.
ezconfig.EzConfig.print_config()
- Just prints config table, nothing more.
class - ezconfig.KeyPrompt
Defines a key-value prompt for EzConfig.
Arguments:
key (str): Key name, must be str.
default_value (str, optional): Will be default value if there are no saved values. Defaults to None.
can_be_empty (bool, optional): True/False. Defaults to True.
value_type (ValueType, optional): Value will be passed instance. Defaults to str.
there is no methods for this class.
That's all, thank you for your attention <3, here u can buy me a coffee
Any crypto network: 0x753846BF882046c5Edc3cefED30A4E6Bf8F99999
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file python-ezconfig-0.2.0.tar.gz
.
File metadata
- Download URL: python-ezconfig-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f84c4ab800427bb9e85deb2cb68be0c20e579ec4f2b3ed8294bebd022441597d |
|
MD5 | 14312806b16910cea203068af9c3c866 |
|
BLAKE2b-256 | 2b92b07854ea1d9325d9c6f0ef0022f4ead048a34d7a5cdf0c194a4b946bb7d0 |