You could make a plugin that calls the script using ITicketChangeListener:
If you need to call your script at specific actions of the Trac workflow, see run_external operation of TracAdvancedTicketWorkflow:
You might be able to use the latter on ticket creation by adding:
create.operations = run_exernal
and adding create.py to $env/hooks with create.py calling your script using the subprocess module.
Ryan