Skip to main content

A Django app to help make building APIs great.

Project description

Django Dans API Toolkit

Lint Test Types codecov

Python Versions Django Versions PyPI Version Downloads GitHub stars License Codacy grade Code style

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.

Available on PyPi

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

  1. Install the package via pip:

    pip install django-dans-api-toolkit
    
  2. Add django_dans_api_toolkit to your INSTALLED_APPS setting:

    INSTALLED_APPS = [
        ...
        'django_dans_api_toolkit',
    ]
    
  3. Run migrations to update your database schema:

    python manage.py migrate
    
  4. 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 and DEFAULT_PAGINATION_CLASS in your settings.py to work with the APIs properly. An example config would be:

https://danielnazarian.com
Copyright 2024 © Daniel Nazarian.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-dans-api-toolkit-1.0.2.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

django_dans_api_toolkit-1.0.2-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file django-dans-api-toolkit-1.0.2.tar.gz.

File metadata

File hashes

Hashes for django-dans-api-toolkit-1.0.2.tar.gz
Algorithm Hash digest
SHA256 86a8733537b76b747ff8d10656cf2d21470bef4138f9dc5b4fe8e6173dab548a
MD5 c3c8acfb054e492fa3720b5280a35059
BLAKE2b-256 98b3ed2b631f5bcaddfb5ed18a7f6003023fe091fd04a62bcf239cae8df9c83f

See more details on using hashes here.

File details

Details for the file django_dans_api_toolkit-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dans_api_toolkit-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 31c1ee0063cab22f5b7a2a6be3e30820c464952bab5b147bb33cf121191ac410
MD5 42e1a556ac9a4e1dfe37e09da9e0ee78
BLAKE2b-256 177d32e905695e27b3fc848a6fbe60d48e9e8f3baec6a3ceb0df72d966607ee9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page