Package: django-wapiti
aboutDjango-wapiti is a generic API layer that can be added to any django project
to allow other applications to get access to its models and methods very easily
through JSON.It is being developped byEcometricaand made open source under a BSD license.statusDjango-wapiti is still under development. What works currently:enabling the api for a given modelaccessing objects by idsearching for objects through any of its fields, using any of the django
queryset field matching operators (exact,iexact,contains, …)auto-complete call allows frontend code to easily auto-complete user-entered
data; it will search for objects through different fieldsthe ModelApi class, like ModelAdmin class for the django admin, is how you
define the behavior an object should have through the APIinstance methods are supported: simply decorate the method to make it availableclass methods are also supported in the same mannerAPI keyslimiting requests per-{ip,session,user,apikey} per-{hour,day,month,year,ever}
per-{http method, object, type, method}slicing of results - add slice_left and slice_right parameters to your request to
slice the results
* the default max slice size is 100, override with settings.WAPITI_MAX_SLICE_SIZEshort-term planBecause we need the following functionality, it likely will be incorporated
soonish:better method for defining the permissions for a given API keyuser authentication (OAuth or otherwise) and row-level permissionscall logging (for quota and throttling enforcement)api introspection: /api/VER/ should return a json (or XML) representation of
the currently registered models and callsknown bugsthe JSON decoder will interpret both 2010-12-31 and “2010-12-31” as a date; it
should interpret the latter as a stringusageinstall django-wapiti. the easiest way might be to use:pip install git+http://git@github.com/ecometrica/django-wapiti.git#egg=django-wapitiwapiti requires the decorator module to function:pip install decoratoraddwapitito your INSTALLED_APPS in the settings.py file of your django
projectcall wapiti.helpers.register_models from somewhere, usually your urls.py, to
register your api models and methodsto make the model class Foo from the app fooapp available through the API,
create a filefooapp/api.pywith this content:from wapiti.helpers import register
from wapiti.modelapi import ModelApi

from fooapp.models import Foo

class FooApi(ModelApi):
    auto_complete_fields = ('name', 'description')
    auto_complete_order_by = 'name'
    model = Foo

register('foo', FooApi)We’ve made the auto_complete method work by automatically searching for Foo
objects with a case-insensitive search on the fields name and description
(which therefore must exist in the Foo model definition).See the filewapiti/modelapi.pyfor a list of all options available in
the ModelApi class for a given model.At this point, all objects of type Foo are available through the API at/api/1.0/foo/. To make an instance method available for calling through
the API, apply thewapiti.helpers.api_methoddecorator to it. To call
foo_method on the Foo object with ID 3, you wouldGET /api/1.0/foo/3/foo_methodSimilarly, for a class method, just decorate it with that sameapi_method,
but apply the pythonclassmethoddecoratoraboveit as well. To call
the foo_cls_method on Foo through the API you would thenGET /api/1.0/foo/foo_cls_methodTo make calls through the API, you’ll need API keys. From the main django
admin interface, click onAdd APIKey, add a name, and add a permission
with resource_regex.*on methodGET. All API calls need to have ak=THEAPIKEYparameter with a valid and active API key.All calls through JSON must have all their parameters be proper JSON! This
means that to pass a string argument to a method, it needs to be surrounded
by double-quotes! See theJSONspec for details.In order to use per-IP limiting, we need the REMOTE_ADDR variable. If you’re
using nginx, this needs to be in the properlocationsection:fastcgi_param REMOTE_ADDR $remote_addr;Release Notesv0.0.1Initial versionv0.0.2Slicing of resultsCompatible with Django 1.4 to 1.6v0.0.3post-South migrationsCompatible with Django 1.7 to 1.9v1.0.0Compatible with Django 1.8 and 1.9 (no longer compatible with Django =< 1.7)v1.0.1File handler now only takes field to better support non-FileSystemStorage
files. Old way is still supported, but deprecated.v1.0.2Previous version forgot to handle the case of no file handler being
supplied. This release fixes that.v1.0.3Allow serialising pre-1900 dates.