Skip to main content

Essentials

IMAPClient is an easy-to-use, Pythonic and complete IMAP client library.

Supported Python versions

3.8 - 3.14

License

New BSD

Project home

https://github.com/mjs/imapclient/

PyPI

https://pypi.python.org/pypi/IMAPClient

Documentation

https://imapclient.readthedocs.io/

Discussions

https://github.com/mjs/imapclient/discussions

Test Status

master branch

Features

  • Arguments and return values are natural Python types.

  • IMAP server responses are fully parsed and readily usable.

  • IMAP unique message IDs (UIDs) are handled transparently. There is no need to call different methods to use UIDs.

  • Escaping for internationalised mailbox names is transparently handled. Unicode mailbox names may be passed as input wherever a folder name is accepted.

  • Time zones are transparently handled including when the server and client are in different zones.

  • Convenience methods are provided for commonly used functionality.

  • Exceptions are raised when errors occur.

Example

from imapclient import IMAPClient

# context manager ensures the session is cleaned up
with IMAPClient(host="imap.host.org") as client:
    client.login('someone', 'secret')
    client.select_folder('INBOX')

    # search criteria are passed in a straightforward way
    # (nesting is supported)
    messages = client.search(['NOT', 'DELETED'])

    # fetch selectors are passed as a simple list of strings.
    response = client.fetch(messages, ['FLAGS', 'RFC822.SIZE'])

    # `response` is keyed by message id and contains parsed,
    # converted response items.
    for message_id, data in response.items():
        print('{id}: {size} bytes, flags={flags}'.format(
            id=message_id,
            size=data[b'RFC822.SIZE'],
            flags=data[b'FLAGS']))

Why IMAPClient?

You may ask: “why create another IMAP client library for Python? Doesn’t the Python standard library already have imaplib?”.

The problem with imaplib is that it’s very low-level. It expects string values where lists or tuples would be more appropriate and returns server responses almost unparsed. As IMAP server responses can be quite complex this means everyone using imaplib ends up writing their own fragile parsing routines.

Also, imaplib doesn’t make good use of exceptions. This means you need to check the return value of each call to imaplib to see if what you just did was successful.

IMAPClient actually uses imaplib internally. This may change at some point in the future.

Installing IMAPClient

IMAPClient is listed on PyPI and can be installed with uv:

uv add imapclient

More installation methods are described in the documentation.

Documentation

IMAPClient’s manual is available at http://imapclient.readthedocs.io/. Release notes can be found at http://imapclient.readthedocs.io/#release-history.

See the examples directory in the root of project source for examples of how to use IMAPClient.

Current Status

You should feel confident using IMAPClient for production purposes.

In order to clearly communicate version compatibility, IMAPClient will strictly adhere to the Semantic Versioning scheme from version 1.0 onwards.

The project’s home page is https://github.com/mjs/imapclient/ (this currently redirects to the IMAPClient Github site). Details about upcoming versions and planned features/fixes can be found in the issue tracker on Github. The maintainers also blog about IMAPClient news. Those articles can be found here.

Discussions

Github Discussions can be used to ask questions, propose changes or praise the project maintainers :)

Working on IMAPClient

The contributing documentation contains information for those interested in improving IMAPClient.

IMAP Servers

IMAPClient is heavily tested against Dovecot, Gmail, Fastmail.fm (who use a modified Cyrus implementation), Office365 and Yahoo. Access to accounts on other IMAP servers/services for testing would be greatly appreciated.

Interactive Console

This script connects an IMAPClient instance using the command line args given and starts an interactive session. This is useful for exploring the IMAPClient API and testing things out, avoiding the steps required to set up an IMAPClient instance.

The IPython shell is used if it is installed. Otherwise the code.interact() function from the standard library is used.

The interactive console functionality can be accessed by running the imapclient-interact script that is installed alongside IMAPClient, or by invoking the interact module like this:

uv run python -m imapclient.interact ...

“Live” Tests

IMAPClient includes a series of live, functional tests which exercise it against a live IMAP account. These are useful for ensuring compatibility with a given IMAP server implementation.

The livetest functionality is run using the imapclient-livetest script that is installed alongside IMAPClient:

uv run imapclient-livetest <livetest.ini> [ optional unittest arguments ]

The configuration file format is described in the main documentation.

WARNING: The operations used by livetest are destructive and could cause unintended loss of data. That said, as of version 0.9, livetest limits its activity to a folder it creates and subfolders of that folder. It should be safe to use with any IMAP account but please don’t run livetest against a truly important IMAP account.

Please include the output of imapclient-livetest with an issue if it fails to run successfully against a particular IMAP server. Reports of successful runs are also welcome. Please include the type and version of the IMAP server, if known.

Download files

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

Source Distribution

imapclient-4.0.1.tar.gz (69.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imapclient-4.0.1-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

File details

Details for the file imapclient-4.0.1.tar.gz.

File metadata

  • Download URL: imapclient-4.0.1.tar.gz
  • Upload date:
  • Size: 69.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for imapclient-4.0.1.tar.gz
Algorithm Hash digest
SHA256 9c46f431ceecde87ae1bbb8c287cbeb20bc70bcbee3d0c3bd0c01808d28630f4
MD5 f2fb2a123b4e31fb341401b9593bd05a
BLAKE2b-256 af6fe128b98df35303d744506357d7024201abf519cc4e5ac03577f7d7be39df

See more details on using hashes here.

File details

Details for the file imapclient-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: imapclient-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 55.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for imapclient-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7dd1a175eda1cb1e99a5aeca4ea2c0b0a3ed36f13b2e677bc3447588336df27
MD5 d6845243535048bff1261d9f4a44aa24
BLAKE2b-256 7e7241d7acbcb9ff9ec612ebcc994fcc831ccb19cd79570a3cabba39d80c18c0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

4.0.1 This release

2 files

4.0.0

2 files

3.1.0

2 files

3.0.1

2 files

3.0.0

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.0

2 files

1.1.0

1 file

1.0.2

3 files

1.0.1

3 files

1.0.0

3 files

0.13

2 files

0.12

2 files

0.11

2 files

0.10.2

2 files

0.10.1

0.10

0.9.2

0.9.1

0.9

0.8.1

0.8

0.7

0.6.2

0.6.1

0.6

0.5.2

0.5.1

0.5

0.4

0.3

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page