{"id":8428,"library":"placebo","title":"Placebo","description":"Placebo is a Python library designed to mock `boto3` calls, allowing developers to record actual AWS service responses and replay them later without interacting with real AWS endpoints. This is particularly useful for unit testing, offline development, and creating consistent test environments. The current version is 0.10.0. Releases have been sporadic, with a significant update to 0.10.0 after a nearly three-year gap, indicating active maintenance but not a fixed cadence.","status":"active","version":"0.10.0","language":"python","source_language":"en","source_url":"https://github.com/garnaat/placebo","tags":["boto3","testing","mocking","aws","offline","sdk"],"install":[{"cmd":"pip install placebo","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Placebo's purpose is to mock boto3 calls; it does not install boto3 itself, but its functionality is entirely dependent on boto3 being present in the environment where AWS calls are made.","package":"boto3","optional":true}],"imports":[{"wrong":"from placebo import attach","symbol":"attach","correct":"from placebo import attach"}],"quickstart":{"code":"import boto3\nimport placebo\nimport os\n\ndata_path = os.path.join(os.path.dirname(__file__), 'placebo_data')\nos.makedirs(data_path, exist_ok=True)\n\nsession = boto3.Session(region_name='us-east-1')\npill = placebo.attach(session, data_path=data_path)\n\n# --- Recording mode ---\n# Set PLACEBO_MODE=record in environment variables to enable recording\n# e.g., PLACEBO_MODE=record python your_script.py\nif os.environ.get('PLACEBO_MODE') == 'record':\n    print(\"Recording AWS calls...\")\n    pill.record()\n    s3 = session.client('s3')\n    try:\n        s3.list_buckets()\n        print(\"Buckets listed and recorded.\")\n    except Exception as e:\n        print(f\"Error during recording: {e}\")\n\n# --- Playback mode ---\n# Default behavior, or set PLACEBO_MODE=playback\n# e.g., PLACEBO_MODE=playback python your_script.py\nelse:\n    print(\"Playing back recorded AWS calls...\")\n    pill.playback()\n    s3 = session.client('s3')\n    try:\n        response = s3.list_buckets()\n        print(\"Buckets listed from recording:\")\n        for bucket in response.get('Buckets', []):\n            print(f\" - {bucket['Name']}\")\n    except Exception as e:\n        print(f\"Error during playback: {e}\")\n\n# Clean up (optional, for demonstration purposes)\n# import shutil\n# if os.path.exists(data_path):\n#     shutil.rmtree(data_path)\n","lang":"python","description":"This example demonstrates how to set up Placebo for both recording and playing back AWS API calls using `boto3`. It creates a `boto3` session, attaches Placebo to it with a specified data directory, and then, based on an environment variable, either records S3 `list_buckets` calls or plays them back from previously recorded JSON files."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.x (e.g., Python 3.6+ is recommended by Placebo's PyPI classifiers).","message":"Placebo version 0.10.0, released in September 2021, officially dropped support for Python 2.x. Codebases still on Python 2.x will need to upgrade to Python 3.x to use this and future versions.","severity":"breaking","affected_versions":">=0.10.0"},{"fix":"Upgrade to Placebo version 0.10.0 or later to ensure correct handling of binary response bodies.","message":"Older versions of Placebo (prior to 0.10.0) had a bug handling binary response bodies from AWS services, which could lead to incorrect data or errors during playback.","severity":"gotcha","affected_versions":"<0.10.0"},{"fix":"Explicitly initialize the default session with `boto3.setup_default_session()` before attaching Placebo, or, preferably, create and pass a named `boto3.Session()` object to `placebo.attach()` for clearer scope.","message":"When using `boto3.DEFAULT_SESSION`, Placebo may not correctly attach unless `boto3.setup_default_session()` is explicitly called beforehand. If you create `boto3` clients from a default session that hasn't been set up, Placebo might not intercept calls.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always call `pill.record()` or `pill.playback()` on the `Pill` object *before* creating any `boto3` clients from the associated session that you intend to mock.","message":"Clients created from a `boto3.Session` *before* `pill.record()` or `pill.playback()` is called might not be 'placebo-aware' and will still make live AWS calls. This was a bug fixed in 0.7.2, but misunderstanding the order of operations can still cause issues.","severity":"gotcha","affected_versions":"<0.7.2, and a potential user error in later versions"}],"env_vars":null,"search_vec":"'0.10.0':48,58 'activ':67 'actual':16 'allow':12 'aw':17,28,77 'boto3':10,74 'cadenc':73 'call':11 'consist':41 'creat':40 'current':45 'design':7 'develop':13,38 'endpoint':29 'environ':43 'fix':72 'gap':65 'indic':66 'interact':25 'later':23 'librari':6 'mainten':68 'mock':9,76 'near':61 'offlin':37,78 'particular':32 'placebo':1,2 'python':5 'real':27 'record':15 'releas':49 'replay':21 'respons':19 'sdk':79 'servic':18 'signific':55 'sporad':52 'test':36,42,75 'three':63 'three-year':62 'unit':35 'updat':56 'use':33 'version':46 'without':24 'year':64","created_at":"2026-04-16T17:02:08.694216+00:00","updated_at":"2026-04-16T17:02:08.694216+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmp3we309zt/venv/lib/python3.12/site-packages/placebo/__init__.py\", line 15, in <module>\n    from placebo.pill import Pill\n  File \"/tmp/tmp3we309zt/venv/lib/python3.12/site-packages/placebo/pill.py\", line 21, in <"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.10.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/garnaat/placebo","docs":null,"changelog":null,"pypi":"https://pypi.org/project/placebo/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","aws","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}