airflow.providers.microsoft.azure.hooks.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

Classes

AzureCosmosDBHook

Interacts with Azure CosmosDB.

Functions

get_database_link(database_id)

Get Azure CosmosDB database link

get_collection_link(database_id, collection_id)

Get Azure CosmosDB collection link

get_document_link(database_id, collection_id, document_id)

Get Azure CosmosDB document link

class airflow.providers.microsoft.azure.hooks.cosmos.AzureCosmosDBHook(azure_cosmos_conn_id=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]
static get_connection_form_widgets()[source]

Returns connection widgets to add to connection form

static get_ui_field_behaviour()[source]

Returns custom field behaviour

get_conn()[source]

Return a cosmos db client.

does_collection_exist(collection_name, database_name)[source]

Checks if a collection exists in CosmosDB.

create_collection(collection_name, database_name=None, partition_key=None)[source]

Creates a new collection in the CosmosDB database.

does_database_exist(database_name)[source]

Checks if a database exists in CosmosDB.

create_database(database_name)[source]

Creates a new database in CosmosDB.

delete_database(database_name)[source]

Deletes an existing database in CosmosDB.

delete_collection(collection_name, database_name=None)[source]

Deletes an existing collection in the CosmosDB database.

upsert_document(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(documents, database_name=None, collection_name=None)[source]

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

delete_document(document_id, database_name=None, collection_name=None, partition_key=None)[source]

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

get_document(document_id, database_name=None, collection_name=None, partition_key=None)[source]

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

get_documents(sql_string, database_name=None, collection_name=None, partition_key=None)[source]

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

test_connection()[source]

Test a configured Azure Cosmos connection.

Get Azure CosmosDB database link

Get Azure CosmosDB collection link

Get Azure CosmosDB document link

Was this entry helpful?