python run on remote machine code example
Example: run python script on remote server
As 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.
ssh user@host python -u - < script.py
If you want to give command line arguments, add them after the -.
ssh user@host python -u - --opt arg1 arg2 < script.py