simple-json-server


Namesimple-json-server JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryA zero-dependency, lightweight REST API server based on a simple JSON file.
upload_time2025-08-09 10:51:36
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2025 10mohi6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords json-server mock api rest http-server prototype
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Simple JSON Server

[![PyPI version](https://badge.fury.io/py/simple-json-server.svg)](https://badge.fury.io/py/simple-json-server)
[![PyPI Downloads](https://static.pepy.tech/badge/simple-json-server)](https://pepy.tech/projects/simple-json-server)
[![Python Version](https://img.shields.io/pypi/pyversions/simple-json-server.svg)](https://pypi.org/project/simple-json-server)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CI/CD Pipeline](https://github.com/10mohi6/simple-json-server/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/10mohi6/simple-json-server/actions/workflows/publish-to-pypi.yml)
[![Coverage Status](https://codecov.io/gh/10mohi6/simple-json-server/branch/main/graph/badge.svg)](https://codecov.io/gh/10mohi6/simple-json-server)

A zero-dependency, lightweight REST API server based on a simple JSON file, built with Python's standard `http.server` module. This project provides a quick and easy way to set up a mock API for frontend development, prototyping, or any scenario where a real backend is not yet available.

Inspired by `json-server`.

## Features

- **Zero Dependencies:** Runs with just a standard Python installation.
- **Web Admin Interface:** A browser-based UI to view, add, edit, and delete data and resources.
- **RESTful API:** Automatically generates a full REST API from a `db.json` file.
- **CRUD Operations:** Supports `GET`, `POST`, `PUT`, `PATCH`, and `DELETE` methods.
- **Advanced Querying:** Filter, sort, and paginate your responses.
- **Full-text Search:** Perform a simple text search across all fields in a resource.
- **Relationships:** Supports both parent (`_expand`) and child (`_embed`) relationships.
- **Cascading Deletes:** Delete dependent resources automatically using `_dependent`.
- **Static File Serving:** The admin UI is bundled with the package. You can also serve your own static files from a `public` directory.

## Installation

You can install the package from PyPI:

```bash
pip install simple-json-server
```

## Usage

1.  **Create a `db.json` file (optional):**
    In your project directory, create a `db.json` file. The keys will be treated as API resources. If you don't create one, the server will start with an empty database.

    ```json
    {
      "posts": [
        { "id": "1", "title": "json-server", "views": 100, "authorId": "1" }
      ],
      "authors": [
        { "id": "1", "name": "Alice" }
      ]
    }
    ```

2.  **Start the server:**
    Run the following command in your project directory:
    ```bash
    simple-json-server
    ```

    The server will be running at `http://127.0.0.1:5000`.

### Command-Line Options

You can customize the server's behavior with the following options:

- **Port:** Run on a different port.
  ```bash
  simple-json-server --port 8080
  ```

- **Host:** Make the server accessible on your local network.
  ```bash
  simple-json-server --host 0.0.0.0
  ```

- **Database File:** Use a different database file.
  ```bash
  simple-json-server --file my_api_data.json
  ```

## Admin Interface

An admin UI is bundled with the server to easily manage your data.

- **URL:** `http://127.0.0.1:5000/admin.html`

**Features:**
- **Resource Management:** Add, rename, and delete resources (e.g., `posts`, `users`) directly from the UI.
- **Data Management:** View, add, edit, and delete individual data entries within a resource using a JSON editor.
- **Query Tester:** A simple interface to test your API endpoints with different query parameters.

## API Endpoints

Based on the `db.json` example above, the following endpoints are available:

### Query Parameters

- **Sort:** `GET /posts?_sort=-views` (Sort by views, descending) or `GET /posts?_sort=title` (Sort by title, ascending).
- **Filter:** `GET /posts?views_gte=200` (Get posts with views >= 200). Operators: `_ne`, `_lt`, `_lte`, `_gt`, `_gte`.
- **Paginate:**
    - `GET /posts?_page=1&_per_page=10` (Page-based pagination)
    - `GET /posts?_start=0&_end=10` (Slice from index 0 to 10)
    - `GET /posts?_start=10&_limit=5` (Slice 5 items starting from index 10)
- **Full-text Search:** `GET /posts?_q=python` (Search for "python" in any field).
- **Relationships:**
    - `GET /posts/1?_expand=author` (Include the parent `author` resource).
    - `GET /authors/1?_embed=posts` (Include the children `posts` resources).
- **Cascading Delete:** `DELETE /posts/1?_dependent=comments` (Delete post 1 and all its associated comments).

## Static File Serving

If you create a `public` folder in the directory where you run the server, it will be used to serve your own static files, overriding the bundled admin UI if there are name conflicts (e.g., `index.html`).

## Development

To contribute to development, clone the repository and install the testing dependencies.

1. **Clone the repository:**
   ```bash
   git clone https://github.com/10mohi6/simple-json-server.git
   cd simple-json-server
   ```

2. **Install dev dependencies:**
   It's recommended to use `uv` for managing the environment.
   ```bash
   uv pip install -e .[dev]
   ```

3. **Run tests:**
   To run tests and see the coverage report in the terminal:
   ```bash
   uv run pytest --cov=simple_json_server --cov-report=term-missing
   ```

## Publishing to PyPI

This project is automatically published to PyPI via GitHub Actions. A new version is released whenever a push is made to the `main` branch.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "simple-json-server",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "json-server, mock, api, rest, http-server, prototype",
    "author": null,
    "author_email": "10mohi6 <10.mohi.6.y@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/76/61/3be592634b83c648967578310c69f218c972e943ff32180f980bd2aaf8e2/simple_json_server-0.2.0.tar.gz",
    "platform": null,
    "description": "# Simple JSON Server\n\n[![PyPI version](https://badge.fury.io/py/simple-json-server.svg)](https://badge.fury.io/py/simple-json-server)\n[![PyPI Downloads](https://static.pepy.tech/badge/simple-json-server)](https://pepy.tech/projects/simple-json-server)\n[![Python Version](https://img.shields.io/pypi/pyversions/simple-json-server.svg)](https://pypi.org/project/simple-json-server)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![CI/CD Pipeline](https://github.com/10mohi6/simple-json-server/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/10mohi6/simple-json-server/actions/workflows/publish-to-pypi.yml)\n[![Coverage Status](https://codecov.io/gh/10mohi6/simple-json-server/branch/main/graph/badge.svg)](https://codecov.io/gh/10mohi6/simple-json-server)\n\nA zero-dependency, lightweight REST API server based on a simple JSON file, built with Python's standard `http.server` module. This project provides a quick and easy way to set up a mock API for frontend development, prototyping, or any scenario where a real backend is not yet available.\n\nInspired by `json-server`.\n\n## Features\n\n- **Zero Dependencies:** Runs with just a standard Python installation.\n- **Web Admin Interface:** A browser-based UI to view, add, edit, and delete data and resources.\n- **RESTful API:** Automatically generates a full REST API from a `db.json` file.\n- **CRUD Operations:** Supports `GET`, `POST`, `PUT`, `PATCH`, and `DELETE` methods.\n- **Advanced Querying:** Filter, sort, and paginate your responses.\n- **Full-text Search:** Perform a simple text search across all fields in a resource.\n- **Relationships:** Supports both parent (`_expand`) and child (`_embed`) relationships.\n- **Cascading Deletes:** Delete dependent resources automatically using `_dependent`.\n- **Static File Serving:** The admin UI is bundled with the package. You can also serve your own static files from a `public` directory.\n\n## Installation\n\nYou can install the package from PyPI:\n\n```bash\npip install simple-json-server\n```\n\n## Usage\n\n1.  **Create a `db.json` file (optional):**\n    In your project directory, create a `db.json` file. The keys will be treated as API resources. If you don't create one, the server will start with an empty database.\n\n    ```json\n    {\n      \"posts\": [\n        { \"id\": \"1\", \"title\": \"json-server\", \"views\": 100, \"authorId\": \"1\" }\n      ],\n      \"authors\": [\n        { \"id\": \"1\", \"name\": \"Alice\" }\n      ]\n    }\n    ```\n\n2.  **Start the server:**\n    Run the following command in your project directory:\n    ```bash\n    simple-json-server\n    ```\n\n    The server will be running at `http://127.0.0.1:5000`.\n\n### Command-Line Options\n\nYou can customize the server's behavior with the following options:\n\n- **Port:** Run on a different port.\n  ```bash\n  simple-json-server --port 8080\n  ```\n\n- **Host:** Make the server accessible on your local network.\n  ```bash\n  simple-json-server --host 0.0.0.0\n  ```\n\n- **Database File:** Use a different database file.\n  ```bash\n  simple-json-server --file my_api_data.json\n  ```\n\n## Admin Interface\n\nAn admin UI is bundled with the server to easily manage your data.\n\n- **URL:** `http://127.0.0.1:5000/admin.html`\n\n**Features:**\n- **Resource Management:** Add, rename, and delete resources (e.g., `posts`, `users`) directly from the UI.\n- **Data Management:** View, add, edit, and delete individual data entries within a resource using a JSON editor.\n- **Query Tester:** A simple interface to test your API endpoints with different query parameters.\n\n## API Endpoints\n\nBased on the `db.json` example above, the following endpoints are available:\n\n### Query Parameters\n\n- **Sort:** `GET /posts?_sort=-views` (Sort by views, descending) or `GET /posts?_sort=title` (Sort by title, ascending).\n- **Filter:** `GET /posts?views_gte=200` (Get posts with views >= 200). Operators: `_ne`, `_lt`, `_lte`, `_gt`, `_gte`.\n- **Paginate:**\n    - `GET /posts?_page=1&_per_page=10` (Page-based pagination)\n    - `GET /posts?_start=0&_end=10` (Slice from index 0 to 10)\n    - `GET /posts?_start=10&_limit=5` (Slice 5 items starting from index 10)\n- **Full-text Search:** `GET /posts?_q=python` (Search for \"python\" in any field).\n- **Relationships:**\n    - `GET /posts/1?_expand=author` (Include the parent `author` resource).\n    - `GET /authors/1?_embed=posts` (Include the children `posts` resources).\n- **Cascading Delete:** `DELETE /posts/1?_dependent=comments` (Delete post 1 and all its associated comments).\n\n## Static File Serving\n\nIf you create a `public` folder in the directory where you run the server, it will be used to serve your own static files, overriding the bundled admin UI if there are name conflicts (e.g., `index.html`).\n\n## Development\n\nTo contribute to development, clone the repository and install the testing dependencies.\n\n1. **Clone the repository:**\n   ```bash\n   git clone https://github.com/10mohi6/simple-json-server.git\n   cd simple-json-server\n   ```\n\n2. **Install dev dependencies:**\n   It's recommended to use `uv` for managing the environment.\n   ```bash\n   uv pip install -e .[dev]\n   ```\n\n3. **Run tests:**\n   To run tests and see the coverage report in the terminal:\n   ```bash\n   uv run pytest --cov=simple_json_server --cov-report=term-missing\n   ```\n\n## Publishing to PyPI\n\nThis project is automatically published to PyPI via GitHub Actions. A new version is released whenever a push is made to the `main` branch.\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 10mohi6\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "A zero-dependency, lightweight REST API server based on a simple JSON file.",
    "version": "0.2.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/10mohi6/simple-json-server/issues",
        "Homepage": "https://github.com/10mohi6/simple-json-server"
    },
    "split_keywords": [
        "json-server",
        " mock",
        " api",
        " rest",
        " http-server",
        " prototype"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a8e8e98825b2640416b34b7ff4f66fce9e6e34e7203014d4751ce8a233cab889",
                "md5": "a79686c1c9425439835080e987beb7ea",
                "sha256": "40d437015b2409a2e781c9a51e6caeb14bdbd8caf320eb6fc8ddd9945a404852"
            },
            "downloads": -1,
            "filename": "simple_json_server-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a79686c1c9425439835080e987beb7ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 14932,
            "upload_time": "2025-08-09T10:51:35",
            "upload_time_iso_8601": "2025-08-09T10:51:35.877786Z",
            "url": "https://files.pythonhosted.org/packages/a8/e8/e98825b2640416b34b7ff4f66fce9e6e34e7203014d4751ce8a233cab889/simple_json_server-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "76613be592634b83c648967578310c69f218c972e943ff32180f980bd2aaf8e2",
                "md5": "335a66c473e1e65a20289b59a06a5a36",
                "sha256": "90480e134658021ee0082a809679cca39705ff0f5d7100dc20472f83901de594"
            },
            "downloads": -1,
            "filename": "simple_json_server-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "335a66c473e1e65a20289b59a06a5a36",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 17977,
            "upload_time": "2025-08-09T10:51:36",
            "upload_time_iso_8601": "2025-08-09T10:51:36.985229Z",
            "url": "https://files.pythonhosted.org/packages/76/61/3be592634b83c648967578310c69f218c972e943ff32180f980bd2aaf8e2/simple_json_server-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-09 10:51:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "10mohi6",
    "github_project": "simple-json-server",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "simple-json-server"
}
        
Elapsed time: 1.79649s