Package: yamello
yamelloauthor informationcodima(coding-mathmatics) on youtubeUsagethis package can serialize as well as deserialize python
data (int,float,bool,str,math.inf,None)
and data structures (listortuple&dict) into
text-based files with suffix.yamelloor.yamlor.yml.As the last 2 suffixes indicate:Yes, anyyamellofile is supposed to satisfy theYAMLspec, too!Sometimes they can be validJSON, too.In comparision to theYamlfile format,yamellois way less capable to express exotic data and does purposefully
not allow binary data dumps.
The scope ofyamellois simply different and has 3 main goals:it essentially tries to feel likeJSONto users, but
mixed in with a bit of syntactic sugarthe deserialization will respect or keep the ordering of
dictionary keys withinyamellofiles
(whatever ordering they may have in the first place)the serialization process ofyamellowill order
dictionary keys alphabeticallyDue to main goals 2 & 3 there is no canonicalization necessary
when hashing serializedyamellofiles; which (aside from
coding exploration) was the major reason to implementyamelloin the first place!fromyamelloimportserialize,deserialize''' deserialization '''withopen('demo_resources/demo.in.yaml',mode='r')asin_stream:in_str=in_stream.read()in_data=deserialize(in_str,vec_constructor=tuple)print(in_data)''' operations on the data '''out_data=in_data''' serialization '''out_str:str=serialize(out_data)withopen('demo_resources/demo.out.yaml',mode='w')asout_stream:out_stream.write(out_str)Please note:yamellois written purely inpythonand
hence it was not developed with execution speed in mind.dataintintare composed of digits0to9(e.g.1217)
and may include a leading minus-to indicate negative
numbers (e.g.-13).Caution:numbers in scientific notation, e.g.12e7, will
be interpreted asfloat!Note:one can writeinfor-inffor infinity or
negative infinity.Note:It is allowed to place underscores_in between digits for
readability (e.g.1_000_000which is equivalent to1_0_0000_0as well as to1000000).floatfloator floating point numbers. They are composed of
digits0to9, including a point.as decimal seperator
(e.g.1.0or0.045or13.076).
They may include a leading minus-to indicate negative
numbers (e.g.-70.09or-0.0007).Note:floatcan be written in scientific notation,
i.e. in exponent notation includinge(e.g.1.4e-8or12e2or-0.3e2)Note:a decimal seperator is necessary, unless scientific
notion is in use.Note:one can writeinfor-inffor infinity or
negative infinity.Note:It is allowed to place underscores_in between
digits for readability (e.g.1_000_000.0_0or1_0e2_0).Caution:decimal seperators.need to be
surrounded by digits (e.g.1.0is valid as well as0.01whereas1.or.01are not)!boolboolcan be written asTrueorFalse(regardless of
upper and lower case, i.e.trueis as muchTrueastRuE)strstror strings always have to be enclosed by a pair of
double-quotes", unless they are dictionary keys
(see dictionaries) where they are optional.
Any composition of UTF-8 may appear in between a pair of
double-quotes.Note:double quotes can be escaped using backslash\"to include double-quotes into strings.Caution:single-quotes'are simply ignored during the
deserialization process to decide whether something is a
string or not.NoneNonecan be denoted bynull(regardless of
upper and lower case, e.g.NULLorNullornuLLare valid as well)infinityinfor-infrepresent infinity or negative infinity
(again regardless of lower and upper case).Note:The serialization will convertmath.inf(from the
math library) ornumpy.inf(from the numpy library) intoinf.Note:The deserialization will convertinfintomath.inf(from the math library).data structuresinline dictInlinedictor dictionaries are enclosed by a pair of
curly-braces{and}. They are anorderedlist ofkey: valuepairs, seperated by commas,. Hence, the
general structure follows:{key1:value1,key2:value2,...}or{key1:value1,key2:value2}as linebreaks do not matter.keyis either a string enclosed by a pair of double-quotes"or a (not enclosed) string containing charactersatoz,AtoZ, underscore_and digits0to9(provided the character is not a digit).valueis anydatadiscussed above or another inlinedictor an inlinelist.{valid_not_enclosed_key:99,"quotesenclosedkeyduetowhitespaces":-17.02,_anotehr_valid_key:"message"}Caution:repeatedkeyswithin the same dictionary will
overwrite each other (last one counts)!(regular) dictRegular aka "not inline"dictsare essentially equivalent to
inlinedicts(-> see inlinedicts). The only two differences
are the syntax and the fact thatvalues(from thekey:valuepairs) can be another
regulardictor a regularlist, too.Regarding the syntax: A regulardictis not surrounded
by curly-braces.
Instead, a line break followed by a consistent increase
of indentation (in front ofkeys) mark the beginning,
as well as a decrease (by the same amount of characters)
of indentation mark the end of a regulardict.
The indentation ofvalues(for thosevaluesthat are
put on one of the next lines) have to be consistent amongvaluesand larger than that of theirkeys.
Furthermore, line breaks replace commas to
separatekey:valuepairs from one another.upper_level_key1:# regular structs (dict and list) require line break ...key1:value1# ... hence a new (regular) dict starts herekey2:value2key3:# empty lines and ...value3# ... linebreaks between keys and values are allowedkey4:# also empty lines between keys and ...value4# ... values are allowedupper_level_key2:upper_level_value2inline listInlinelistor lists are enclosed by a pair of
brackets[and]. They are anorderedcollection ofentries, seperated by commas,. Hence, the
general structure follows:[value1,value2,...]or[value1,value2]as linebreaks again do not matter.entryis anydatadiscussed above or another inlinedictor an inlinelist.(regular) listRegular aka "not inline"listsare essentially equivalent to
inlinelists(-> see inlinelist). The only two differences
are the syntax and the
fact thatentriescan be another regulardictor a regularlist, too.Regarding the syntax: A regularlistis not surrounded
by brackets.
Instead, a line break followed by a consistent increase
of indentation mark the beginning,
as well as a decrease (by the same amount of characters)
of indentation mark the end of a regularlist.
Every entry has to be introduced by a dash-followed by at least one
space. The indentation ofentries(for thoseentriesthat are
put on one of the next lines) have to be consistent among suchentriesand larger than that compared to the indentation of their dashes-.
Furthermore, line breaks replace commas to
separateentriesfrom one another.upper_level_key1:# following struct is equivalent to [value1, value2, value3, value4]-value1-value2-value3-# line breaks are valid, but require either a comment or your IDE not to delete trailing whitespacesvalue4upper_level_key2:# following struct is equivalent to [[value5, value6], [value7], value8]--value5-value6--value7-value9upper_level_key3:upper_level_value3additional featurescommentseverything after#on any line is considered as a comment
and ignored by the parser during deserialization.aliasAny data as well as inline data struct can be aliased for re-use.
The definition of a new alias is introduced by&and the use of an
alias is introduced by*. Using an alias requires it definition to take
place further up the same document. The same alias can be defined only once.upper_level_key1:&key1"content"# defines alias of name: "key1" with value: "content"upper_level_key2:*key1# substitutes the value: "content" stored under the alias with name: "key1"&key2 upper_level_key3:&other_key[99,inf,null]# defines to aliasupper_level_key4:-*key2# substitutes the (string) value: "upper_level_key3"-*other_key# substitutes the (inline list) value: [99, inf, null]Note:rules for alias names are the same as for not (by double quotes)
enclosed dictionary keys, i.e. upper, lower case letters, underscore.
Except for the first character also digits may be used withindocs...under constructionTODOswrite MkDocs documentation(maybe) write an actual specexchange allraiseAssertion('palceholder')for proper Exceptions within the code!informal info on license (english)This repository is licensed under GPL-V3 (see LICENSE). You can refer to the author of this package as codima & ... .