Perky Configuration Format
Perky is a new, simple, and Pythonic text file format designed for configuration files, serving as an alternative to INI, TOML, and JSON. It focuses on a minimal, human-friendly syntax and explicit data type handling, supporting strings, mappings (dicts), and sequences (lists) natively, leaving other type transformations to the user. The library is lightweight, fast, written in 100% pure Python, and currently maintained with version 0.9.3, supporting Python 3.6+.
Common errors
-
ModuleNotFoundError: No module named 'perky'
cause The 'perky' library is not installed in the current Python environment.fixRun `pip install perky` to install the library. -
FileNotFoundError: [Errno 2] No such file or directory: 'your_config.perky'
cause The file path provided to `perky.load()` does not exist or is incorrect.fixVerify the file path and name. Ensure the file exists at the specified location or provide the correct absolute/relative path. -
perky.errors.PerkyError: Unexpected character '=' in line ...
cause A malformed Perky syntax, often due to an unquoted '=' or other structural errors within a line.fixReview the Perky file at the indicated line number. Ensure key-value pairs are correctly formatted, strings are properly quoted (if necessary), and container structures are valid. Pragmas (lines starting with '=') must be at the beginning of the line. -
KeyError: 'some_key'
cause Attempting to access a key in a Perky-parsed dictionary that does not exist.fixCheck the Perky file for the correct key name and structure. Use `dict.get()` with a default value to safely access optional keys, e.g., `config.get('optional_key', 'default_value')`.
Warnings
- breaking The `encoding` argument was removed from `perky.load()` and `perky.loads()` in version 0.9.0. Perky now exclusively supports UTF-8 encoding for reading and writing files. If other encodings are required, users must handle the loading/saving to disk and use `loads`/`dumps` for string-to-object conversion.
- breaking The `Parser` attribute `breadcrumbs` was renamed to `stack` in version 0.9.1. While `breadcrumbs` remains an alias for now, it is undocumented and unsupported, and will be removed before version 1.0.
- deprecated The entire `perky.transformation` submodule, which provided functions to convert strings to native Python types, is deprecated and no longer maintained or supported. It will be removed before version 1.0.
- gotcha Perky explicitly supports only strings, dictionaries, and lists. It does not perform automatic type inference for integers, floats, booleans, or `None`. Values like `True`, `123`, or `1.5` are parsed as strings.
Install
-
pip install perky
Imports
- load
from perky import load
- loads
from perky import loads
Quickstart
import perky
config_string = """
name = ExampleApp
version = 1.0
settings = {
debug = True
log_level = INFO
features = [
feature_a
feature_b
]
}
"""
config = perky.loads(config_string)
print(config['name'])
print(config['settings']['debug'])
print(config['settings']['features'][0])
# Example of loading from a file (if 'config.perky' existed)
# with open('config.perky', 'w') as f:
# f.write(config_string)
# file_config = perky.load('config.perky')
# print(file_config)