Python client for a DjangoRestFramework based web site
Project description
# Strato Python API Package
A python library for interacting with any Django web server base on django-rest-framework
Package is based on https://github.com/samgiles/slumber, but enhanced to support tokens and other features.
## Features
* Support for tokens. Both
* django-rest-framework's own tokens: `rest_framework.authentication.TokenAuthentication`
* JWT tokens: `rest_framework_jwt.authentication.JSONWebTokenAuthentication`
* Support for arguments (e.g. `?name1=val1&name2=val2`)
* Support for custom methods (e.g. ``/ap1/v1/object/custom/`)
## Requirements
restframeworkclient requires the following modules.
* Python 2.7+ or 3.4+
* requests
## Installation
```
pip install drf_client
```
## Usage Guide
Example
```
options = {
'DOMAIN': 'http://127.0.0.1:8000',
'API_PREFIX': 'api/v1',
'TOKEN_TYPE': 'jwt',
'TOKEN_FORMAT': 'JWT {token}',
'LOGIN': 'auth/login/',
'LOGOUT': 'auth/logout/',
}
c = RestApi(options)
ok = c.login(email=email, password=password)
if ok:
# GET some data
my_object = c.myresourcename.get()
for obj in my_object['results']:
pprint(obj)
logger.info('------------------------------')
payload = {
'data1': 'val1',
'data2': 'val2',
}
resp = c.myresourcename.post(data=payload)
```
## Django Setup
Client assumes by default that all urls should end with a slash (tested with the default
router: `routers.DefaultRouter()`)
Apart from the regular Django and Rest Framework setup, this package currently relies on the following custom
login and logout API functions:
```
class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'email', 'username')
class APILogoutViewSet(APIView):
permission_classes = (permissions.IsAuthenticated,)
def post(self, request, format=None):
logout(request)
return Response({}, status=status.HTTP_204_NO_CONTENT)
urlpatterns = [
url(r'^auth/logout/$', APILogoutViewSet.as_view(), name='api-logout'),
```
## Development
To test, run python setup.py test or to run coverage analysis:
```
coverage run --source=iotile_cloud setup.py test
coverage report -m
```
You can also use py.test:
```
py.test
```
A python library for interacting with any Django web server base on django-rest-framework
Package is based on https://github.com/samgiles/slumber, but enhanced to support tokens and other features.
## Features
* Support for tokens. Both
* django-rest-framework's own tokens: `rest_framework.authentication.TokenAuthentication`
* JWT tokens: `rest_framework_jwt.authentication.JSONWebTokenAuthentication`
* Support for arguments (e.g. `?name1=val1&name2=val2`)
* Support for custom methods (e.g. ``/ap1/v1/object/custom/`)
## Requirements
restframeworkclient requires the following modules.
* Python 2.7+ or 3.4+
* requests
## Installation
```
pip install drf_client
```
## Usage Guide
Example
```
options = {
'DOMAIN': 'http://127.0.0.1:8000',
'API_PREFIX': 'api/v1',
'TOKEN_TYPE': 'jwt',
'TOKEN_FORMAT': 'JWT {token}',
'LOGIN': 'auth/login/',
'LOGOUT': 'auth/logout/',
}
c = RestApi(options)
ok = c.login(email=email, password=password)
if ok:
# GET some data
my_object = c.myresourcename.get()
for obj in my_object['results']:
pprint(obj)
logger.info('------------------------------')
payload = {
'data1': 'val1',
'data2': 'val2',
}
resp = c.myresourcename.post(data=payload)
```
## Django Setup
Client assumes by default that all urls should end with a slash (tested with the default
router: `routers.DefaultRouter()`)
Apart from the regular Django and Rest Framework setup, this package currently relies on the following custom
login and logout API functions:
```
class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'email', 'username')
class APILogoutViewSet(APIView):
permission_classes = (permissions.IsAuthenticated,)
def post(self, request, format=None):
logout(request)
return Response({}, status=status.HTTP_204_NO_CONTENT)
urlpatterns = [
url(r'^auth/logout/$', APILogoutViewSet.as_view(), name='api-logout'),
```
## Development
To test, run python setup.py test or to run coverage analysis:
```
coverage run --source=iotile_cloud setup.py test
coverage report -m
```
You can also use py.test:
```
py.test
```
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
Close
Hashes for django-rest-framework-client-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69b2f6e328bb1013fb29b1277677ca946354f5eb06e9cb1a796761b4ad2f37ff |
|
MD5 | abbd17f1e25064ceccd5be4a18ad7322 |
|
BLAKE2b-256 | dd2185f060da294856900ce190f7621107ce76d0f47cd0c3a52652f3eec4640d |