Take a REST with django-nap: APIs for Django

https://travis-ci.org/funkybob/django-nap.png https://pypip.in/d/django-nap/badge.png https://pypip.in/v/django-nap/badge.png

Whilst there are many existing RESTful API tools about, many of them are very complex, and [as I found] some are quite slow!

I wanted to take the solid serialising pattern from TastyPie, with the separation of roles of django-rest-framework, and include a Publisher API I developed some time ago.

In the spirit of the Unix philosophy, Nap provides a few tools which each do one thing, and do it well. They are:

  1. Serialiser

    Declarative style Serialiser definitions for reducing complex Python objects to simple types expressible in JSON.

  2. Publisher

    A Class-based view system which merges many related views into a single class, including url routing.

  3. API

    Manage many Publishers and API versions with simple auto-discover resource registration.

Nap does not provide the wide range of features you see in tools like Django REST Framework and TastyPie, such as rate limiting, token authentication, automatic UI, etc. Instead, it provides a flexible framework that makes it easy to combine with other specialised apps.

Contents:

Quick Start

  1. Create a Serialiser for your Model in serialisers.py
from nap import models
from myapp.models import MyModel

class MyModelSerialiser(models.ModelSerialiser):
    class Meta:
        model = MyModel
        exclude = ['user',]
  1. Create a Publisher in publishers.py, and register it.
from nap import api, models
from myapp.serialisers import MyModelSerialiser

class MyModelPublisher(models.ModelPublisher):
    serialiser = MyModelSerialiser()

api.register('api', MyModelPublisher)
  1. Auto-discover publishers, and add your APIs to your URLs:
from nap import api

api.autodiscover()

urlpatterns('',
    (r'', include(api.patterns())
    ...
)

Indices and tables