Don’t thnks this is possible directly, but you migth be able to execute the python script when stored in the resources folder and try to invoke the script froma java action with the help of Apache Commons Exec for example.
Never tried this though.
For some ideas on doing this from java have a look at: https://www.baeldung.com/java-working-with-python