Convert yaml/jinja to python?

is there a way one can directly import/convert a yaml/jinja template in python? would be a great tool…
example:

i have a sensor.log_tail:

  - platform: file
    file_path: /config/home-assistant.log
    name: Log tail

which shows the last line in the log in the frontend. Every now and then this is more than 255 characters, so it errors out.

If i could make a python script like here, with the sensor.log_tail value (state) in ‘attribute’ : text that would be so nice. Using the state-card-value_only, would allow showing the value in the frontend.

hass.states.set('sensor.log_tail', '', {
        'custom_ui_state_card': 'state-card-value_only',
        'text': log-tail
        }) 

or can this be realized in another way in python, not needing to import anything at all? simply read the log and show the last lines?

same goes for this template based on @skalavala 's work, which is rather cool:

map_totaal_actueel_sensors:
  friendly_name: Overzicht sensors actueel
  unit_of_measurement: 'Watt'
  value_template: >
   {{ '-'.ljust(30, '-') }} {{ '-'.ljust(30, '-') }}
   {{ 'Entity ID'.ljust(30, ' ') }} {{ 'Actueel verbruik'.ljust(30, ' ') }}
   {{ '-'.ljust(30, '-') }} {{ '-'.ljust(30, '-') }}
   {%-for state in states.sensor 
     if  state.entity_id.endswith('actueel') and state.state >'0' %}
   {{state.name[:-8]}}: {{state.state.ljust(30, ' ')}}
   {%-endfor%}
   {{ '-'.ljust(30, '-') }} {{ '-'.ljust(30, '-') }}
   'Count sensors :' {{ state_attr('sensor.total_sensors', 'count') }} 'totaal: ' {{ states.sensor|selectattr( 'entity_id','in',state_attr('group.iungo_actueel_verbruik','entity_id'))
    |map(attribute='state')|map('int')|sum }} 

see here how I have tackled that for now in Template to add values of all sensors with certain name ending with great help from @pnbruckner

lease have a look, thx,
Marius