Librerie di Azure Cosmos DB per PythonAzure Cosmos DB libraries for Python

PanoramicaOverview

Usare Azure Cosmos DB nelle applicazioni Python per l'archiviazione e l'esecuzione di query nei documenti JSON in un archivio dati NoSQL.Use Azure Cosmos DB in your Python applications to store and query JSON documents in a NoSQL data store.

Altre informazioni su Azure Cosmos DB.Learn more about Azure Cosmos DB.

Libreria clientClient library

pip install pydocumentdb

Libreria di gestioneManagement library

pip install azure-mgmt-cosmosdb

EsempioExample

Trovare documenti corrispondenti in Azure Cosmos DB usando un'interfaccia di query analoga a SQL:Find matching documents in Azure CosmosDB using a SQL-like query interface:

import pydocumentdb
import pydocumentdb.document_client as document_client

# Initialize the Python Azure Cosmos DB client
client = document_client.DocumentClient(config['ENDPOINT'], {'masterKey': config['MASTERKEY']})
# Create a database
db = client.CreateDatabase({ 'id': config['DOCUMENTDB_DATABASE'] })

# Create collection options
options = {
    'offerEnableRUPerMinuteThroughput': True,
    'offerVersion': "V2",
    'offerThroughput': 400
}

# Create a collection
collection = client.CreateCollection(db['_self'], { 'id': config['DOCUMENTDB_COLLECTION'] }, options)

# Create some documents
document1 = client.CreateDocument(collection['_self'],
    { 
        'id': 'server1',
        'Web Site': 0,
        'Cloud Service': 0,
        'Virtual Machine': 0,
        'name': 'some' 
    })

# Query them in SQL
query = { 'query': 'SELECT * FROM server s' }    

options = {} 
options['enableCrossPartitionQuery'] = True
options['maxItemCount'] = 2

result_iterable = client.QueryDocuments(collection['_self'], query, options)
results = list(result_iterable)

print(results)

EsempiSamples