{"id":6396,"library":"macaroonbakery","title":"Macaroon Bakery","description":"macaroonbakery is a Python library that provides higher-level operations for working with macaroons, building upon the core `pymacaroons` library. It implements the httpbakery conventions, allowing for automatic gathering of discharge macaroons for third-party caveats. The library is currently at version 1.3.4 and, while listed as '2 - Pre-Alpha' on PyPI, shows recent activity on its GitHub repository, suggesting active maintenance.","status":"active","version":"1.3.4","language":"en","source_language":"en","source_url":"https://github.com/go-macaroon-bakery/py-macaroon-bakery","tags":["macaroon","cookie","security","authentication","authorization","httpbakery"],"install":[{"cmd":"pip install macaroonbakery","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for HTTP interactions, especially with BakeryAuth.","package":"requests","optional":false},{"reason":"Python bindings to libsodium, a cryptographic library.","package":"PyNaCl","optional":false},{"reason":"Core macaroon implementation that macaroonbakery builds upon.","package":"pymacaroons","optional":false},{"reason":"Python 2 and 3 compatibility library.","package":"six","optional":false},{"reason":"Used for Protocol Buffer serialization/deserialization.","package":"protobuf","optional":false},{"reason":"Parser and generator of RFC 3339-compliant timestamps.","package":"pyRFC3339","optional":false}],"imports":[{"note":"The primary module for interacting with the HTTP bakery.","symbol":"httpbakery","correct":"from macaroonbakery import httpbakery"},{"note":"The class used for authenticating requests with macaroon bakery.","symbol":"BakeryAuth","correct":"from macaroonbakery.httpbakery import BakeryAuth"}],"quickstart":{"code":"import requests\nfrom macaroonbakery import httpbakery\nimport os\n\n# A placeholder for a URL protected by a macaroon bakery service.\n# In a real application, this would be a URL to your service.\nPROTECTED_URL = os.environ.get('MACAROON_PROTECTED_URL', 'http://localhost:8080/protected')\n\n# Initialize a RequestsCookieJar to store macaroons\njar = requests.cookies.RequestsCookieJar()\n\ntry:\n    # Make a request using BakeryAuth. It will handle macaroon acquisition.\n    # For the first request, it might redirect to an authentication service.\n    resp = requests.get(\n        PROTECTED_URL,\n        cookies=jar,\n        auth=httpbakery.BakeryAuth(cookies=jar)\n    )\n    resp.raise_for_status() # Raise an exception for HTTP errors\n\n    print(f\"Successfully accessed {PROTECTED_URL}. Response: {resp.text[:100]}...\")\n    # Subsequent requests will reuse the macaroons in the jar\n\nexcept requests.exceptions.HTTPError as e:\n    print(f\"HTTP Error: {e.response.status_code} - {e.response.text}\")\nexcept requests.exceptions.RequestException as e:\n    print(f\"Request failed: {e}\")","lang":"python","description":"This quickstart demonstrates how to use `macaroonbakery.httpbakery.BakeryAuth` to interact with a protected URL. It automatically manages the acquisition and storage of macaroons using a `RequestsCookieJar`. The `PROTECTED_URL` should be replaced with an actual endpoint that uses macaroon-based authentication. The first request might trigger a redirection to an authentication provider, which `BakeryAuth` is designed to handle."},"warnings":[{"fix":"Review release notes for each update. Pin to exact versions for production use and thoroughly test upgrades.","message":"The library's PyPI status is '2 - Pre-Alpha', indicating that its API may not be stable and could change without adhering to strict semantic versioning. Users should expect potential breaking changes in minor or patch releases.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of the upstream dependency's status. Monitor both macaroonbakery and pymacaroons for updates or potential issues.","message":"macaroonbakery relies heavily on `pymacaroons` for its core macaroon functionality. The `pymacaroons` library appears to be less actively maintained (last release Feb 2018), which could limit new features or delay critical updates for macaroonbakery.","severity":"gotcha","affected_versions":"All versions"},{"fix":"It is strongly recommended to use `macaroonbakery` with Python 3.5+ to ensure compatibility and benefit from ongoing support.","message":"While `setup.py` indicates compatibility with Python 2.7, modern Python development primarily targets Python 3. Using `macaroonbakery` with Python 2.7 might lead to compatibility issues with other libraries or a lack of future support.","severity":"gotcha","affected_versions":"<=1.3.4 (Python 2.7)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}