Record and replay gRPC interactions for testing
Project description
grpcvcr
Record and replay gRPC interactions for testing - like VCR.py but for gRPC.
Installation
pip install grpcvcr
Quick Start
from grpcvcr import recorded_channel, RecordMode
# Record on first run, replay on subsequent runs
with recorded_channel("tests/cassettes/my_test.yaml", "localhost:50051") as channel:
stub = MyServiceStub(channel)
response = stub.GetUser(GetUserRequest(id=1))
assert response.name == "Alice"
Features
- Record & Replay: Automatically record gRPC interactions and replay them in tests
- All RPC Types: Supports unary, server streaming, client streaming, and bidirectional streaming
- Async Support: Full support for
grpc.aioasync clients - pytest Integration: Built-in fixtures and markers for easy test integration
- Flexible Matching: Match requests by method, metadata, body, or custom logic
- Multiple Formats: Store cassettes as YAML or JSON
Recording Modes
| Mode | Description |
|---|---|
NEW_EPISODES |
Play existing, record new (default) |
NONE |
Playback only - fail if no match |
ALL |
Always record, overwrite existing |
ONCE |
Record if cassette missing, then playback |
Async Support
from grpcvcr import AsyncRecordingChannel, Cassette, RecordMode
cassette = Cassette("test.yaml", record_mode=RecordMode.ALL)
async with AsyncRecordingChannel(cassette, "localhost:50051") as recording:
stub = MyServiceStub(recording.channel)
response = await stub.GetUser(GetUserRequest(id=1))
pytest Integration
import pytest
from grpcvcr import RecordMode
@pytest.mark.grpcvcr(cassette="user_test.yaml", record_mode=RecordMode.NONE)
def test_get_user(grpcvcr_cassette):
from grpcvcr import RecordingChannel
with RecordingChannel(grpcvcr_cassette, "localhost:50051") as rc:
stub = MyServiceStub(rc.channel)
response = stub.GetUser(GetUserRequest(id=1))
assert response.name == "Alice"
Run in record mode:
pytest --grpcvcr-record=new_episodes
Run in strict playback mode (CI):
pytest --grpcvcr-record=none
Request Matching
from grpcvcr import recorded_channel, MethodMatcher, RequestMatcher, MetadataMatcher
# Match on method + request body
matcher = MethodMatcher() & RequestMatcher()
with recorded_channel("test.yaml", "localhost:50051", match_on=matcher) as channel:
...
# Ignore certain metadata keys
matcher = MethodMatcher() & MetadataMatcher(ignore_keys=["x-request-id"])
License
MIT
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 grpcvcr-0.1.1.tar.gz.
File metadata
- Download URL: grpcvcr-0.1.1.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
497b4df603a6da059f15155a791868c4304cc7a929dbb98f0bfd131a193a723e
|
|
| MD5 |
cfd3688174d0f978946a0817ef1bab25
|
|
| BLAKE2b-256 |
0734edcd7e12171c7cf8df3f7a0b9dcc60a10281b5b9f43d2ef3d399a7c77637
|
Provenance
The following attestation bundles were made for grpcvcr-0.1.1.tar.gz:
Publisher:
release.yml on tboser/grpcvcr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grpcvcr-0.1.1.tar.gz -
Subject digest:
497b4df603a6da059f15155a791868c4304cc7a929dbb98f0bfd131a193a723e - Sigstore transparency entry: 867748497
- Sigstore integration time:
-
Permalink:
tboser/grpcvcr@d77cfad728c20cb7f1d586948bad4b844f1ae74a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tboser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d77cfad728c20cb7f1d586948bad4b844f1ae74a -
Trigger Event:
push
-
Statement type:
File details
Details for the file grpcvcr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: grpcvcr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f31ee97f5cb4ef76ad9d1da1c88e3722308eebfaeeff856591e7865d33da315b
|
|
| MD5 |
4cfe4cd363e2305c10191f724d6bda8d
|
|
| BLAKE2b-256 |
f856038dd09592ab290ac45cfd933b488080343162a8e1943b6afec8e947999a
|
Provenance
The following attestation bundles were made for grpcvcr-0.1.1-py3-none-any.whl:
Publisher:
release.yml on tboser/grpcvcr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grpcvcr-0.1.1-py3-none-any.whl -
Subject digest:
f31ee97f5cb4ef76ad9d1da1c88e3722308eebfaeeff856591e7865d33da315b - Sigstore transparency entry: 867748509
- Sigstore integration time:
-
Permalink:
tboser/grpcvcr@d77cfad728c20cb7f1d586948bad4b844f1ae74a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tboser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d77cfad728c20cb7f1d586948bad4b844f1ae74a -
Trigger Event:
push
-
Statement type: