Cloudant-Python是CouchDB和Cloudant实例的Python异步接口。封装了请求来处理头、JSON序列化、流响应体等等功能的样板,例如:
importcloudant#connecttohttps://garbados.cloudant.comaccount=cloudant.Account('garbados',async=True)#andhttps://garbados.cloudant.com/allyourbasedatabase=account.database('allyourbase')#createthedatabasefuture=database.put()response=future.result()#throwanerroriftheresponsecodeindicatesfailureresponse.raise_for_status()printdatabase.get().result().json()#{"db_name":"allyourbase",...}异步HTTP请求返回Future对象等待HTTP响应,可调用Response对象的result()方法来获取结果。如果你没有传递async=True则执行同步请求:
importcloudant#connecttohttps://localhost:5984account=cloudant.Account()response=account.get()printresponse.json()#{"couchdb":"Welcome",...}获取Cloudant-Python的方法:
pipinstallcloudant
评论