Skip to main content

Modern REST framework for Django with types and async support

Project description

Modern REST Logo - Light Modern REST Logo - Dark

Modern REST framework for Django with types and async support!

wemake.services Modern REST test codecov PyPI Downloads Python Version wemake-python-styleguide Ask DeepWiki

Features

  • Blazingly fast
  • Fully typed and checked with mypy, pyright, and pyrefly in strict modes
  • Strict schema validation of both requests and responses
  • Supports django>=5.2
  • Supports pydantic2, but not bound to it
  • Supports msgspec, but not bound to it
  • Supports async Django without any sync_to_async calls inside
  • Supports openapi 3.1+ schema generation out of the box
  • Supports all your existing django primitives and packages, no custom runtimes
  • Great testing tools with schemathesis, polyfactory, bundled pytest plugin, and default Django's testing primitives
  • 100% test coverage
  • Built by the community for the community, not a single-person project
  • Great docs
  • No AI slop, but built for the LLM era: use our llms-full.txt or context7 for the context, we also support different use-cases specific to LLMs
  • No emojis 🌚️️

Benchmark - Light Benchmark - Dark

Sync mode

Testimonials

The one thing I really love about django-modern-rest is its pluggable serializers and validators. Frameworks that are tightly coupled with pydantic can be really painful to work with.

Kirill Podoprigora, CPython core developer

Using django-modern-rest has been a game-changer for my productivity. The strict type safety and schema validation for both requests and responses mean I spend less time debugging and more time building.

Josiah Kaviani, Django core developer

Installation

Works for:

  • CPython 3.11+
  • Django 5.2+
pip install django-modern-rest

There are several included extras:

  • 'django-modern-rest[msgspec]' provides msgspec support and the fastest json parsing, recommended to be always included
  • 'django-modern-rest[pydantic]' provides pydantic support
  • 'django-modern-rest[jwt]' provides pyjwt auth support
  • 'django-modern-rest[openapi]' provides OpenAPI schema validation and generates better OpenAPI examples with polyfactory

Example

The shortest example:

>>> import uuid
>>> import pydantic
>>> from dmr import Body, Controller, Headers
>>> # Or use `dmr.plugins.msgspec` or write your own!
>>> from dmr.plugins.pydantic import PydanticSerializer

>>> class UserCreateModel(pydantic.BaseModel):
...     email: str

>>> class UserModel(UserCreateModel):
...     uid: uuid.UUID

>>> class HeaderModel(pydantic.BaseModel):
...     consumer: str = pydantic.Field(alias='X-API-Consumer')

>>> class UserController(
...     Controller[PydanticSerializer],
...     Body[UserCreateModel],
...     Headers[HeaderModel],
... ):
...     def post(self) -> UserModel:  # <- can be async as well!
...         """All added props have the correct runtime and static types."""
...         assert self.parsed_headers.consumer == 'my-api'
...         return UserModel(uid=uuid.uuid4(), email=self.parsed_body.email)

And then route this controller in your urls.py:

>>> from django.urls import include, path
>>> from dmr.routing import Router

>>> router = Router(
...     'api/',
...     [
...         path('user/', UserController.as_view(), name='users'),
...     ],
... )
>>> urlpatterns = [
...     path(router.prefix, include((router.urls, 'my_app'), namespace='api')),
... ]

Done! Now you have your shiny API with 100% type safe validation and interactive docs.

Next steps:

License

MIT

Credits

This project was generated with wemake-python-package. Current template version is: e1fcf312d7f715323dcff0d376a40b7e3b47f9b7. See what is updated since then.

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

django_modern_rest-0.2.0.tar.gz (730.2 kB view details)

Uploaded Source

Built Distribution

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

django_modern_rest-0.2.0-py3-none-any.whl (783.7 kB view details)

Uploaded Python 3

File details

Details for the file django_modern_rest-0.2.0.tar.gz.

File metadata

  • Download URL: django_modern_rest-0.2.0.tar.gz
  • Upload date:
  • Size: 730.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.9 Darwin/24.6.0

File hashes

Hashes for django_modern_rest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0380e9d55cc76f7831dbd397301083010a41ee4eede264c41265e524af1ac3f4
MD5 5b430a6b55dcb17f9d435fb8bf6a7f05
BLAKE2b-256 302c6169272bd3b8acea58af89c2cd38b6469e14ead44cb0170b29498e6066a5

See more details on using hashes here.

File details

Details for the file django_modern_rest-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_modern_rest-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 783.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.9 Darwin/24.6.0

File hashes

Hashes for django_modern_rest-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95e50c9d2ce17f2576ade50a8772216e974c48a2d3ba2d5ccb44be01f148870a
MD5 4b1c76f22bbf677060cdf2a391ec070c
BLAKE2b-256 1fb4741d0feb0c17dfbe58fdeef895a762fb6cb4de1851772a21561641939c79

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