sif - simple info format
get the official python module / go home
welcome! this is the official documentation about sif. below is the spec, and python API documentation.
- syntax
sif is designed to be the absolute bare minimum required for writing data, while maintaining a clean readable syntax.
you'll notice the syntax to be very similar to something like ini or toml, because sif was inspired from them.
the syntax is key = value
. basically, everything before the first = sign is considered the key,
while everything after it is considered the value.
- example:
# this is a comment
key = value
another key = another value
newlines = can also be done
simply put a space at the start of a new line
9+10=21
- comments, newline strings, types
1. every single line beginning with a #
is considered a comment.
2. newline strings work by having a space character at the start of a new line. this tells the parser we are continuing the key above.
if you put n spaces like " hello world", those space will be inserted into the output string too. the first one is a delimiter for a newline to the string.
3. because the format is minimal, theres no types, everything is a string.
however you can make type conversion for stuff like "true", "false" or "null" yourself.
- using the python module
- parse(string: str) -> dict
parses a sif string as an object
example:
import sif
with open("file.sif", "r") as f:
data = sif.parse(f.read())
print(data["key"])
- parse_arr(string: str) -> list
parses a sif string as an array
example:
import sif
with open("file.sif", "r") as f:
data = sif.parse_arr(f.read())
print(data[0][1]) # gets the value of the first key
- dump(obj: dict) -> str
dumps a dictionary as a sif string
note that this function does remove comments and may not work well in rare special occasions.
example:
import sif
with open("file.sif", "r") as f:
data = sif.parse(f.read())
data["key"] = "new value"
with open("export.sif", "w") as f:
f.write( sif.dump(data) )