Take a REST with django-nap: APIs for Django¶
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:
Serialiser
Declarative style Serialiser definitions for reducing complex Python objects to simple types expressible in JSON.
Publisher
A Class-based view system which merges many related views into a single class, including url routing.
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:
- Serialisers
- Fields
- Publishers
- Authorisation
- APIs
- Model Classes
- HTTP Utilities
- New Relic
- Examples
- Changelog
- v0.13.9
- v0.13.8
- v0.13.7
- v0.13.6
- v0.13.5.1
- v0.13.5
- v0.13.4
- v0.13.3
- v0.13.2.1
- v0.13.2
- v0.13.1
- v0.13.0
- v0.12.5.1
- v0.12.5
- v0.12.4
- v0.12.3
- v0.12.2
- v0.12.1
- v0.12
- v0.11.6.1
- v0.11.6
- v0.11.5.1
- v0.11.5
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10
- v0.9.1
- v0.9
- v0.8
- v0.7.1
- v0.7
- v0.6
- v0.5
- v0.4
- v0.3
- v0.2
- v0.1
Quick Start¶
- 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',]
- 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)
- Auto-discover publishers, and add your APIs to your URLs:
from nap import api
api.autodiscover()
urlpatterns('',
(r'', include(api.patterns())
...
)