---
source: https://iinventedlight.com/library/notes/python-imaplib.md
title: "Python imaplib: an IMAP4 protocol client"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, imaplib — IMAP4 protocol client; CPython, imaplib documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-imaplib"
tags: [python, imaplib, imap, email, client]
client: Librarian
sources:
  - id: S1
    title: "imaplib — IMAP4 protocol client"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/imaplib.html
    accessed: 2026-11-23
    license: "PSF License Version 2"
  - id: S2
    title: "imaplib documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/imaplib.rst
    accessed: 2026-11-23
    license: "PSF License Version 2"
---
# Python imaplib: an IMAP4 protocol client
**Answer:** This module defines three classes, IMAP4, IMAP4_SSL and IMAP4_stream.

## Classes and protocol

The three classes are IMAP4, IMAP4_SSL, and IMAP4_stream.

Together they encapsulate a connection to an IMAP4 server.

The implemented subset follows the IMAP4rev1 client protocol in RFC 3501.

It is backward compatible with IMAP4 (RFC 1730) servers.

The STATUS command is not supported in plain IMAP4.

The module is not available on WebAssembly.

## Connection defaults and context managers

When host is omitted, the local host is used.

When port is omitted, the standard IMAP4 port 143 is used.

The IMAP4 class can be used as a context manager.

The IMAP4 LOGOUT command is issued automatically when the with statement exits.

## See also

- [python-smtplib](https://iinventedlight.com/library/notes/python-smtplib/)
- [python-ftplib](https://iinventedlight.com/library/notes/python-ftplib/)
- [python-email](https://iinventedlight.com/library/notes/python-email/)

## Claims

- id: C1
  claim: The module defines IMAP4, IMAP4_SSL, and IMAP4_stream.
  source: S1
  evidence: "three classes, IMAP4 , IMAP4_SSL and IMAP4_stream"

- id: C2
  claim: The client covers a large subset of IMAP4rev1 in RFC 3501.
  source: S1
  evidence: "large subset of the IMAP4rev1 client protocol as defined in RFC 3501"

- id: C3
  claim: The STATUS command is not supported in IMAP4.
  source: S2
  evidence: "command is not supported in IMAP4"

- id: C4
  claim: Leaving a with block issues LOGOUT automatically.
  source: S2
  evidence: "command is issued automatically"

## Sources

- [S1] imaplib — IMAP4 protocol client. Python Software Foundation. https://docs.python.org/3/library/imaplib.html . License: PSF License Version 2. Accessed 2026-11-23.

- [S2] imaplib documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/imaplib.rst . License: PSF License Version 2. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, imaplib — IMAP4 protocol client; CPython, imaplib documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
