The python-cloudant library has a context manager to simplify working with documents:
# Upon entry into the document context, fetches the document from the # remote database, if it exists. Upon exit from the context, saves the # document to the remote database with changes made within the context. with Document(database, 'julia006') as document: # The document is fetched from the remote database # Changes are made locally document['name'] = 'Julia' document['age'] = 6 # The document is saved to the remote database
Source: http://python-cloudant.readthedocs.io/en/latest/document.html
What is the behaviour if the remote document doesn't exist? Is the document set to None
, or is an exception thrown?