Only Sprite objects have animations, so there can't be a general purpose method for it. You also need to know a valid animation name, which is not easily obtainable.
What are you trying to achieve? Addon developers often try to make their addon change things automatically, when it would be better to just expose it to the event system and let the user connect that to whatever they want using events.