用烧瓶药水编写的api客户端
Potion-client的Python项目详细描述
说明
这是一个python客户端,用于用Flask-Potion(用于自文档json api的强大flask扩展)编写的api。
这个包使用Requests为药水api提供一个超级简单的接口 适用于所有常见的身份验证方法。它为api中的每个资源生成类,并自动处理分页。 以及解析和序列化引用。它还有一些基本的IPython Notebook支持。
示例
frompotion_clientimportClientfrompotion_client.authimportHTTPBearerAuthfrompotion_client.exceptionsimportItemNotFoundclient=Client('http://localhost/api',auth=HTTPBearerAuth('79054025255fb1a26e4bc422aef54eb4'))u123=client.User(123)chomp=client.Animal()chomp.owner=u123chomp.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))forpetinpets:ifpetisnotchomp:pet.add_friend(chomp)print("{} is now friends with Chomp".format(pet.name)))try:foo=client.User.first(where={"username":"foo"})exceptItemNotFound: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.")
安装
要安装potion-client,请运行:
pip install potion-client