Coder Social home page Coder Social logo

potion-client's Introduction

Potion client

https://img.shields.io/travis/biosustain/potion-client/new-potion-client.svg?style=flat-square https://img.shields.io/coveralls/biosustain/potion-client/new-potion-client.svg?style=flat-square https://img.shields.io/pypi/v/Potion-Client.svg?style=flat-square https://img.shields.io/pypi/l/Potion-Client.svg?style=flat-square Join the chat at https://gitter.im/biosustain/potion

Description

This is a Python client for APIs written in Flask-Potion (a powerful Flask extension for self-documenting JSON APIs).

The package uses Requests to provide a super-simple interface to Potion APIs that works with all common authentication methods. It generates classes for each of the resources in the API and automatically handles pagination and resolving and serializing references. It also has some basic IPython Notebook support.

Example

from potion_client import Client
from potion_client.auth import HTTPBearerAuth
from potion_client.exceptions import ItemNotFound

client = Client('http://localhost/api', auth=HTTPBearerAuth('79054025255fb1a26e4bc422aef54eb4'))

u123 = client.User(123)

chomp = client.Animal()
chomp.owner = u123
chomp.name = "Chomp"
chomp.species = "hamster"
chomp.save()

pets = client.Animal.instances(where={"owner": u123}, sort={"created_at": True})

print("{} has {} pet(s)".format(u123.first_name, len(pets))

for pet in pets:
    if pet is not chomp:
        pet.add_friend(chomp)
        print("{} is now friends with Chomp".format(pet.name)))

try:
    foo = client.User.first(where={"username": "foo"})
except ItemNotFound:
    print("User 'foo' does not exist!")
else:
    chomp.update(owner=foo)
    print("Chomp has been sold to {}".format(foo.name))

chomp.destroy()
print("RIP, Chomp. You lived a happy life.")

Installation

To install potion-client, run:

pip install potion-client

Authors

Potion-client was written by João Cardoso and Lars Schöning.

potion-client's People

Contributors

lyschoening avatar pypingou avatar the-code-magician avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.