{"id":8035,"library":"cookies","title":"cookies (sashahart)","description":"The `cookies` library (by Sasha Hart) is a Python module designed for parsing and rendering RFC 6265-compliant HTTP `Cookie:` request headers and `Set-Cookie:` response headers. It offers a cleaner API compared to the standard library's `http.cookies` and explicitly adheres to modern cookie standards, eschewing backward compatibility with older, less compliant RFCs (like 2109 or 2965). The last release was in 2014 (v2.2.1), and there is no apparent active development, suggesting it is no longer maintained.","status":"abandoned","version":"2.2.1","language":"en","source_language":"en","source_url":"https://gitlab.com/sashahart/cookies","tags":["http","cookies","rfc6265","web-development","header-parsing"],"install":[{"cmd":"pip install cookies","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"This library is designed as a replacement for http.cookies and has a different API.","wrong":"from http.cookies import SimpleCookie","symbol":"Cookies","correct":"from cookies import Cookies"},{"symbol":"Cookie","correct":"from cookies import Cookie"}],"quickstart":{"code":"from cookies import Cookies, Cookie\n\n# Create a Cookies object for response headers\nresponse_cookies = Cookies()\nresponse_cookies['session_id'] = 'abc123def456'\nresponse_cookies['session_id'].path = '/'\nresponse_cookies['session_id'].max_age = 3600 # 1 hour\n\n# You can also set using a Cookie object directly\nmy_cookie = Cookie('user', 'guest')\nmy_cookie.domain = 'example.com'\nresponse_cookies.add(my_cookie)\n\nprint('Set-Cookie Headers:')\nfor header_line in response_cookies.render_response():\n    print(header_line)\n\n# Simulate receiving a Cookie header from a request\nrequest_header_string = 'session_id=abc123def456; other_data=some_value'\nrequest_cookies = Cookies.from_request(request_header_string)\n\nprint('\\nParsed Request Cookies:')\nfor name, cookie in request_cookies.items():\n    print(f\"  {name}: {cookie.value}\")\n\n# Access a specific cookie\nif 'session_id' in request_cookies:\n    print(f\"Session ID from request: {request_cookies['session_id'].value}\")\n","lang":"python","description":"Demonstrates creating, manipulating, and rendering 'Set-Cookie' headers, and parsing 'Cookie' request headers."},"warnings":[{"fix":"Do not treat this library as a drop-in replacement for `http.cookies`. Adapt your code to its distinct RFC 6265-compliant API.","message":"The 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.","severity":"breaking","affected_versions":"All versions"},{"fix":"For 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.","message":"The 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+).","severity":"deprecated","affected_versions":"All versions (since 2014)"},{"fix":"Do 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.","message":"The 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`).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `pip install cookies` was run correctly. If conflicts exist, rename your local script/module, or use a virtual environment. Confirm you are importing `Cookies` (capital C) and not `cookies` (lowercase c) from the package itself.","cause":"Attempting to use the `cookies` library in a Python environment where another module or package named 'cookies' exists or there's a typo in the import.","error":"ImportError: cannot import name 'Cookies' from 'cookies'"},{"fix":"Access cookie attributes using dot notation (e.g., `cookie.path = '/'`) directly on the `Cookie` object, as shown in the quickstart. The `Cookie` objects are not dictionaries themselves, though the `Cookies` collection object acts like a dictionary of `Cookie` objects.","cause":"Attempting to access cookie attributes in a way that differs from the library's API or attempting to use a `dict`-like access for attributes instead of direct attribute access.","error":"AttributeError: 'Cookie' object has no attribute 'expires' (or 'path', 'domain', etc.)"}]}