I wrote this package to address what I saw as a weakness in Django’s built-in approach to model lifecycle events, which dispatches to a handler outside the model class. My package provides a decorator interface to declaritively describe when methods on the model should fire in response to lifecycle events, optionally predicated on field changes.
Django is a great framework, but lacking a declaritive lifecycle interface – critical for managing complexity as projects evolve – seemed like a weak point versus Rails for growing sophisticated, enterprise-scale apps.
Django REST - Flex Fields
REST is a great pattern, providing UI clients with Google Maps-like navigation of your business domain and letting them focus on providing a great end-user experience. However, in service architecutures where many clients with different use cases are calling upon your REST services, it can be useful to offer them slightly different resource representations on the fly, rather than having to add a multitude of resources to the REST interface.
This package makes it easy to expand nested resource, omit fields or specify only the fields needed for a given use case when using Django REST Framework. This is one of the problems that JSON:API solves, but you may find it difficult to implement its spec or find its format too verbose. This project is meant to offer a simple way to provide some JSON:API/GraphQL-like functionality.
Django REST - Access Policy
This package provides declarative, explicit authorization for Django REST Framework projects. I really like how AWS designed its Identity Access Management (IAM) service – powerful and flexible, combining context-based and role-based access rules in JSON policies. This package is inspired and partly modeled after IAM. Programmer error and confusion can be a major security vulnerability, and I’ve tried to provide a higher-level syntax that allows developers (and maybe even non-technical stakeholders) to focus on the rules of the business, not the code. Access policies are also JSON-serializable, allowing them to be stored outside the codebase and injected dynamically. You can change access rules without redeploying code, a key benefit for complex enterprise systems that are always changing.
Django REST - Typed Views
The idea of using Python’s type annotations during runtime for data validation has taken off in more recent projects (API Star, FastAPI). As a big fan of Django’s batteries-included approach, I wanted to see this feature in REST Framework. This project adds a couple of decorators to enable this feature. Mostly, this project is just an adapter to Django REST’s existing serializer fields, but it also enables integration with other libraries, such as Pydantic and Marshmallow. Special thanks to this blog post by Instagram for inspiring the decorator-based approach.