A library to easily manage program configuration.
Project description
SimpleCFG
A library to easily manage program configuration, for Python.
Installation
pip install simplecfg
Quick Start
import simplecfg
cfg = simplecfg.Config("settings.cfg")
# Writing
cfg.set("username", "Max")
cfg["website"] = "https://itsmaxymoo.com"
cfg.write_file()
# Reading
cfg.read_file()
name = cfg.get("username") # 'name' contains "Max"
Functions
All of the following functions are to be called on an instance of simplecfg.Config
Name | Function | Argument(s) | Returns |
---|---|---|---|
__init__(path: str) |
Constructor | Path to the config file | - |
get(key: str) |
Get an item from the config | Key name | Item stored at key, otherwise None |
set(key: str, value) |
Set a value in the config | Key name, item | None |
delete(key: str) |
Remove an item from the config | Key name | Item if found, otherwise None |
get_keys() |
Returns an iterable of all keys in the config | - | iterable |
dump() |
Returns text representation of the config | - | str |
wipe() |
Deletes all keys | - | - |
read_file(load_if_corrupt = False) |
Loads config from disk | Boolean to create an empty config if the file is corrupt. Otherwise, raise ValueError | - |
write_file() |
Commit config to disk | - | - |
Magic Functions
Name | Behavior |
---|---|
__len__() |
Returns the number of keys in the config |
__contains__(key: str) |
Returns true if key exists in the config |
__getitem__(key: str) |
Alias to get(key) |
__setitem__(key: str, value) |
Alias to set(key, value) |
__delitem__(key: str) |
Alias to delete(key) , does not return anything |
SynchronousConfig
Alternatively, you may opt to use simplecfg.SynchronousConfig
.
It has the same functions as simplecfg.Config
, but it will automatically
commit the config to disk with every modification.
Predefined Directories
SimpleCFG contains some predefined directories in the module simplecfg.dir
,
to assist in configuration file placement. Each directory is accessed at
simplecfg.dir.DIRNAME
Directory Name | Linux | Mac OS | Windows |
---|---|---|---|
HOME |
~ |
~ |
~ |
APP_DATA |
~/.local/share |
~\AppData\Roaming |
~/Library/Application Support |
CONFIG |
~/.config |
~\AppData\Roaming |
~/Library/Application Support |
TEMP |
/tmp |
~\AppData\Local\Temp |
/tmp |
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
simplecfg-2.0.0.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for simplecfg-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abd88aae7628ddf792654f0d6672a06a0fa1d821b23cd72be70d42e01c5888ea |
|
MD5 | 804ede44bc1ae9c0b78f05bdf8b5faf5 |
|
BLAKE2b-256 | ff3ddd93dc2c474662fb651ae803f2e53d75c5c2e8db85ea82c6fbc8a54486ae |