That’s not how python scripts work. Python scripts are a substitution for the yaml scripts. They run via service calls. If you want to call that script when something changes, you need to make a yaml automation that calls that python script.
There is no built in python engine for automation. You have to use PyScript or Appdaemon for that.