资源算法flair-api-client-py

flair-api-client-py

2020-04-09 | |  40 |   0 |   0

Flair API Client (Python) Build Status

This package provides a very simple API client for the Flair API. Since the Flair API uses the JSON-API standard, this client is just a very thin wrapper around a JSON API client, but provides hooks for a extending it with custom models.

Installation

Eventually this will be released on PyPi, for now you'll need to install via github

pip install git+git://github.com/flair-systems/flair-api-client-py.git

This package depdends on requests, and requires Python 3.5 or greater.

Usage

from flair_api import make_client

client = make_client(client_id, client_secret, 'https://api.flair.co/')# retrieve a list of structures available to this accountstructures = client.get('structures')# get a single room by idroom = client.get('rooms', id="1")# fetch vents in a roomvents = room.get_rel('vents')# delete a roomroom.delete()# update a roomroom.update(attributes={'name': 'Master Bedroom'}, relationships=dict(structure=structures[0], vents=vents))# create a ventvent = c.create('vents', attributes={'name': 'North Vent'}, relationships=dict(room=room))# Add a vent to a roomroom.add_rel(vents=vent)# Update vent relationship for a roomroom.update_rel(vents=[vent])# Delete a vent relationship for a roomroom.delete_rel(vents=vent)

Authorization

At the moment, this package only supports authenticating to the Flair API using a client credentials request. This will give access to resources owned by the user to whom the credentials were issued. Support for other OAuth flow will be coming in future releases.

Extension

If, instead of having requests initialize or update the default Resource object, you'd like to use your own classes you can initialize the client with a mapper:

from flair_api import make_client, Resourceclass User(Resource):    def __init__(*args, **kwargs):        self.__super__.init(*args, **kwargs)        
    def __str__(self):        return "User: " + self.attributes['name']
        
client = make_client(client_id, client_secret, 'https://api.flair.co/', mapper={'users': User})

users = client.get('users')for user in users:    print(user)  # "User: Edward", "User: Kenny", "User: Danimal"

Contributing

Contributions are welcome by anyone. To get started, sign the Contributor License Agreement.

License

Copyright 2016 by Standard Euler, Inc

Licensed under the Apache Public License 2.0. See LICENSE.


上一篇:flair-for-chinese

下一篇:dev-networks-flairs

用户评价
全部评价

热门资源

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...