airflow.providers.microsoft.azure.hooks.azure_cosmos

This module contains integration with Azure CosmosDB.

AzureCosmosDBHook communicates via the Azure Cosmos library. Make sure that a Airflow connection of type azure_cosmos exists. Authorization can be done by supplying a login (=Endpoint uri), password (=secret key) and extra fields database_name and collection_name to specify the default database and collection to use (see connection azure_cosmos_default for an example).

Module Contents

class airflow.providers.microsoft.azure.hooks.azure_cosmos.AzureCosmosDBHook(azure_cosmos_conn_id: str = default_conn_name)[source]

Bases: airflow.hooks.base.BaseHook

Interacts with Azure CosmosDB.

login should be the endpoint uri, password should be the master key optionally, you can use the following extras to default these values {"database_name": "<DATABASE_NAME>", "collection_name": "COLLECTION_NAME"}.

Parameters

azure_cosmos_conn_id (str) -- Reference to the Azure CosmosDB connection.

conn_name_attr = azure_cosmos_conn_id[source]
default_conn_name = azure_cosmos_default[source]
conn_type = azure_cosmos[source]
hook_name = Azure CosmosDB[source]
get_conn(self)[source]

Return a cosmos db client.

__get_database_name(self, database_name: Optional[str] = None)[source]
__get_collection_name(self, collection_name: Optional[str] = None)[source]
does_collection_exist(self, collection_name: str, database_name: str)[source]

Checks if a collection exists in CosmosDB.

create_collection(self, collection_name: str, database_name: Optional[str] = None)[source]

Creates a new collection in the CosmosDB database.

does_database_exist(self, database_name: str)[source]

Checks if a database exists in CosmosDB.

create_database(self, database_name: str)[source]

Creates a new database in CosmosDB.

delete_database(self, database_name: str)[source]

Deletes an existing database in CosmosDB.

delete_collection(self, collection_name: str, database_name: Optional[str] = None)[source]

Deletes an existing collection in the CosmosDB database.

upsert_document(self, document, database_name=None, collection_name=None, document_id=None)[source]

Inserts a new document (or updates an existing one) into an existing collection in the CosmosDB database.

insert_documents(self, documents, database_name: Optional[str] = None, collection_name: Optional[str] = None)[source]

Insert a list of new documents into an existing collection in the CosmosDB database.

delete_document(self, document_id: str, database_name: Optional[str] = None, collection_name: Optional[str] = None)[source]

Delete an existing document out of a collection in the CosmosDB database.

get_document(self, document_id: str, database_name: Optional[str] = None, collection_name: Optional[str] = None)[source]

Get a document from an existing collection in the CosmosDB database.

get_documents(self, sql_string: str, database_name: Optional[str] = None, collection_name: Optional[str] = None, partition_key: Optional[str] = None)[source]

Get a list of documents from an existing collection in the CosmosDB database via SQL query.

Get Azure CosmosDB database link
Get Azure CosmosDB collection link
Get Azure CosmosDB document link

Was this entry helpful?