Cloudant/CouchDB 的異步Python接口: cloudant-python

jopen 11年前發布 | 16K 次閱讀 Python開發 cloudant-python

Cloudant-Python 是 CouchDB 和 Cloudant 實例的 Python 異步接口。封裝了請求來處理頭、JSON 序列化、流響應體等等功能的樣板,例如:

import cloudant

# connect to https://garbados.cloudant.com
account = cloudant.Account('garbados', async=True)
# and https://garbados.cloudant.com/allyourbase
database = account.database('allyourbase')

# create the database
future = database.put()
response = future.result()
# throw an error if the response code indicates failure
response.raise_for_status()

print database.get().result().json()
# { "db_name": "allyourbase", ... }

異步 HTTP 請求返回 Future 對象等待 HTTP 響應,可調用 Response 對象的 result() 方法來獲取結果。如果你沒有傳遞 async=True 則執行同步請求:

import cloudant

# connect to http://localhost:5984
account = cloudant.Account()

response = account.get()
print response.json()
# { "couchdb": "Welcome", ... }

獲取 Cloudant-Python 的方法:

pip install cloudant

項目主頁:http://www.baiduhome.net/lib/view/home/1385014754359

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!