I used pycrypto in my projects before but since the project is no longer under active development it is highly recommended to move to cryptography.
I faced some difficulty during this migration so I am documenting my solution to help others.
This is how my pycrypto code to get pem encoded key looked like
from Crypto.IO import PKCS8
from Crypto.IO import PEM
def key_stuff(key_file=None):