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-3.12+ and Django 2.1-5.0+. Installation:

$ pip install djapi

Setup

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']

Usage

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.auth_required
@api.user_passes_test(lambda user: user.is_staff)
@api.validate(PostForm)
def posts_create(request, post):
    post.created_by = request.user
    post.save()
    return api.json(201, created=post.pk)

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.

Source Distribution

djapi-0.3.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

djapi-0.3-py2.py3-none-any.whl (10.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file djapi-0.3.tar.gz.

File metadata

  • Download URL: djapi-0.3.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for djapi-0.3.tar.gz
Algorithm Hash digest
SHA256 c4b49d29981297df2b457d8a55345cc5bb376fce5500b4bbb41d14731f59c785
MD5 7cd4ab80877e9bb38ca71e0d88975e32
BLAKE2b-256 0ffa883c786a2e1c5271d353a4dbca8b8c09ef34e678121aa88e6dfa51728784

See more details on using hashes here.

File details

Details for the file djapi-0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: djapi-0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for djapi-0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8c5f27e2d704c625a96db517a4cde9abd7cb2d49f0038f978354a37e586076ce
MD5 7cbe22ff86d83d6ee886258fa603bb50
BLAKE2b-256 a68c98d22ce78904035b6c0ceaa0ad381d550bb9eeb6461e58baeca25a9df176

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