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 wiremockVerified import paths — ran on the pinned version, not inferred.
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.
Migrate your code to use `WireMockClient` and the new fluent API for `MappingBuilder` and `ResponseDefinitionBuilder`. Refer to the official documentation for migration guides.
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.
Always terminate your `MappingBuilder` and `ResponseDefinitionBuilder` fluent calls with `.build()`. For example: `MappingBuilder.get(...).will_return(ResponseDefinitionBuilder.response()...).build()`.
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.
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.