MockAPI
Generate and run local mock API servers from small JSON/YAML specs.
MockAPI is a terminal-first mock API generator for frontend development, integration testing, demos, and API contract prototyping. It turns compact JSON/YAML specs into working Flask routes, can generate REST-style resource specs with realistic Faker data, previews route responses without starting a server, validates duplicate routes and status codes, and exports OpenAPI documents for downstream tooling.
- Spec-driven mock servers - run GET, POST, PUT, PATCH, DELETE, OPTIONS, and HEAD routes from JSON or YAML.
- REST resource generation - scaffold list, detail, create, update, patch, and delete endpoints with realistic sample data.
- Dynamic response templates - use placeholders such as
{{ name }},{{ uuid }},{{ body.email }}, and{{ path.id }}. - OpenAPI export - turn a mock spec into a portable OpenAPI 3 document.
- Fast local previews - inspect, validate, and request mock responses directly from the CLI.
- Clean terminal output - Rich tables, panels, syntax highlighting, and readable validation errors.
Installation
pip install mockapi-cli
The installed console command is:
mockapi --help
Usage
Create a starter spec:
mockapi init mockapi.yaml --resource users
Generate a richer resource:
mockapi generate shop.yaml --resource products --field id:id --field name:word --field price:float --field in_stock:bool
Inspect and validate it:
mockapi inspect shop.yaml
mockapi validate shop.yaml
Preview a route without starting a server:
mockapi request shop.yaml GET /products/42
mockapi request shop.yaml POST /products --body '{"name":"Keyboard","price":89.9}'
Run the local API:
mockapi serve shop.yaml --port 8080
Export an OpenAPI document:
mockapi openapi shop.yaml --output openapi.json
Commands
| Command | Description | Example |
|---|---|---|
mockapi init [path] |
Create a starter YAML spec. | mockapi init mockapi.yaml --resource users |
mockapi generate <output> |
Generate CRUD-style REST routes with fake data. | mockapi generate api.yaml --resource orders --count 10 |
mockapi serve <spec> |
Start a Flask mock API server. | mockapi serve api.yaml --port 8080 |
mockapi inspect <spec> |
Show API metadata and route summaries. | mockapi inspect api.yaml |
mockapi validate <spec> |
Validate methods, paths, status codes, and duplicate routes. | mockapi validate api.yaml |
mockapi sample <resource> |
Generate fake records as JSON or a table. | mockapi sample users --field email:email --count 3 |
mockapi request <spec> <method> <path> |
Render a mock response without a server. | mockapi request api.yaml GET /orders/1 |
mockapi openapi <spec> |
Export an OpenAPI 3 document. | mockapi openapi api.yaml -o openapi.json |
mockapi export <spec> |
Normalize and convert a spec to JSON or YAML. | mockapi export api.yaml --to json -o api.json |
Configuration
MockAPI specs are plain YAML or JSON files. A route includes an HTTP method, path, status code, optional headers, and response body.
name: Example API
version: 1.0.0
cors: true
routes:
- method: GET
path: /users/{id}
status: 200
response:
id: "{{ path.id }}"
name: "{{ name }}"
email: "{{ email }}"
- method: POST
path: /users
status: 201
response:
id: "{{ uuid }}"
email: "{{ body.email }}"
Supported placeholder sources include Faker fields ({{ name }}, {{ email }}, {{ city }}), generated values ({{ uuid }}, {{ int }}, {{ bool }}), request body fields ({{ body.name }}), query parameters ({{ query.page }}), headers ({{ headers.Authorization }}), and route parameters ({{ path.id }}).
License
MIT License. See LICENSE.
Metadata
Release files for mockapi-cli 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mockapi_cli-0.1.0.tar.gz | 14.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mockapi_cli-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.0 kB
Release files / mockapi_cli-0.1.0.tar.gz
| Download URL | mockapi_cli-0.1.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ccda1dbbeac66a1f4a3d7fde49dda866c76fc3e97a113bc759e747bdc7a3e0f
|
|
BLAKE2b-256 checksum How to use checksums |
4ee65e207d89ead38186aaa355370a860707ba00cee160473b0471e7c8d2b3a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Release files / mockapi_cli-0.1.0-py3-none-any.whl
| Download URL | mockapi_cli-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e48aef4358604a1f3b2ef316d993ca0ea087a1df0eb84aec240a9d6bad42065b
|
|
BLAKE2b-256 checksum How to use checksums |
bce5b879876553bf0e4742f3c17ca276fa67c1de5f440003cdca518ab8b483bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|