Skip to main content

Pythonic Gmail client

Project description

Pythonic Gmail client (WIP)


  • [x] Clean API
  • [x] No other dependencies than standard libraries
  • [x] Supports all of the SEARCH criteria
  • [-] Supports access to all of the HEADER fields via attributes
  • [ ] Lazy loading for contents


import sys
import getpass
import datetime

from gmaily import Gmaily

g = Gmaily()

user_email = input('Email: ')
user_pw = getpass.getpass()

if not g.login(user_email, user_pw):
    print('Cannot login')

msgs = g.inbox().after( - datetime.timedelta(weeks=2))
for msg in msgs.all():
    print('\n' + (' Mail UID: %d ' % msg.uid).center(80, '=') + '\n')
    print('Subject:', msg.subject)
    print('From:', msg.sender)
    print('Attachments:', msg.attachments)

    print('-' * 10)



Searching Mailbox

SearchQuery, which is returned by some methods like Gmaily.inbox supports method chaining and you can easily mix search criterias together:

two_weeks_ago = - datetime.timedelta(weeks=2)
msgs = g.inbox().by('').before(two_weeks_ago)

Alternatively, you can use other mailboxes than INBOX in the above example using Gmaily.mailbox method:

msgs = g.mailbox('URGENT').on(

You can then execute the query and fetch the results using SearchQuery.all:


You can find the full list of supported criterias and their description at here. Note that ALL criteria is not present because it’s the default criteria and SearchQuery.all stands for executing the query. Any other names like .fetch(), .do() could be taken the place, but I chose the .all() because it looks similar than famous ORMs’.

And some other criterias are omitted too:

  • NOT
  • OR
  • UID


Currently it requires Python 3.

$ pip install gmaily



Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gmaily, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size gmaily-0.0.2-py3-none-any.whl (5.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size gmaily-0.0.2.tar.gz (4.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page