Show HN: Python library to read and manage your Gmail

by charlierguoon 8/6/13, 8:44 PMwith 29 comments
by spindritfon 8/6/13, 10:10 PM

You can also retrieve the password from your system keyring[1]

    import keyring

    pass_is = keyring.get_password('gmail', 'whatever@gmail.com')
you set it with

    set_password(servicename, username, password)
so

    set_password('gmail', 'whatever@gmail.com', 'one of those per app passwords if you use 2factor for example')
[1] https://pypi.python.org/pypi/keyring

by mcrittendenon 8/6/13, 11:31 PM

This is great.

For the record, if you just need to do some simple scripting of your Gmail, maybe on cron, Google Apps Script is great for that. https://developers.google.com/apps-script/

Here's a recent simple example I wrote up. http://mikecr.it/ramblings/marking-gmail-read-with-apps-scri...

by kbar13on 8/6/13, 10:37 PM

Cool!

If you're looking for non-gmail-specific email lib thingerator, check out IMAPClient (it's better than imaplib I swear!):

http://imapclient.readthedocs.org/en/latest/

by ajaxaddictedon 8/7/13, 9:00 AM

There is also Imbox https://github.com/martinrusev/imbox, which is a Python library for reading all kinds of IMAP mailboxes, not just Gmail

by superchinkon 8/7/13, 6:54 AM

Slightly off topic, but does anyone know of a similar library for Google Calendar that's any good?

by eliasmacphersonon 8/7/13, 8:54 AM

This is really cool. The only thing I use gmail web interface for since I moved to mutt and IMAP, is forwarding already sent emails with large attachments to new addresses. They way I have mutt set up is that it downloads the attachment first and then sends it once per recipient. The web interface just sends it, so I wonder is there a way to duplicate that functionality with mutt or with a library like this.

by duvanderon 8/7/13, 4:48 AM

I really wish the username/password option wasn't supported. What use cases aren't possible with OAuth?

by deepGemon 8/7/13, 6:39 AM

Guess I can potentially use this as a module in a tornado/Django web application for scheduling email, without having the user to sign in to gmail explicitly or opening up a separate pop-up/browser window.

by hatchooon 8/7/13, 5:59 AM

This is great. Thank you for sharing.

I've been planning to create a Python script to help me automatically label my older emails based on content. This is a big help.

by ibudialloon 8/7/13, 1:44 AM

Thank you, this is really useful.

Just when I needed it and wanted to write one you posted it. I don't think I would have done half the good job you did.

by armson 8/7/13, 12:12 AM

Thank you for sharing this. I've been very interested in building my own Gmail client the past few weeks, and this looks like a nice starting point.

by AnSavvideson 8/7/13, 9:20 AM

Very cool - I am sure a lot of people will get good use out of it. Rather surprised nothing like this already existed.

by bussiereon 8/7/13, 10:00 AM

how to get the attachment files ? i didn't see anyhting in the doc about it ... Are they in the body ?

by kneson 8/7/13, 12:26 AM

Didn't know the Ruby one existed, thanks for that!

by maskedinvaderon 8/7/13, 1:17 AM

thank you for this. I was looking for something like this for a project I was working on

by kuduon 8/7/13, 4:06 AM

This looks pretty nice. It's really too bad that it works with a Google service.

by giison 8/7/13, 11:37 AM

interesting,will try it.