https://github.com/bigbuildbench/em1208_adrf
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.3%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: BigBuildBench
- License: other
- Language: Python
- Default Branch: master
- Size: 27.3 KB
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Async Django REST framework
Async support for Django REST framework
Requirements
- Python 3.8+
- Django 4.1+
We highly recommend and only officially support the latest patch release of each Python and Django series.
Installation
Install using pip...
pip install adrf
Add 'adrf' to your INSTALLED_APPS setting.
python
INSTALLED_APPS = [
...
'adrf',
]
Examples
Async Views
When using Django 4.1 and above, this package allows you to work with async class and function based views.
For class based views, all handler methods must be async, otherwise Django will raise an exception. For function based views, the function itself must be async.
For example:
```python from adrf.views import APIView
class AsyncAuthentication(BaseAuthentication): async def authenticate(self, request) -> tuple[User, None]: return user, None
class AsyncPermission: async def has_permission(self, request, view) -> bool: if random.random() < 0.7: return False
return True
async def has_object_permission(self, request, view, obj):
if obj.user == request.user or request.user.is_superuser:
return True
return False
class AsyncThrottle(BaseThrottle): async def allow_request(self, request, view) -> bool: if random.random() < 0.7: return False
return True
def wait(self):
return 3
class AsyncView(APIView): authenticationclasses = [AsyncAuthentication] permissionclasses = [AsyncPermission] throttle_classes = [AsyncThrottle]
async def get(self, request):
return Response({"message": "This is an async class based view."})
from adrf.decorators import api_view
@apiview(['GET']) async def asyncview(request): return Response({"message": "This is an async function based view."}) ```
Async ViewSets
For viewsets, all handler methods must be async too.
views.py ```python from django.contrib.auth import getusermodel from rest_framework.response import Response
from adrf.viewsets import ViewSet
User = getusermodel()
class AsyncViewSet(ViewSet):
async def list(self, request):
return Response(
{"message": "This is the async `list` method of the viewset."}
)
async def retrieve(self, request, pk):
user = await User.objects.filter(pk=pk).afirst()
return Response({"user_pk": user and user.pk})
```
urls.py ```python from django.urls import path, include from rest_framework import routers
from . import views
router = routers.DefaultRouter() router.register(r"async_viewset", views.AsyncViewSet, basename="async")
urlpatterns = [ path("", include(router.urls)), ]
```
Async Serializers
serializers.py
```python from adrf.serializers import Serializer from rest_framework import serializers
class AsyncSerializer(Serializer): username = serializers.CharField() password = serializers.CharField() age = serializers.IntegerField() ```
views.py
```python from .serializers import AsyncSerializer from adrf.views import APIView
class AsyncView(APIView): async def get(self, request): data = { "username": "test", "password": "test", "age": 10, } serializer = AsyncSerializer(data=data) serializer.is_valid() return await serializer.adata ```
Async Generics
models.py
```python from django.db import models
class Order(models.Model): name = models.TextField() ```
serializers.py
```python from adrf.serializers import ModelSerializer from .models import Order
class OrderSerializer(ModelSerializer): class Meta: model = Order fields = ('name', ) ```
views.py
```python from adrf.generics import ListCreateAPIView from .models import Order from .serializers import OrderSerializer
class ListCreateOrderView(ListCreateAPIView): queryset = Order.objects.all() serializer_class = OrderSerializer ```
Owner
- Name: BigBuildBench
- Login: BigBuildBench
- Kind: organization
- Repositories: 1
- Profile: https://github.com/BigBuildBench
abbr. B3, benchmarking the repo-level understanding capability of your LLMs by reconstructing project build-file.
GitHub Events
Total
- Create event: 3
Last Year
- Create event: 3
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- pre-commit/action v2.0.0 composite
- faker ^26.1.0 develop
- pytest ^8.3.2 develop
- pytest-cov ^5.0.0 develop
- pytest-django ^4.8.0 develop
- ruff ^0.5.5 develop
- tox ^4.16.0 develop
- python >=3.8