Manage your configuration files.
Project description
Config File
Manage and manipulate your configuration files
This python package is currently a work in progress and is in a pre-alpha phase. The API is liable to break until v1.
Config File allows you to use the same simple API for manipulating INI, JSON, YAML, and TOML configuration files. For the time being, it only supports INI.
Installation
$ pip install config_file
Examples
config.ini
[calendar] today = monday start_week_on_sunday = false today_index = 0 quarter_hours_passed = 0.25
example.py
from config_file import ConfigFile config = ConfigFile("~/.config/test/config.ini") # Output your config file as a string config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 0\nquarter_hours_passed = 0.25\n\n' # Retrieve values with a section.key format config.get("calendar.today") >>> 'monday' # Values from the config file are automatically parsed config.get("calendar.start_week_on_sunday") >>> False # Values from the config file are automatically parsed config.get("calendar.start_week_on_sunday") >>> False # Unless you don't want them to be parsed config.get("calendar.today_index", parse_type=False) >>> '0' # The dot syntax is also used to set values. True is returned on success. config.set("calendar.today_index", 20) >>> True config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n' # If you specify a section that isn't in your config file, the section and the key are added for you. config.set("week.tuesday_index", 2) >>> True config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n[week]\ntuesday_index = 2\n\n' # Delete can delete an entire section or just a key/value pair. config.delete('week') >>> True config.stringify() >>> '[calendar]\ntoday = monday\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n' # Delete can delete an entire section or just a key/value pair. config.delete('calendar.today') >>> True config.stringify() >>> '[calendar]\nstart_week_on_sunday = false\ntoday_index = 20\nquarter_hours_passed = 0.25\n\n' # You can also just check if the file has a particular section or key. config.has('calendar') >>> True config.has('week') >>> False config.has('calendar.start_week_on_sunday') >>> True # The file is only written back out when you call save() config.save() >>> True # You can also reset the file back to its original state. The current configuration file # would be deleted and replaced by a copy of the original. By default, since our passed in # config file was at path `~/.config/test/config.ini`, `reset()` will look for # `~/.config/test/config.original.ini` config.reset() >>> True # Or you can specify the file path explicitly config.reset(original_file_path="~/some_other_directory/this_is_actually_the_original.ini") >>> True
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size config_file-0.4.0-py3-none-any.whl (9.0 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size config_file-0.4.0.tar.gz (8.6 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for config_file-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbc0687f241f473f77cb57f05611b5b3721ca92544639a5260fef48acd4539b5 |
|
MD5 | 635e03d21bd0d74c591db3970daef16d |
|
BLAKE2-256 | 7296a709be1c2f42cb0373275037c60df4ffec85885c350ccfa5e328acdc26e2 |