My goal is to define labels programmatically for the case similar for the figure below:

But I didn't find any guidance how to do so using Python.
I have a feeling it could be done using QgsLabel but didn't find any working exmaple how to do so.
I seek some example how to do so;
If I'm wrong with QgsLabel idea, can you explain briefly the right approach for this?
As usual some code example could be very useful.