What is it ?
Kroissan is a tool that combine the simplicity of YAML with the power of Python to open a new way of making spreadsheet.
How to install it ?
Kroissan is coded in python, so it is available on pip.
$ pip3 install kroissan
How to use it ?
Kroissan interpret the Python contained into the YAML files to create a new YAML.
Let’s take an example, we have file containing the costs of different objects per year, and you want to calculate the objects total costs for a year.
# input.yaml
costs:
2017:
object_1: 1500
object_2: 1200
object_3: 2200
2018:
object_1: 2000
object_2: 3200
object_3: 1200
2019:
object_1: 2400
object_2: 5000
object_3: 8400
sum: |
{y: sum(v.values()) for y,v in costs.items()}
We can now execute Kroissan with the input.yaml file as parameter.
$ kroissan input.yaml
costs:
2017:
object_1: 1500
object_2: 1200
object_3: 2200
2018:
object_1: 2000
object_2: 3200
object_3: 1200
2019:
object_1: 2400
object_2: 5000
object_3: 8400
sum:
2017: 4900
2018: 6400
2019: 15800
Kroissan print the result directly to stdout
.
So, we can redirect the ouput into a file if we want to store the result.
$ kroissan input.yaml > output.yaml
Kroissan let us chain the YAML files.
We can split the previous file input.yaml
into two files.
# data.yaml
costs:
2017:
object_1: 1500
object_2: 1200
object_3: 2200
2018:
object_1: 2000
object_2: 3200
object_3: 1200
2019:
object_1: 2400
object_2: 5000
object_3: 8400
# sum.yaml
sum: |
{y: sum(v.values()) for y,v in costs.items()}
We can now give those two files to Kroissan.
And see that the result is a new YAML with the operation of sum.yaml
with the data from data.yaml
$ kroissan data.yaml sum.yaml
sum:
2017: 4900
2018: 6400
2019: 15800
Of course, you can chain more then two files!
Is there more to know ?
You can merge several YAML files for one step, just separate them with the character :
.
# costs.yaml
costs:
2017:
object_1: 1500
object_2: 1200
object_3: 2200
2018:
object_1: 2000
object_2: 3200
object_3: 1200
# revenue.yaml
revenue:
2017:
object_1: 2400
object_2: 4800
object_3: 1100
2018:
object_1: 700
object_2: 1600
object_3: 1000
# sum.yaml
costs: |
{y: sum(v.values()) for y,v in costs.items()}
revenue: |
{y: sum(v.values()) for y,v in revenue.items()}
$ kroissan costs.yaml:revenue.yaml sum.yaml
costs:
2017: 4900
2018: 6400
revenue:
2017: 8300
2018: 3300
Print version.
$ kroissan -v
Print the help.
$ kroissan -h