Can I use a Suricata IDS alert to trigger some python code?

I think with dgram you might run into record size issues, depending on how much metadata you config the alerts to have. unix_stream might be a safer bet.