A Django app to help make building APIs great.
Project description
Django Dans API Toolkit
Description
Django Dans API Toolkit is a Django app to help make building APIs great.
It provides a collection of tools for common API tasks, intended to complement Django Rest Framework (DRF) rather than replace it.
Features
The toolkit includes:
- API Response Handler (
api_response_handler.py
): Standardizes API response formats. - API Response Renderer (
api_response_renderer.py
): Ensures consistent response rendering across your APIs. - Base Serializer (
serializers/base.py
): Simplifies serializer creation with masking and reference functionality.
Quick Start
Installation
-
Install the package via pip:
pip install django-dans-api-toolkit
-
Add
django_dans_api_toolkit
to yourINSTALLED_APPS
setting:INSTALLED_APPS = [ ... 'django_dans_api_toolkit', ]
-
Run migrations to update your database schema:
python manage.py migrate
-
Use the provided tools in your views and serializers.
Example Usage
API Response Handler
from django_dans_api_toolkit.api_response_handler import ApiResponseHandler
def my_view(request):
handler = ApiResponseHandler()
data = {"key": "value"}
return handler.response_success(results=data)
Base Serializer
from django_dans_api_toolkit.serializers.base import BaseSerializer
from myapp.models import MyModel
class MyModelSerializer(BaseSerializer):
class Meta:
model = MyModel
fields = '__all__'
ref_fields = ['field1', 'field2']
masked_fields = ['field3']
API Response Renderer
Ensure DEFAULT_AUTHENTICATION_CLASSES
and DEFAULT_PAGINATION_CLASS
are set in your settings.py for proper API functionality. Set the renderer itself as well.
Example configuration:
REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 20,
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.TokenAuthentication",
),
}
Requirements
- Python 3.10 - 3.11
- Django 3.1 or higher
- Django Rest Framework
- NOTE: not only must you have this installed, you must have set
DEFAULT_AUTHENTICATION_CLASSES
andDEFAULT_PAGINATION_CLASS
in yoursettings.py
to work with the APIs properly. An example config would be:
- NOTE: not only must you have this installed, you must have set
https://danielnazarian.com
Copyright 2024 © Daniel Nazarian.
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
Hashes for django-dans-api-toolkit-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e0595e61f58bf1e9c4a71f03fa5affae52aa0de37fac7cc3098e60889c53b04 |
|
MD5 | 6e8063b34d0274dd9b81db7934d146b7 |
|
BLAKE2b-256 | 4f9fffe867f72172f28b2d1d4e87891ffed5370337f16b9119e127a342c7dc9a |
Hashes for django_dans_api_toolkit-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e73e37de6a33dd887e70f70542a9d1a70a9233d8c34f20e00d095dd6c8dcb2a |
|
MD5 | ed8a5f5bf2f4568ae7ccc9aac345d9c4 |
|
BLAKE2b-256 | 5225b59d7bb2a6bc173907617177f7c9441ee7a8b9b1b958837a9a6ff317eb4f |