Instant mock API server from an OpenAPI/Swagger spec, JSON file, or Postman collection.
Project description
phantom-api
Spin up a fully functional mock API server in seconds — from an OpenAPI spec, a JSON file, or a Postman collection.
Install · Quick start · Features · CLI · Comparison
Frontend developers shouldn't have to wait for the backend. phantom-api turns any API description into a running mock server with realistic fake data, latency simulation, error injection, and record/replay — no cloud account, no Java, no boilerplate.
Install
pip install phantomapi-server
Requires Python 3.10+.
Quick start
# From an OpenAPI / Swagger spec
phantom-api serve petstore.yaml
# From a JSON file (auto-generates CRUD endpoints)
phantom-api serve users.json
# From a Postman collection
phantom-api serve collection.json --type postman
╭───────────────── phantom-api - Mock Server Running ─────────────────╮
│ http://127.0.0.1:3000 │
│ Source: petstore.yaml (openapi) │
│ Routes: 4 Delay: 0ms │
╰─────────────────────────────────────────────────────────────────────╯
Features
| Feature | Description |
|---|---|
| From OpenAPI | Parse OpenAPI 3.x / Swagger 2.0 → full mock server |
| From JSON | Drop a JSON file → instant CRUD endpoints |
| From Postman | Import Postman Collection v2.1 → mock all requests |
| Fake data | Schema-aware generation (format, pattern, and field-name aware) via Faker |
| Custom delays | Simulate latency globally or per request |
| Error simulation | Return 4xx/5xx by header or query param |
| Record & replay | Proxy a real API, record responses, replay offline |
| Hot reload | Watch the spec file and rebuild routes on change |
| Admin dashboard | Inspect routes and request stats at /__admin |
CLI
phantom-api serve spec.yaml # start a mock server
phantom-api serve spec.yaml --port 4000 # custom port
phantom-api serve spec.yaml --host 0.0.0.0 # expose beyond localhost (opt-in)
phantom-api serve spec.yaml --delay 200ms # add latency
phantom-api serve spec.yaml --watch # hot reload on changes
phantom-api serve spec.yaml --seed 42 # deterministic fake data
phantom-api record https://api.example.com -o recordings/ # record
phantom-api replay recordings/ # replay offline
phantom-api routes spec.yaml # list generated routes
phantom-api validate spec.yaml # validate without serving
Per-request controls
| Control | Header | Query |
|---|---|---|
| Latency (ms) | X-Mock-Delay: 250 |
?__delay=250 |
| Force error | X-Mock-Status: 503 |
?__status=503 |
curl "http://127.0.0.1:3000/pets?__status=503" # → 503 error body
curl "http://127.0.0.1:3000/pets?__delay=500" # → 500ms latency
Admin endpoints
| Method | Path | Description |
|---|---|---|
| GET | /__admin/routes |
List all generated routes |
| GET | /__admin/stats |
Request statistics and uptime |
| POST | /__admin/reset |
Reset statistics |
Run in Docker
Run a mock server anywhere — CI, a shared dev box, or production-like environments —
without installing Python. The image binds to 0.0.0.0:3000 inside the container.
# Build the image
docker build -t phantom-api .
# Serve a spec by mounting it into /spec
docker run --rm -p 3000:3000 \
-v "$PWD/openapi.json:/spec/openapi.json:ro" \
phantom-api serve /spec/openapi.json --type openapi --seed 42
Or use the published image from Docker Hub:
docker run --rm -p 3000:3000 \
-v "$PWD/openapi.json:/spec/openapi.json:ro" \
fazorboy/phantom-api serve /spec/openapi.json
docker compose
A ready-made docker-compose.yml serves a mounted spec (defaulting to
the Morpheus mock). Point it at any single-file spec with SPEC_FILE:
SPEC_FILE=./openapi.json docker compose up --build
curl http://localhost:3000/__admin/routes
The container reads PHANTOM_API_HOST and PHANTOM_API_PORT (default 0.0.0.0 / 3000),
so the same environment variables configure the server locally too.
Multi-file specs (a root
openapi.yamlthat$refs intopaths/andcomponents/) must first be bundled into a single self-contained file. See Turn any OpenAPI repo into a mock.
Turn any OpenAPI repo into a mock
Many API projects (for example HewlettPackard/morpheus-openapi) publish a multi-file OpenAPI spec plus example JSONs. To serve one:
# 1. Bundle the multi-file spec into a single dereferenced file (Redocly)
npx @redocly/cli bundle openapi.yaml -o bundled.json --dereferenced
# 2. Inline any example $refs that Redocly leaves inside example values
python skills/openapi-mock-server/inline_example_refs.py bundled.json --base . -o mock.json
# 3. Serve it (locally or in Docker)
phantom-api serve mock.json --type openapi --seed 42
The bundled openapi-mock-server skill automates this end to end — fetching the repo,
detecting its build tooling, bundling, inlining examples, and starting the server locally
or in a container. See skills/openapi-mock-server/SKILL.md.
Fake data generation
phantom-api maps schema fragments to realistic values, in priority order:
- Spec examples — any
examplein the schema or response is used verbatim. - Semantic match —
format: email→ an address,format: uuid→ a UUID, a field namedfirst_name→ a first name,pattern→ a matching string. - Type fallback — bounded integers, floats, booleans, arrays, and nested objects.
Pass --seed for reproducible output in CI.
Comparison
| phantom-api | Prism | WireMock | Postman Mock | |
|---|---|---|---|---|
| Single-command start | ✅ | ✅ | ⚠️ | ⚠️ |
| No runtime beyond Python | ✅ | ❌ (Node) | ❌ (Java) | ❌ (cloud) |
| OpenAPI + Swagger | ✅ | ✅ | ⚠️ | ⚠️ |
| JSON → CRUD | ✅ | ❌ | ❌ | ❌ |
| Postman collections | ✅ | ❌ | ❌ | ✅ |
| Record & replay | ✅ | ⚠️ | ✅ | ❌ |
| Offline / no account | ✅ | ✅ | ✅ | ❌ |
Security
- Binds to
127.0.0.1by default; exposing the server requires an explicit--host. - Specs are validated and never executed;
$refresolution is cycle-safe and refuses external references. - Recordings use hash-based filenames confined to the output directory (no path traversal).
- Resource limits: max 10,000 routes and 64 MB spec files.
Development
pip install -e ".[dev]"
ruff check src/ tests/
pytest --cov=src/phantom_api
See docs/CONTRIBUTING.md for details.
License
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 phantomapi_server-1.1.0.tar.gz.
File metadata
- Download URL: phantomapi_server-1.1.0.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26ddc84a813eff05866b3ca1352ba2eaf1898a0fbd8a32a0d3575e9d881a169d
|
|
| MD5 |
359642c436a94e698e06545fc75f2d40
|
|
| BLAKE2b-256 |
2e2a4c984d2c199e7ea40f96ab5b881f5937c67336087088e926f2324b82d82c
|
Provenance
The following attestation bundles were made for phantomapi_server-1.1.0.tar.gz:
Publisher:
release.yml on bhayanak/phantom-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phantomapi_server-1.1.0.tar.gz -
Subject digest:
26ddc84a813eff05866b3ca1352ba2eaf1898a0fbd8a32a0d3575e9d881a169d - Sigstore transparency entry: 2194803163
- Sigstore integration time:
-
Permalink:
bhayanak/phantom-api@f31f7f9ac26072abffb316a30b429b1653ecb361 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/bhayanak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f31f7f9ac26072abffb316a30b429b1653ecb361 -
Trigger Event:
push
-
Statement type:
File details
Details for the file phantomapi_server-1.1.0-py3-none-any.whl.
File metadata
- Download URL: phantomapi_server-1.1.0-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1661bade381f54c0e241d9e2842cda1dace1daee0c74da4edb3d637564c50eaf
|
|
| MD5 |
feb20502fffbc20f9eb04c63023680a9
|
|
| BLAKE2b-256 |
6120a7d46e7fec317d0f9bbdd86dd1ec0e17c77d75dde1ea377d9dded126b9b4
|
Provenance
The following attestation bundles were made for phantomapi_server-1.1.0-py3-none-any.whl:
Publisher:
release.yml on bhayanak/phantom-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phantomapi_server-1.1.0-py3-none-any.whl -
Subject digest:
1661bade381f54c0e241d9e2842cda1dace1daee0c74da4edb3d637564c50eaf - Sigstore transparency entry: 2194803171
- Sigstore integration time:
-
Permalink:
bhayanak/phantom-api@f31f7f9ac26072abffb316a30b429b1653ecb361 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/bhayanak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f31f7f9ac26072abffb316a30b429b1653ecb361 -
Trigger Event:
push
-
Statement type: