Skip to main content

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


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 details)

Uploaded Source

Built Distribution

simplecfg-2.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file simplecfg-2.0.0.tar.gz.

File metadata

  • Download URL: simplecfg-2.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for simplecfg-2.0.0.tar.gz
Algorithm Hash digest
SHA256 37aa13d37133aa67de2404af41b6363d64fc1043f43ad0e86a2c683b05dcbe0b
MD5 0332bb4abf8110f3fe15dd640ed4c28e
BLAKE2b-256 c861a2b097ecd8180c2596134c6e0b9016c732b635e1416a94d4edbf6f14783d

See more details on using hashes here.

File details

Details for the file simplecfg-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: simplecfg-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for simplecfg-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abd88aae7628ddf792654f0d6672a06a0fa1d821b23cd72be70d42e01c5888ea
MD5 804ede44bc1ae9c0b78f05bdf8b5faf5
BLAKE2b-256 ff3ddd93dc2c474662fb651ae803f2e53d75c5c2e8db85ea82c6fbc8a54486ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page