Hi! ![]()
Some people might know me because of my CPython core development work, django-stubs maintaince, or even by wemake-django-template.
django-modern-rest
Docs: https://django-modern-rest.rtfd.io/
I want to present my latest project to Django community. I made a really simple, yet powerful REST framework for Django. Here’s a quick 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 PydanticFastSerializer
class UserCreateModel(pydantic.BaseModel):
email: str
class UserModel(UserCreateModel):
uid: uuid.UUID
consumer: str
class HeaderModel(pydantic.BaseModel):
consumer: str = pydantic.Field(alias='X-API-Consumer')
class UserController(Controller[PydanticFastSerializer]):
async def post( # <- can be sync as well!
self,
parsed_body: Body[UserCreateModel],
parsed_headers: Headers[HeaderModel],
) -> UserModel:
"""All added props have the correct runtime and static types."""
return UserModel(
uid=uuid.uuid4(),
email=parsed_body.email,
consumer=parsed_headers.consumer,
)
Here are some interesting features:
- Blazingly fast
- Supports
django>=4.2, CPython 3.11+ and PyPy 3.11+ - Supports
pydantic2,msgspec,attrs,dataclasses,TypedDictas model schemas, but not bound to any of these libraries - Supports async Django without any
sync_to_asynccalls inside, tested to work with free-threading builds - Fully typed and checked with
mypy,pyright, andpyreflyin strict modes - Uses default Django routing system, but speeds up all
path()calls from 30% to x50 times - Supports content negotiation, has default implementations for
jsonandmsgpack - Supports streaming: SSE and JsonLines
- Supports Django session auth and JWT auth out of the box
- Supports flexible throttling rules
- Strict schema validation of both requests and responses, including errors
- Supports OpenAPI 3.1 / 3.2 semantic schema generation
- Swagger UI, Redoc, Scalar, Stoplight Elements,
openapi.json,openapi.yamlviews supported by default - Supports all your existing
djangoprimitives and packages, supports wrapping any existing Django middleware, no custom runtimes - Easy to write plugins for and sharing reusable code
- Great testing tools with schemathesis, polyfactory, bundled
pytestplugin, and default Django’s testing primitives - 100% test coverage with 2000+ of carefully designed unit, integration, and property-based tests
- High security standards
- Built by the community for the community, not a single-person project
- Great docs
- No AI slop, but built for the LLM era with curated skills, contexts, LLMs integrations
For example, we offer official $dmr skill to write code using all our best-practices with agents. We also offer skills to create new django-modern-rest projects from OpenAPI schema file or skills for converting existing django-ninja or django-rest-framework code base to django-modern-rest. Migrating has never been easier ![]()
We also care about providing good context with llms-full.txt and context7.json.
As a fun fact, we compile parts of the framework with mypyc for some extra speed. Basically, using type-annotated Python code allows us to get some free performance with the pre-built wheels and pure python wheels for all platforms.
It also has integrations with tracecov API coverage tool, which allows you to see what API routes / responses / schemas you have really tested in your test cases:
Project just released 0.7.0 version, it is still in its early stages, but I invite you to check it out and star
it on GitHub if you like it!
