Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexopryshko/django-serializer
Flexible toolkit for building APIs base on Marshmallow
https://github.com/alexopryshko/django-serializer
api django marshmallow python3 rpc-framework
Last synced: about 1 month ago
JSON representation
Flexible toolkit for building APIs base on Marshmallow
- Host: GitHub
- URL: https://github.com/alexopryshko/django-serializer
- Owner: alexopryshko
- License: mit
- Created: 2017-03-18T09:09:08.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-27T13:24:47.000Z (over 1 year ago)
- Last Synced: 2024-11-10T01:51:34.239Z (about 2 months ago)
- Topics: api, django, marshmallow, python3, rpc-framework
- Language: Python
- Homepage:
- Size: 125 KB
- Stars: 11
- Watchers: 2
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Django-serializer
## Installation
django-serializer packaged and delivered via [pypi](https://pypi.org/project/django-serializer/)
`pip install django-serializer`
## Features
Serialization provided by [marshmallow](https://github.com/marshmallow-code/marshmallow).
The library provide generic and custom CRUD views and paginators.
Automatic swagger generation provided by [apispec](https://github.com/marshmallow-code/apispec)# Changelog
See [HISTORY.md](https://github.com/alexopryshko/django-serializer/blob/master/HISTORY.md)## Quickstart
### basic flow
```python
from django_serializer.v2.serializer import ModelSerializer
from django_serializer.v2.views import ApiView
from myapp.models import MyModelclass MyModelSerializer(ModelSerializer):
class SMeta:
model = MyModel
fields = ('id', 'foo', 'bar')class MyView(ApiView):
class Meta:
serializer = MyModelSerializerdef execute(self, request, *args, **kwargs):
return MyModel.objects.first()
```### multiple objects
```python
from django_serializer.v2.serializer import ModelSerializer
from django_serializer.v2.views import ApiView
from myapp.models import MyModelclass MyModelSerializer(ModelSerializer):
class SMeta:
model = MyModel
fields = ('id', 'foo', 'bar')class MyListView(ApiView):
class Meta:
serializer = MyModelSerializer
serializer_many = Truedef execute(self, request, *args, **kwargs):
return MyModel.objects.first()
```### using query params
```python
from django import forms
from django_serializer.v2.views import ApiViewclass MyQueryForm(forms.Form):
id = forms.IntegerField()class MyListView(ApiView):
class Meta:
query_form = MyQueryForm
serializer = MyModelSerializer
serializer_many = True
def execute(self, request, *args, **kwargs):
object_id = self.request_query['id']
return MyModel.objects.filter(id=object_id).first()
```### add swagger
```python
# urls.py
from django_serializer.v2.swagger.views import index
from django.urls import pathurlpatterns = [
path('swagger.json', index),
]
```## Contribution
Feel free to open pull request to the latest `rc-` branch.## Licence
See [LICENSE](https://github.com/alexopryshko/django-serializer/blob/master/LICENSE.txt)