A lightweight Django ViewSet alternative with minimal abstraction.
Project description
Django Small View Set
A lightweight Django ViewSet alternative with minimal abstraction. This library provides a simple and transparent way to define API endpoints without relying on complex abstractions.
Documentation
- Getting Started: A bare-bones example to get the fundamentals.
- Register URLs: How to register viewset urls.
- Custom Endpoints: Learn how to define custom endpoints alongside the default router.
- Handling Endpoint Exceptions: Understand how to write your own decorators for exception handling.
- Custom Protections: Learn how to subclass
SmallViewSetto add custom protections like logged-in checks. - DRF Compatibility: Learn how to use some of Django Rest Framework's tools, like Serializers.
Reasoning behind this library:
A note from the library creator:
I feel like a justification to not "just use DRF" is in order.
After working in Django Rest Framework for years, I liked how nice it was for getting an API up and running really quickly, but I hated how often I would get stuck debugging some abstracted thing in a serializer, or a viewset, then spend too much time implementing some niche (and usually hacky feeling) fix.
Sadly, there are a lot of these pain points in DRF, and a lack of separation-of-concerns. For instance, I always disliked how serializers don't just serialize, they do operations like saving and updating, often resulting in business logic in serializers. That is not serialization. When using mixins on DRF viewsets, often customization methods are required, like which permissions to use for each endpoint, which serializer to use, add a custom "perform_create" method to help serializers save, etc. and it makes it difficult to do reverse lookups to endpoints. It also meant POSTing to reverse('foo-list') would happen, which really should be posting to the "foo-collection" or something else. It's nitpicky yes, but these nitpicks are all over.
So I wrote this. No black box anything. Surprisingly (because it was not the goal), I reduced the number of lines of code in every single one of my viewsets because I didn't need to register so many mixins, set up complex decorators, or define so many helper methods.
I still like some tools DRF provides, like throttles and serializers (when only used as validators or model => json conversions), those are still completely compatible and honestly amazing. I'm glad DRF exists, I've gotten a TON of use out of it over the years.
I also really liked my Spring Boot experience (and other frameworks, but Spring Boot was recent) where the pattern is to throw exceptions and a global exception handler will convert the errors to json responses, allowing a developer to bail on an endpoint at any time, no matter how deep in business logic they may be.
With this ViewSet and pattern, your call stack will never be far away from the real issue, letting you debug in peace.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_small_view_set-0.1.0.tar.gz.
File metadata
- Download URL: django_small_view_set-0.1.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.8.0-58-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae25dd6bd72e945f0077abae2a1b50ed86ed2089a83fe0514f0c82eb59a5c6d8
|
|
| MD5 |
d2e9a6a4d02ccc824ea61b2499cb9bfc
|
|
| BLAKE2b-256 |
88015bdb734a23911d6480ce4f47fdf21be49d8e3378a9bec535e589297741ee
|
File details
Details for the file django_small_view_set-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_small_view_set-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.8.0-58-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af8c3d60938215030e5edb4fedb46f343babc1e4051f21b16937c346ed597d5d
|
|
| MD5 |
5d8a85e5f71ba11b7eba73d9338f0236
|
|
| BLAKE2b-256 |
8278012e9c15b22888ee91b12f7d8d0006da1ba9d2c0df87af7a34bad8760957
|