DRF Lighten
Purpose
Even if we call the same end point at multiple places, the information we want from the response varies greatly. DRF Lighten makes it possible to specify and get only the data you want.
Installation
pip install drf_lighten
Usage
# serializers.py
from app import models
from drf_lighten.serializers import DynamicFieldsMixin
from rest_framework import serializers
class UserSerializer(DynamicFieldsMixin,
serializers.HyperlinkedModelSerializer)
class Meta:
model = models.User
fields = "__all__"
class ProfileSerializer(DynamicFieldsMixin,
serializers.HyperlinkedModelSerializer)
user = UserSerializer(read_only=True)
class Meta:
model = models.Profile
fields = "__all__"
# views.py
from app import models
from drf_lighten.views import DynamicFieldsMixin
from rest_framework import viewsets
# …
class ProfileViewSet(DynamicFieldsMixin, viewsets.ModelViewSet):
queryset = models.Profile.objects.all()
serializer_class = serializers.ProfileSerializer
Examples
https://localhost:8000/profiles/
[
{
"url": "https://localhost:8000/profiles/22/",
"picture": "https://localhost:8000/media/22.jpg",
"phone_number": "+251-911-11-11-11",
"user": {
"url": "https://localhost:8000/users/22/",
"user_name": "jupi2142",
"email": "test@gmail.com",
"first_name": "Henock",
"last_name": "Tesfaye"
},
"posts": [
"https://localhost:8000/posts/77/",
"https://localhost:8000/posts/78/",
"https://localhost:8000/posts/79/",
"https://localhost:8000/posts/79/",
"https://localhost:8000/posts/99/"
]
}
]
https://localhost:8000/profiles/?fields=["url", "picture", {"user": ["url", "username"]}]
[
{
"url": "https://localhost:8000/profiles/22/",
"picture": "https://localhost:8000/media/22.jpg",
"user": {
"url": "https://localhost:8000/users/22/",
"user_name": "jupi2142"
}
}
]
Configuration
If you want to use different query params than the ones provided, you can go to your django project's settings and do that
DRF_LIGHTEN_INCLUDE = 'fields'
DRF_LIGHTEN_EXCLUDE = 'exclude'
Metadata
Release files for drf_lighten 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drf_lighten-0.8.1.tar.gz | 8.4 kB | Without provenance | Details for drf_lighten-0.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_lighten-0.8.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for drf_lighten-0.8.1-py2.py3-none-any.whl |
Total release size: 14.6 kB
Release files / drf_lighten-0.8.1.tar.gz
| Download URL | drf_lighten-0.8.1.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
905df73f9e82cfea020cdee4cb1a55dc970ac49fac44ba9b4c22b9f16f6d498b
|
|
BLAKE2b-256 checksum How to use checksums |
fe3730513f2ceb285506260802bb9b15ea83e7467b48fe592e000b5f10ab5a72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.26.0
|
Release files / drf_lighten-0.8.1-py2.py3-none-any.whl
| Download URL | drf_lighten-0.8.1-py2.py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e62b2ce456434177e9af1ef3fd36b28eb1a1d35f2f4afbba37b3bf2b614d1ebf
|
|
BLAKE2b-256 checksum How to use checksums |
aebb4240c22dab792c43781308c53046b5f462035ee140023076c9d1b09f2b61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.26.0
|
Security for drf_lighten 0.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.