VCR recording, sanitization, and validation for Keboola component HTTP interactions
Project description
keboola.vcr
VCR recording, sanitization, and validation for Keboola component HTTP interactions.
Installation
pip install keboola.vcr
Usage
from keboola.vcr.recorder import VCRRecorder
from keboola.vcr.sanitizers import DefaultSanitizer
recorder = VCRRecorder(
cassette_dir="tests/cassettes/my_test",
secrets={"api_key": "secret"},
)
Features
- Recording: Captures real HTTP interactions via vcrpy and stores them as JSON cassettes
- Sanitization: Redacts secrets, tokens, and sensitive fields before saving cassettes
- Scaffolding: Generates test directory structures from component config definitions
- Validation: Compares output snapshots to detect regressions
Sanitizing data before the component reads it
By default, sanitizers scrub the cassette only — during recording the
component still receives the real API response, so real values can end up in the
component's output tables. To stop real customer data from ever reaching the
component, tag a sanitizer with scrub_before_read=True. The recorder then
redacts those fields in the response before the component reads them, so the
output is clean regardless of format (CSV, Parquet, or direct-to-Storage).
# tests/.../sanitizers.py
from keboola.vcr import BodyFieldSanitizer
def get_sanitizers(config):
return [
# PII the component only reads and emits → redacted before the component reads it
BodyFieldSanitizer(fields=["customer_name", "email", "phone"], scrub_before_read=True),
]
Rule: only tag fields the component consumes and emits. Never tag a value the component sends back to the live API during recording — a pagination cursor, an async job ID, or an OAuth token — because it must stay real for the follow-up request to succeed. Token/secret sanitizers stay untagged (cassette-only) for exactly this reason. If a redacted value is sent to the live API, recording aborts with an error naming the tagged sanitizer(s) so you can find and untag the offending field.
Caution: only tag field-scoped body sanitizers (e.g. BodyFieldSanitizer)
with scrub_before_read. Do not tag whole-response sanitizers like
DefaultSanitizer or HeaderSanitizer — their header whitelisting would also
apply to the component-visible response during recording, and can strip
pagination or rate-limit headers the component needs to keep working.
Development
uv sync --all-groups
uv run pytest tests/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keboola_vcr-0.7.0.tar.gz.
File metadata
- Download URL: keboola_vcr-0.7.0.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
331d2d23a8910370e5db9758209148fea71be5986c0a89bde82b3ed098126587
|
|
| MD5 |
fd07075575e3d022c851942432a993b0
|
|
| BLAKE2b-256 |
d8967111329bf1afe656c065d758e780dec0d94101f0431b039b7d3d6512760c
|
File details
Details for the file keboola_vcr-0.7.0-py3-none-any.whl.
File metadata
- Download URL: keboola_vcr-0.7.0-py3-none-any.whl
- Upload date:
- Size: 48.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a370b143bfe25c02de3ab9c6bd3473534c9a211bc702bf6e4f3b87a775e497f1
|
|
| MD5 |
8b80a2193e42c379f02f7f7250a6e9ec
|
|
| BLAKE2b-256 |
4c4163164c22088443e30c9b0ead8739bd94879549bcf6e6147d26b68ef66edd
|