Skip to main content

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

Metadata

Release files for simplecfg 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simplecfg 2.0.0
File Size Uploaded Provenance Actions
simplecfg-2.0.0.tar.gz 4.5 kB Without provenance Details for simplecfg-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simplecfg 2.0.0
File Interpreter ABI Platform Actions
simplecfg-2.0.0-py3-none-any.whl Python 3 none any Details for simplecfg-2.0.0-py3-none-any.whl

Total release size: 10.1 kB

Release files / simplecfg-2.0.0.tar.gz

Download URL simplecfg-2.0.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
37aa13d37133aa67de2404af41b6363d64fc1043f43ad0e86a2c683b05dcbe0b
BLAKE2b-256 checksum
How to use checksums
c861a2b097ecd8180c2596134c6e0b9016c732b635e1416a94d4edbf6f14783d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / simplecfg-2.0.0-py3-none-any.whl

Download URL simplecfg-2.0.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abd88aae7628ddf792654f0d6672a06a0fa1d821b23cd72be70d42e01c5888ea
BLAKE2b-256 checksum
How to use checksums
ff3ddd93dc2c474662fb651ae803f2e53d75c5c2e8db85ea82c6fbc8a54486ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Security for simplecfg 2.0.0

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.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page