from M2Crypto import RSA
rsa = RSA.load_pub_key('public.pem')
ctxt = rsa.public_encrypt(fileinput.input().read(), RSA.pkcs1_oaep_padding)
print(ctxt.encode('base64'))
How to implement OpenSSL functionality in Python?