Install & Compatibility
Where this runs
tested against v2.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.018s · 18MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.012s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Cookies
✓ from cookies import Cookies
✗ from http.cookies import SimpleCookie
This library is designed as a replacement for http.cookies and has a different API.
Cookie
✓ from cookies import Cookie
Demonstrates creating, manipulating, and rendering 'Set-Cookie' headers, and parsing 'Cookie' request headers.
from cookies import Cookies, Cookie
# Create a Cookies object for response headers
response_cookies = Cookies()
response_cookies['session_id'] = 'abc123def456'
response_cookies['session_id'].path = '/'
response_cookies['session_id'].max_age = 3600 # 1 hour
# You can also set using a Cookie object directly
my_cookie = Cookie('user', 'guest')
my_cookie.domain = 'example.com'
response_cookies.add(my_cookie)
print('Set-Cookie Headers:')
for header_line in response_cookies.render_response():
print(header_line)
# Simulate receiving a Cookie header from a request
request_header_string = 'session_id=abc123def456; other_data=some_value'
request_cookies = Cookies.from_request(request_header_string)
print('\nParsed Request Cookies:')
for name, cookie in request_cookies.items():
print(f" {name}: {cookie.value}")
# Access a specific cookie
if 'session_id' in request_cookies:
print(f"Session ID from request: {request_cookies['session_id'].value}")
Debug
Known issues
breakingThe library explicitly does NOT maintain backward compatibility with Python's standard library `Cookie.py` (now `http.cookies`), RFC 2109, or RFC 2965. Its API is different and it adheres strictly to RFC 6265.fixDo not treat this library as a drop-in replacement for `http.cookies`. Adapt your code to its distinct RFC 6265-compliant API.
affects: All versions
deprecatedThe library reached version 2.2.1 in September 2014 and has not been updated since. It is compatible with Python 2.6, 2.7, 3.2, 3.3, and PyPy (2.7), but is unlikely to work with newer Python 3.x versions (e.g., Python 3.4+).fixFor new projects or modern Python environments (3.4+), consider using Python's built-in `http.cookies` or a more actively maintained third-party library if specific RFC 6265 strictness is not paramount, or if you require functionality beyond basic parsing/rendering.
affects: All versions (since 2014)
gotchaThe library avoids providing a means to store pickled Python objects in cookie values due to security concerns, a feature present in older `Cookie.py` implementations (e.g., `SmartCookie`).fixDo not attempt to store complex Python objects directly as cookie values; serialize them to strings (e.g., JSON) if necessary, or store state server-side using a session ID.
affects: All versions
Upgrade
Version history
2.2.1latest on PyPI · released Sep 27, 2014
Audit
Dependencies
No dependency data recorded yet.