Skip to main content

The library of simple helpers to build API with Django.

Project description

The library of simple helpers to build API with Django. Not aimed at implementing REST.

Requirements: Python 2.7+ and Django 1.8+. Installation:

$ pip install djapi


Most of the library needs no configuration, but if you want to use token authentication:

INSTALLED_APPS += ['djapi.authtoken']
DJAPI_AUTH = ['djapi.authtoken.use_token']

# Or add default django auth for e.g. debugging purposes
DJAPI_AUTH = ['djapi.authtoken.use_token', 'djapi.auth.use_contribauth']


import djapi as api

posts_qs = api.queryset(Post).filter(visible=True) \
    .values_but('visible', 'modified_on')          \
    .values_add(category='category__title')        \
    .map_types(Image, lambda img: img.url)

@api.catch(Post.DoesNotExist, status=404)
def post(request, pk):
    return api.json(posts_qs.get(pk=pk))

def posts_list(request):
    return api.json(api.paginate(request, posts_qs, per_page=20))

@api.user_passes_test(lambda user: user.is_staff)
def posts_create(request, post):
    post.created_by = request.user
    return api.json(201,

posts = api.route(get=posts_list, post=posts_create)

Download files

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

Files for djapi, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size djapi-0.2.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page