An ORM for tastypie's API on the client-side.
Project description
Designed to take the heavy lifting out of working with django-tastypie APIs on the client side.
Currently in beta.
Features
Django model-like ORM API allowing you to GET, POST, PUT, PATCH, and DELETE:
factory = ResourceFactory('http://localhost:8000/myapp/api/v1/') current_resource = factory.resource.get(field='name') # GET new_resource = factory.resource(field='new_name') # POST new_resource.field = 'different_name' # PATCH / PUT current_resource.delete() # DELETE
Easily work with any related resources:
new_resource.children = [ factory.resource(field='new_name1'), factory.resource(field='new_name2'), ]
Simple way to set and update authentication per resource:
factory.resource.auth = ApiKeyAuth('username', 'key12345')
Access custom endpoints using simple methods:
new_resource.cust_endpoint('arg1', arg2=3)
Set whether the resources should be cached locally or always updated remotely (per resource or per instance):
factory.resource.caching = False # Or per instance new_resource.set_caching(False)
Basic field validation before connecting to the API.
Bulk create / update / delete to minimise API access:
factory.resource.bulk( create=[{field='name1'}, {field='name2'}], delete=[new_resource], )
Auto-generate docs for your tastypie API (in progress).
Find more information on these features at read the docs!
Requirements
The following needs to be installed locally to run TastyTopping:
Python 2.7+ or Python 3.3+
requests (link) >= 1.0.0
Tested against:
django >= 1.5.0
django-tastypie >= 0.9.14
(see the tox.ini file for more information).
Example
A basic example of a simple workflow, using the following API on the server side:
# myapp/models.py # =============== from django.db import models class Example(models.Model): path = models.CharField(max_length=255, unique=True) rating = models.IntegerField(default=50) date = models.DateTimeField('date', null=True) # myapp/api.py # ============ from .models import Example class ExampleResource(ModelResource): class Meta: queryset = Example.objects.all() resource_name = 'example' authorization = Authorization() filtering = {'path': ALL, 'rating': ALL} ordering = ['rating']
Using TastyTopping on the client side would look like this:
from datetime import datetime from tastytopping import ResourceFactory factory = ResourceFactory('http://localhost:8000/myapp/api/v1/') ex1 = factory.example(path='any text', rating=80) ex1.date = datetime.now() ex1_copy = factory.example.get(rating=80) ex1.delete()
Find more examples at read the docs!
Justification
Why another one? There are some other packages around that do something similar (most notably tastypie-queryset-client), but they’re lacking in a few areas:
Python3 support.
Support for authentication.
Support for custom endpoints.
A thorough set of unit tests.
Development has stagnated (none of them have released in close to a year, whereas tastypie has been releasing thick and fast).
Creating this was FUN!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for TastyTopping-1.0.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11d4f68450f7fc4f7c3f2cf6f716a0bc3668a9d52c2d99df94569a1f7e0a911a |
|
MD5 | 79d23fc5d7d8275fde2a61d5ce336d0b |
|
BLAKE2b-256 | 9dd3c63a088c5cb1b4841b66b18a40011f26d5aaa1f897a8f953272f310d2c23 |