English | 日本語
mockserv is a zero-dependency (runtime) CLI tool that spins up a local HTTP mock server from your OpenAPI 3.x or JSON Schema files using only Python's stdlib http.server.
No Node.js. No Docker. No manual stub writing. Just point it at your spec and start mocking.
- OpenAPI 3.x & JSON Schema support -- Load
.yaml,.yml, or.jsonspecs - Realistic mock responses -- Generated from
example, type inference, and format hints - Custom response overrides -- Override any endpoint with a simple YAML file
- Latency simulation -- Add artificial delays to simulate real-world network conditions
- Request logging -- Log to stdout or write structured JSON Lines for test assertions
- CORS enabled -- Ready for frontend development out of the box
- Zero runtime dependencies -- Only
pyyamlis required; everything else is stdlib
pip install mockservOr install from source:
git clone https://github.com/izag8216/mockserv.git
cd mockserv
pip install -e .mockserv start petstore.yaml --port 8080Your mock server is now running at http://localhost:8080.
mockserv start user.json --port 8080Auto-generated endpoints: GET /users, POST /users, GET /users/{id}, etc.
mockserv start api.yaml --delay 200Every response will have a 200ms artificial delay.
Create overrides.yaml:
"/pets:get:200":
- id: 99
name: Custom Pet
tag: dogThen run:
mockserv start petstore.yaml --responses overrides.yamlmockserv start api.yaml --log --log-file requests.jsonlmockserv start <spec> [options]
--port PORT Server port (default: 8080)
--delay MS Latency in milliseconds (default: 0)
--responses FILE YAML file with custom response overrides
--log Enable stdout request logging
--log-file FILE Write JSON Lines request log
mockserv validate <spec> [options]
--strict Validate schemas against meta-schema
Priority order:
- Custom override (
--responses) examplefield in schemaexamplesarray (first item)defaultfield- Type inference:
string->"string"(or format-aware: email, uri, uuid, date, etc.)integer->0number->0.0boolean->truearray->[](withitemspopulated)object->{}(withrequiredfields populated)
mockserv/
src/mockserv/ # Core implementation
tests/ # pytest suite
examples/ # Sample specs
docs/ # Detailed documentation
See CONTRIBUTING.md.
MIT License (c) 2024 izag8216