Registry / testing / wiremock

wiremock

JSON →
library2.7.0pypypi✓ verified 84d ago

The `wiremock` library provides a Python client for the WireMock Admin API, enabling programmatic control and configuration of WireMock standalone servers. It allows developers to define stub mappings, reset server state, and verify requests from Python tests or scripts. The current version is 2.7.0, with an active release cadence, often aligning with updates to the WireMock Java core.

pip install wiremock
INSTALL
IMPORT
SIG · WIREMOCK
W
wiremock
testingpythonv2.7.0
Install
2.5s avg
Import
—
Disk
35MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.7.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.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 37.1MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 2.5s · import 0.000s · 38MB
35MB installed
● package 35MB
Code
Verified usage

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

f
✓ from wiremock import f
✗ from wiremock.client import WireMockClient
os
✓ from wiremock import os
✗ from wiremock.client import WireMockClient

This quickstart demonstrates how to connect to a WireMock server, clear existing stubs, define a new GET stub for `/hello`, and then verify it by making an HTTP request. Ensure a WireMock Java server is running independently before executing this code.

import os import requests from wiremock.client import WireMockClient, MappingBuilder, ResponseDefinitionBuilder, HttpMethods # The URL where your WireMock server is running. Make sure it's started! # Example: `java -jar wiremock-standalone-2.35.0.jar --port 8080` WIREMOCK_BASE_URL = os.environ.get('WIREMOCK_URL', 'http://localhost:8080') client = WireMockClient(base_url=WIREMOCK_BASE_URL) print(f"Connected to WireMock at {WIREMOCK_BASE_URL}") # 1. Clear all existing stub mappings for a clean slate client.reset_mappings() print("All previous stub mappings cleared.") # 2. Define a new stub mapping for a GET request to /hello hello_stub = MappingBuilder.get(url_path='/hello') \ .will_return( ResponseDefinitionBuilder.response() \ .with_status(200) \ .with_header('Content-Type', 'text/plain') \ .with_body('Hello from WireMock!') ) \ .build() client.create_mapping(hello_stub) print("Stub for GET /hello created.") # 3. Verify the stub by making a request to the WireMock instance try: response = requests.get(f"{WIREMOCK_BASE_URL}/hello") print(f"Request to /hello received status: {response.status_code}") print(f"Response body: {response.text}") assert response.status_code == 200 assert response.text == 'Hello from WireMock!' print("Stub verified successfully!") except requests.exceptions.ConnectionError as e: print(f"Error: Could not connect to WireMock server at {WIREMOCK_BASE_URL}. Is it running?") print(f"Details: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") # Optional: Clean up after verification # client.reset_mappings() # print("All stub mappings cleared again.")
Debug
Known issues
breakingVersion 2.0.0 introduced significant breaking changes, including renaming `AdminClient` to `WireMockClient` and a complete overhaul of the API for defining stub mappings.
fix
Migrate your code to use `WireMockClient` and the new fluent API for `MappingBuilder` and `ResponseDefinitionBuilder`. Refer to the official documentation for migration guides.
affects: >=2.0.0
gotchaThe `wiremock` Python client controls a WireMock server; it does not start or manage the server itself. You must have a WireMock Java server running independently (e.g., via JAR, Docker, or standalone). Failure to start the WireMock server will result in `ConnectionError`.
fix
Before running your Python code, ensure your WireMock server is active and accessible at the specified `base_url`. Common ways to run it include `java -jar wiremock-standalone-2.35.0.jar --port 8080` or using a Docker container.
affects: All
gotchaWhen defining stub mappings, it's crucial to call `.build()` at the end of the `MappingBuilder` chain to finalize the mapping object before passing it to `client.create_mapping()`. Forgetting `.build()` will lead to incorrect object types or `AttributeError`.
fix
Always terminate your `MappingBuilder` and `ResponseDefinitionBuilder` fluent calls with `.build()`. For example: `MappingBuilder.get(...).will_return(ResponseDefinitionBuilder.response()...).build()`.
affects: All
gotchaWhen running tests, stubs defined in previous tests can interfere with subsequent ones, leading to flaky results. It's good practice to clear WireMock's state between tests.
fix
Use `client.reset_mappings()` to clear only stub mappings, or `client.reset_all()` to clear mappings, requests, and scenarios. This is often done in a `setUp` or `tearDown` method of your test runner.
affects: All
gotchaThe Python client's features and compatibility are tied to the version of the WireMock Java Admin API. New features in the Java server might not be immediately available or fully supported by older Python client versions.
fix
Keep both your WireMock Python client and WireMock Java server reasonably up-to-date. If encountering issues with new WireMock features, check the `wiremock-python` changelog and the WireMock Java documentation for compatibility notes.
affects: All
Upgrade
Version history
2.7.0latest on PyPI · released Jul 28, 2025
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the WireMock Admin API and for verifying stubs.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
wiremock — pip install wiremock · libregistry