How to use Google API of Gmail with Python Google API: https://developers.google.com/gmail/api/quickstart/python
How to read email from direct credentials: https://www.codemiles.com/python-tutorials/reading-email-in-python-t10271.html readMail_POP.py readMail_IMAP.py#Not tested
Follow this step first to have API access to your script in gmail. https://support.google.com/a/answer/6260879?hl=en