a python wrapper for the python client of Azure DocumentDB
Project description
A simple python wrapper for the python client of Azure DocumentDB
Installation
Using pip:
pip install pyzure_documentdb
Note: pydocumentdb requires requests of version 2.10.0
Usage
A credential file containing secret things is needed:
# credentials.py DOCUMENTDB_NAME = 'mydocdb' DOCUMENTDB_HOST = 'https://mydocdb.documents.azure.com:443/' DOCUMENTDB_KEY = '!@#!@#!@#YOUR_SECRET_KEY!@#!@#!@#'
Import and initiate:
import credentials from pyzure_docdb.documentdb import DocumentDB docdb = DocumentDB(credentials)
Get
Get a database or a collection with each id:
db = docdb.get_database('mydb') coll = docdb.get_collection('mydb', 'mycoll')
Get a single document with a series of id (database - collection - document):
doc = docdb.get_document('mydb', 'mycoll', 'mydoc')
Or get all documents:
docs = docdb.get_documents('mydb', 'mycoll')
Query
Query with your custom sql:
sql = 'SELECT * FROM c WHERE c.type=1' docs = docdb.query_documents('mydb', 'mycoll', sql)
Create
Create a database, a collection by its id:
newdb = docdb.create_db('mynewdb') newcoll = docdb.create_collection('mynewdb', 'mynewcoll')
Create a document giving a dictionary:
data = {'field1': 'value1', 'field2': 'value2'} newdoc = docdb.create_document('mynewdb', 'mynewcoll', data)
Upsert (update or insert) a document:
doc = docdb.upsert_document('mynewdb', 'mynewcoll', data)
Replace
Replace a document by modifying the original one:
doc = docdb.get_document('mydb', 'mycoll', 'mydoc') doc['type'] = 3 doc.update(another_dict) docdb.replace_document(doc)
Delete
Empty a collection by deleting all documents of the collection:
docdb.empty_documents('mydb', 'mycoll')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Built Distribution
Hashes for pyzure_documentdb-0.1.0.dev3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12ac63f146c67fb2a74acd21a5a1184b31d620f27e76266c66c4c44d87c118ef |
|
MD5 | 005b6f5aa18e6c84172ee8920974c40c |
|
BLAKE2-256 | db8bf20bace8cf6a34e205c03a3e520486413ad026c0f1e157cfd306fa5924fc |