Spin up a fake REST API from JSON/CSV with zero code.
Project description
Data Server
Spin up a fake REST API from a JSON or CSV file with zero framework setup.
Data Server reads your file, exposes routes automatically, supports CRUD for list resources, and writes changes back to disk.
Table of Contents
- Why Data Server
- Installation
- Quick Start
- How Routing Works
- Request and Response Behavior
- Query Parameters (filter, sort, paging)
- CLI Reference
- Data File Requirements
- Development
- Release and Publish (PyPI)
- License
Why Data Server
- Generate an API from existing mock data in seconds.
- Test frontend flows without hand-writing backend endpoints.
- Simulate realistic behavior (pagination, sorting, filtering, latency).
- Keep data local and editable through HTTP requests.
Installation
pip install mock_data_server
You can run it either as a module or a CLI command:
python -m mock_data_server <file>
# or
mock-data-server <file>
Quick Start
- Create a sample JSON file:
{
"todos": [
{ "id": 1, "title": "Write docs", "done": false },
{ "id": 2, "title": "Ship feature", "done": false }
]
}
- Start the server:
mock-data-server ./todos.json --port 8000
- Try requests:
curl http://127.0.0.1:8000/
curl http://127.0.0.1:8000/todos
curl http://127.0.0.1:8000/todos/1
How Routing Works
GET /returns discovered routes and supported methods.- Each top-level list becomes a collection endpoint (for example,
todos->/todos). - Collection endpoints support
GETandPOST. - Item endpoints support
GET,PUT,PATCH, andDELETE.
If you provide --url-path-prefix /api/v1, all routes are served under that prefix.
Request and Response Behavior
POSTreturns201.DELETEreturns204when successful.- Other successful requests return
200. - CORS header
Access-Control-Allow-Origin: *is included. - Errors are returned as JSON:
{
"error": {
"description": "...",
"code": 400,
"details": "..."
}
}
You can add custom headers to every response with:
--additional-headers "X-Limit:20;X-Source:mock"
Query Parameters (filter, sort, paging)
Collection GET requests support:
- Filtering: any extra query keys are treated as exact-match filters.
- Sorting:
sort_by=<field>andorder=asc|desc. - Pagination:
page(starts at0)size(default comes from--page-size, default value is10)
Example:
curl "http://127.0.0.1:8000/todos?done=false&sort_by=title&order=asc&page=0&size=5"
You can rename these query parameter names via CLI flags such as --page-param-name, --sort-param-name, --order-param-name, and --size-param-name.
CLI Reference
Usage:
mock-data-server <file> [options]
Required positional argument:
file: Path to a.jsonor.csvfile.
Server options:
--host(default:127.0.0.1)--port(default:2000)--url-path-prefix--static-folder--static-url-prefix(default:static)--additional-headers--sleep-before-request(milliseconds)
Data/controller options:
--id-name(default:id)--auto-generate-ids/--no-auto-generate-ids--use-timestamps/--no-use-timestamps--created-at-key-name(default:created_at)--updated-at-key-name(default:updated_at)--page-size(default:10)--page-param-name(default:page)--sort-param-name(default:sort_by)--order-param-name(default:order)--size-param-name(default:size)
Data File Requirements
JSON
- Must be valid JSON.
- Top-level object keys typically map to endpoint paths.
- List values are treated as resources that support CRUD.
- Changes are persisted back to the same file.
CSV
- The CSV filename (without extension) becomes the route name.
- Rows are exposed as a single collection.
- Values are read as strings.
- Changes are written back to the same CSV file.
Development
# install with dev dependencies
pip install -e .[dev]
# format + lint
ruff format .
ruff check .
# type-check
mypy --strict mock_data_server
# run tests
coverage run -m unittest discover -v -s tests
coverage report -m
Main CI runs on push/PR to main.
Release and Publish (PyPI)
Publishing is automated through GitHub Actions after a successful CI run on main.
- Bump
versioninpyproject.toml. - Ensure repo secret
PYPI_API_TOKENis configured. - Merge to
main. - CI passes, then the publish workflow uploads to PyPI.
License
MIT
Project details
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 mock_data_server-1.0.1.tar.gz.
File metadata
- Download URL: mock_data_server-1.0.1.tar.gz
- Upload date:
- Size: 215.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46463b646da9e55d440f3d1662fc1594565d8757f9dbe8c772259d8b18b4af48
|
|
| MD5 |
fce82ceec2a0c445ec20854ed0e504e8
|
|
| BLAKE2b-256 |
d185eaf9e5b8d1c3a0ab869d89e93556204bd628dde5e25f8544b67da2f35b24
|
File details
Details for the file mock_data_server-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mock_data_server-1.0.1-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee44fdad7e49d4e6dee34caa6726b3951fbbc54b25578783a1e5fbaf7abb37c1
|
|
| MD5 |
abb64760693d2a0555c9d66c496100dc
|
|
| BLAKE2b-256 |
2a8209e0f254ce407024aeda724bd35671b5fce46f44c5117e626413c777843c
|