Skip to main content

Lightweight Django utilities for JSON APIs: schema-driven form views, auth endpoints, user settings, and middleware.

Project description

unrest_api

Lightweight Django utilities for building JSON APIs - schema-driven form views, auth endpoints, user-settings scaffolding, and helpful middleware.

Install

pip install unrest_api

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "unrest_api",
]

Features

  • unrest_api.schema.schema_form — turn a ModelForm into a JSON CRUD endpoint (GET schema, POST create, PUT partial update, DELETE).
  • unrest_api.schema.UnrestFormModelForm base that exposes self.request so __init__, clean, and save can scope querysets and defaults to the current user.
  • unrest_api.urls — drop-in auth routes (login, logout, register, settings).
  • unrest_api.models.AbstractUserSettings — abstract base providing timezone and theme plus the OneToOneField to AUTH_USER_MODEL (related_name='settings').
  • unrest_api.middleware.Json404Middleware — converts Http404 raised under an API prefix into JsonResponse({'error': ...}, status=404).

Quick start

# urls.py
from django.urls import include, path

urlpatterns = [
    path("api/auth/", include("unrest_api.urls")),
]
# forms.py
from unrest_api.schema import UnrestForm, register
from .models import Widget

@register
class WidgetForm(UnrestForm):
    class Meta:
        model = Widget
        fields = ["name", "color"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # self.request is available here

Settings

Setting Default Description
UNREST_USER_SETTINGS_FORM None Dotted path to a ModelForm for project-specific fields exposed by the unified settings endpoint.
UNREST_JSON_404_PREFIX "/api/" URL prefix under which Json404Middleware converts Http404 to JSON.

Compatibility

  • Python 3.11+
  • Django 5.2+

Changelog

See CHANGELOG.md.

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

unrest_api-0.4.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

unrest_api-0.4.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file unrest_api-0.4.0.tar.gz.

File metadata

  • Download URL: unrest_api-0.4.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for unrest_api-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b977e2f8e065de1feb59e383601379aa95755783fed44f63e5626ad85a97e9a8
MD5 2d23ec15859401f9704cf2499738d0ab
BLAKE2b-256 252838f0d9a556aad958ae877806531ddf08afbf87a78ba66de089ac166da889

See more details on using hashes here.

File details

Details for the file unrest_api-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: unrest_api-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for unrest_api-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 454c92475232e9605606d222b0c9a5f9b27b6256e5f323f8edaac7b377cc5f90
MD5 683b43b9e729fbd6d8e7e3dc0d6c936c
BLAKE2b-256 acc26adfef1b7e9fc9fd84a7493d5a59dbb10d6668b8be8339df58a0e5910bac

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