Skip to main content

A Django DRF mock response tool

Project description

drf-mock-response

📦 A lightweight mock response framework for Django REST Framework (DRF).
Easily simulate API endpoints using static JSON files stored inside your Django apps.


🔧 Features

  • Plug & play mock API views (List, Detail, Update, Delete)
  • Supports ViewSet-based mocks
  • Loads JSON mock data from json_mock/ directory inside each Django app
  • Customizable HTTP status code and response delay
  • No real DB or models required

📁 Project Structure

In each Django app:

your_app/
├── json_mock/
│ └── your_mock.json
├── views/
│ └── your_mock_views.py


🚀 Installation

pip install git+https://github.com/khodealib/drf-mock-response.git

Or after cloning:

pip install /path/to/drf_mock_response/

🧩 Usage

# your_app/views/mocks.py

from drf_mock_response.views import MockListAPIView

class ProductListMock(MockListAPIView):
    json_filename = "product_list.json"
    mock_status = 200
    delay_seconds = 1
# your_app/urls.py

from django.urls import path
from .views.mocks import ProductListMock

urlpatterns = [
    path("mock/products/", ProductListMock.as_view()),
]

Place your mock file in:

your_app/json_mock/product_list.json

🔁 ViewSet Example

from drf_mock_response.viewsets import MockViewSet

class UserMockViewSet(MockViewSet):
    json_filename = "user_list.json"

And wire it with a router in your urls.py.

✅ Requirements

Django ≥ 3.2
djangorestframework ≥ 3.14

📄 License

MIT © 2025 Ali Bagheri

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

drf_mocker-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_mocker-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file drf_mocker-0.1.0.tar.gz.

File metadata

  • Download URL: drf_mocker-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for drf_mocker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 16d5cd0b4a81e31e51d401c8dafff73a6194707e0aa180bb515e446c02d4a6e8
MD5 b9905e668ea065244b4d789e709a7ec6
BLAKE2b-256 2a4cfc19fcdc79656de74d1849706ce69e2c62e4504f89e25349c1b84e8ae11e

See more details on using hashes here.

File details

Details for the file drf_mocker-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: drf_mocker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for drf_mocker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d9bd77e3379230d53adf7e0534bdfe546ebc017900878465faa531077a7cc19
MD5 9aff66037924bb357ccbc8e10cb351c9
BLAKE2b-256 90bf22d608dc62663da2c7be9e9a14dead12f3b9189afcba7e580c211483df53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page