---
source: https://iinventedlight.com/library/notes/python-http-cookies.md
title: "Python http cookies: parse and write HTTP cookies"
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, http.cookies — HTTP state management; CPython, http.cookies 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-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). 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-http-cookies"
tags: [python, cookies, http, morsel, web]
client: Librarian
sources:
  - id: S1
    title: "http.cookies — HTTP state management"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/http.cookies.html
    accessed: 2026-11-24
    license: "PSF License Version 2"
  - id: S2
    title: "http.cookies documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/http.cookies.rst
    accessed: 2026-11-24
    license: "PSF License Version 2"
---
# Python http cookies: parse and write HTTP cookies
**Answer:** The cookies module defines classes for abstracting the concept of cookies, an HTTP state management mechanism.

## Classes

BaseCookie is a dictionary-like object whose keys are strings.

The values stored there are Morsel instances.

When you set a key, the value is first converted to a Morsel.

SimpleCookie derives from BaseCookie and supports strings as cookie values.

## Parsing and errors

On encountering an invalid cookie, CookieError is raised.

If cookie data comes from a browser, you should catch CookieError on parsing.

Version 3.3 allowed a colon as a valid cookie name character.

The cookies module and the cookiejar module do not depend on each other.

## See also

- [python-http-cookiejar](https://iinventedlight.com/library/notes/python-http-cookiejar/)
- [python-http-client](https://iinventedlight.com/library/notes/python-http-client/)
- [python-http-server](https://iinventedlight.com/library/notes/python-http-server/)

## Claims

- id: C1
  claim: The module defines classes that abstract HTTP cookies.
  source: S1
  evidence: "defines classes for abstracting the concept of cookies"

- id: C2
  claim: SimpleCookie supports strings as cookie values.
  source: S1
  evidence: "SimpleCookie supports strings as cookie values"

- id: C3
  claim: BaseCookie is a dictionary-like object whose keys are strings.
  source: S2
  evidence: "This class is a dictionary-like object whose keys are strings"

- id: C4
  claim: The cookies and cookiejar modules do not depend on each other.
  source: S2
  evidence: "do not depend on each other"

## Sources

- [S1] http.cookies — HTTP state management. Python Software Foundation. https://docs.python.org/3/library/http.cookies.html . License: PSF License Version 2. Accessed 2026-11-24.

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

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, http.cookies — HTTP state management; CPython, http.cookies 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).
