Package: yamtable
yamtable |🍠✨|A pretty ✨ formatting library meant for CLIs that need to display complex or ambiguously structured data, e.g. data from a REST API.The idea is that, sometimes you have data that would look best as YAML, as it is quite good at displaying dictionaries.
And sometimes you might have a list of dictionaries (e.g. a list of entities with attributes) and displaying that would
look muchhh better in a table because YAML would make it almost impossible to scan through the very tall representation
of your data.And sometimes you have a mix of the two. Like you could have some top level keys that would look best as YAML, but then
you have some tabular data inside of it.Point being, wouldn't it be nice to be able to print out this mixed data in a nice way without having to rewrite and customize a
data formatter for each data configuration? Often times you want to look at the data first to even know what's going on and how you want
to format it!importyamtable# some messy objectyamtable.dump({'blah0':{'something':[{'is_up':False,'value_A':0.5367493221202239,'value_B':100.0825738163817,'id':2588},{'is_up':True,'value_A':0.4559654642937784,'value_B':100.76840781583714,'id':2259}],'other thing':[{'is_up':False,'value_A':0.5881412394062349,'value_B':100.18253046678744,'id':4778}],'third thing':[1,2,3]},'blah1':{'something':[{'is_up':False,'value_A':0.6647093697365306,'value_B':100.15798391354355,'id':2477},{'is_up':True,'value_A':0.8701196743925997,'value_B':100.45672829258778,'id':4183}],'other thing':[{'is_up':False,'value_A':0.9113837527694413,'value_B':100.05392635622654,'id':2553}],'third thing':[1,2,3]}})Ahhhh!blah0:something:value_A  is_up      value_B    id---------  -------  ---------  ----0.894  🥀         100.515  35660.379  🌹         100.345  4560other thing:value_A  is_up      value_B    id---------  -------  ---------  ----0.218  🥀         100.781  1311third thing:-1-2-3blah1:something:value_A  is_up      value_B    id---------  -------  ---------  ----0.203  🌹         100.998  43460.995  🌹         100.094  3308other thing:value_A  is_up      value_B    id---------  -------  ---------  ----0.455  🥀         100.621  1686third thing:-1-2-3InstallpipinstallyamtableUsageimportyamtable# some test dataimportrandomdefsensor_data(n=8):return[{'is_up':random.choice([False,True]),'value_A':random.random(),'value_B':random.random()+100,'id':random.randint(1000,5000)}foriinrange(n)]yamtable.dump(sensor_data())Author NotesThis is a fun pet project built so I could stop copying mutating code between CLI projects.
It isn't meant to be mature or fool-proof for all kinds of data.Since it deals with deeply nested data, it is difficult to find ways to intuitively customize
the behavior from a top-level perspective. Defining multi-depth configuration from a dict level
is probably not the best idea, but if you want to customize behavior, you can just override the
class methods. Seeexamples/custom.pyfor an example.TODO:add ability to limit data displayed, sometimes a table can just be way too bighow to make colors legible and pretty on different systems with different themesMore Examples:$pythonexamples/nested.py

wow:blah0:something:+---------+-----------+-----------+------+|is_up|value_B|value_A|id|+=========+===========+===========+======+|🥀|101|0.597|4211|+---------+-----------+-----------+------+|🥀|101|0.11|2245|+---------+-----------+-----------+------+otherthing:+---------+-----------+-----------+------+|is_up|value_B|value_A|id|+=========+===========+===========+======+|🌹|100|0.0576|1272|+---------+-----------+-----------+------+thirdthing:-1-2-3oooh:+-----------------------+-------+-------+|aaa|bbb|ccc|+=======================+=======+=======+|okay:hm|-1|5||hmm:interesting|-2|||more?:wow:srsly?|||+-----------------------+-------+-------+|okay:wow|-1|5||hmm:interesting|-2|||more?:wow:srsly?|||+-----------------------+-------+-------+|okay:wowwow|-1|5||hmm:interesting|-2|||more?:||||isittoomuch:umm||||maybe:...|||+-----------------------+-------+-------+blah1:something:+---------+-----------+-----------+------+|is_up|value_B|value_A|id|+=========+===========+===========+======+|🥀|101|0.223|1315|+---------+-----------+-----------+------+|🥀|101|0.409|2428|+---------+-----------+-----------+------+otherthing:+---------+-----------+-----------+------+|is_up|value_B|value_A|id|+=========+===========+===========+======+|🌹|101|0.68|4227|+---------+-----------+-----------+------+thirdthing:-1-2-3oooh:+-----------------------+-------+-------+|aaa|bbb|ccc|+=======================+=======+=======+|okay:hm|-1|5||hmm:interesting|-2|||more?:wow:srsly?|||+-----------------------+-------+-------+|okay:wow|-1|5||hmm:interesting|-2|||more?:wow:srsly?|||+-----------------------+-------+-------+|okay:wowwow|-1|5||hmm:interesting|-2|||more?:||||isittoomuch:umm||||maybe:...|||+-----------------------+-------+-------+$pythonexamples/fancy_columns.py

Withoutfancycolumns:value_Ciddescvalue_Bvalue_Anamesomethingis_up
--------------------------------------------------------------------------99.14395thisissensor01010.72Sensor0asdfjasdf🌹-99.13523thisissensor11000.899Sensor1asdfjasdf🥀-99.14136thisissensor21000.905Sensor2asdfjasdf🌹-99.62474thisissensor31010.236Sensor3asdfjasdf🌹-993817thisissensor41010.6Sensor4asdfjasdf🌹-99.21471thisissensor51010.192Sensor5asdfjasdf🥀-99.23353thisissensor61010.24Sensor6asdfjasdf🥀-992630thisissensor71010.665Sensor7asdfjasdf🌹

Withfancycolumns:'is_up, id|name/desc, ..., value_*'is_upid|name/descsomethingvalue_A|value_B|value_C
-----------------------------------------------------------------
🌹1157|Sensor0asdfjasdf0.343|101|-99.7thisissensor0🥀4963|Sensor1asdfjasdf0.214|101|-99.1thisissensor1🌹3172|Sensor2asdfjasdf0.297|101|-99thisissensor2🥀1533|Sensor3asdfjasdf0.948|100|-99.4thisissensor3🌹4236|Sensor4asdfjasdf0.251|100|-99thisissensor4🥀4697|Sensor5asdfjasdf0.799|100|-100thisissensor5🥀4500|Sensor6asdfjasdf0.406|100|-99.5thisissensor6🥀3251|Sensor7asdfjasdf0.49|100|-99.8thisissensor7More examples:examples/bools.py: see all the boolean variations and how to customizeexamples/custom.py: see how to alter how things are formattedexamples/table_formats.py: see all the table format variations...