1As others have said, pipe it into ssh. But what you will want to do is give the proper arguments. You will want to add -u to get the output back from ssh properly. And want to add - to handle the output and later arguments.
2
3ssh user@host python -u - < script.py
4If you want to give command line arguments, add them after the -.
5
6ssh user@host python -u - --opt arg1 arg2 < script.py