Skip to main content

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/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keboola_vcr-0.7.1.tar.gz (45.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keboola_vcr-0.7.1-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file keboola_vcr-0.7.1.tar.gz.

File metadata

  • Download URL: keboola_vcr-0.7.1.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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

Hashes for keboola_vcr-0.7.1.tar.gz
Algorithm Hash digest
SHA256 1f4f4557dae473ec43375da46bd69677d78b5fcabd48d443158b5c47771c70d7
MD5 f37e9d5af99c2c14d99375474d810350
BLAKE2b-256 3271abef1086ea6953fa01ab722eeb5c899f31604f2c739ed3a6b8b2f071d76d

See more details on using hashes here.

File details

Details for the file keboola_vcr-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: keboola_vcr-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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

Hashes for keboola_vcr-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71c6dd1589199b2873a971d9c5409d2ba452ff174b31bffe5e18c8a8091ab1af
MD5 9dff5a5041e7a97464b7527cb521c52f
BLAKE2b-256 6e892d320232cefc3cc5d7142857f0eb3ac9e3e020fcd9eec0efb43b4205e9b4

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.5

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page