Registry / testing / placebo

placebo

JSON →
library0.10.0pypypiunverified

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.

pip install placebo
INSTALL
IMPORT
SIG · PLACEBO
P
placebo
testingpythonv0.10.0
Install
2.7s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.10.0 · 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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.7s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

attach
from placebo import attach
from placebo import attach

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.

import boto3 import placebo import os data_path = os.path.join(os.path.dirname(__file__), 'placebo_data') os.makedirs(data_path, exist_ok=True) session = boto3.Session(region_name='us-east-1') pill = placebo.attach(session, data_path=data_path) # --- Recording mode --- # Set PLACEBO_MODE=record in environment variables to enable recording # e.g., PLACEBO_MODE=record python your_script.py if os.environ.get('PLACEBO_MODE') == 'record': print("Recording AWS calls...") pill.record() s3 = session.client('s3') try: s3.list_buckets() print("Buckets listed and recorded.") except Exception as e: print(f"Error during recording: {e}") # --- Playback mode --- # Default behavior, or set PLACEBO_MODE=playback # e.g., PLACEBO_MODE=playback python your_script.py else: print("Playing back recorded AWS calls...") pill.playback() s3 = session.client('s3') try: response = s3.list_buckets() print("Buckets listed from recording:") for bucket in response.get('Buckets', []): print(f" - {bucket['Name']}") except Exception as e: print(f"Error during playback: {e}") # Clean up (optional, for demonstration purposes) # import shutil # if os.path.exists(data_path): # shutil.rmtree(data_path)
Debug
Known issues
breakingPlacebo 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.
fix
Upgrade your Python environment to Python 3.x (e.g., Python 3.6+ is recommended by Placebo's PyPI classifiers).
affects: >=0.10.0
gotchaOlder 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.
fix
Upgrade to Placebo version 0.10.0 or later to ensure correct handling of binary response bodies.
affects: <0.10.0
gotchaWhen 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.
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.
affects: All versions
gotchaClients 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.
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.
affects: <0.7.2, and a potential user error in later versions
Upgrade
Version history
0.10.0latest on PyPI · released Sep 28, 2021
Audit
Dependencies
boto3optionalPlacebo'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.
Agent activity
26 hits · last 30 days
node
24
Amazon
1
Resources
placebo — pip install placebo · libregistry