A simple, Pythonic file format. Same interface as the
Project description
perky
Because the world needed another configuration file format
Copyright 2018 by Larry Hastings
Overview
Perky is a new, simple rcfile format for Python programs.
The following are Perky features:
Perky syntax
Perky configuration files look something like JSON without the quoting.
example name = value
example dict = {
name = 3
another name = 5.0
}
example list = [
a
b
c
]
# lines starting with hash are ignored
# blank lines are ignored
" quoted name " = " quoted value "
triple quoted string = """
indenting
is preserved
the string is automatically outdented
to the leftmost character of the ending
triple-quote
<-- aka here
"""
Explicit transformation is better than implicit
One possibly-surprising design choice of Perky: the only natively supported values for the Perky parser are dicts, lists, and strings. Other commonly-used types (ints, floats, etc) are handled using a different mechanism: transformation.
A Perky transformation takes a dict as input, and transforms
the contents of the dict based on a schema. A Perky schema
is a dict with the same general shape as the dict produced
by the Perky parse, but it contains dicts, lists,
and transformation functions.
If you want myvalue in {'myvalue':'3'}
to be a real integer,
transform it with the schema {'myvalue': int}
.
API
perky.loads(s) -> d
Parses a string containing Perky-file-format settings. Returns a dict.
perky.load(filename, encoding="utf-8") -> d
Parses a file containing Perky-file-format settings. Returns a dict.
perky.dumps(d) -> s
Converts a dictionary to a Perky-file-format string. Keys in the dictionary must all be strings. Values that are not dicts, lists, or strings will be converted to strings using str. Returns a string.
perky.dump(filename, d, encoding="utf-8")
Converts a dictionary to a Perky-file-format string
using perky.dump
, then writes it to filename.
perky.transform(d, schema) -> o
Recursively transforms a Perky dict into some other object (usually a dict) using the provided schema.
perky.Required
perky.nullable(fn) -> fn
perky.const(fn) -> o
TODO
- Backslash quoting currently does "whatever your version of Python does". Perhaps this should be explicit, and parsed by Perky itself?
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
Built Distribution
File details
Details for the file perky-0.1.tar.gz
.
File metadata
- Download URL: perky-0.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e36837bcb2357caf792aa057f221e8987e55e19f80ea967b7e2a999af63b3b3 |
|
MD5 | 5d261bfa392721980e6b81bedaae8f91 |
|
BLAKE2b-256 | 23603f9663a44fe4d74f380f7d5e976bed4e7367a6190fc6bb5f6383be778007 |
File details
Details for the file perky-0.1-py3-none-any.whl
.
File metadata
- Download URL: perky-0.1-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f895c74c3c1e3acd96a45b7f63def4df934cf786a53d950067b2e9b7bf8da4d |
|
MD5 | 28873a9c0cd66a515ed5334a4f692600 |
|
BLAKE2b-256 | 6a58ea119f7d0faf09927e40e696242e63e8627763bc795f3cbbf74691f1d51f |