INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Upserts a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. :return: The upserted UDF. :rtype: dict
def UpsertUserDefinedFunction(self, collection_link, udf, options=None): """Upserts a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. ...
Reads a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The read UDF. :rtype: dict
def ReadUserDefinedFunction(self, udf_link, options=None): """Reads a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The read UDF. :rtype: ...
Reads all store procedures in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of Stored Procedures. :rtype: query_iterable.Qu...
def ReadStoredProcedures(self, collection_link, options=None): """Reads all store procedures in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query It...
Creates a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The created Stored Procedure. :rtype: ...
def CreateStoredProcedure(self, collection_link, sproc, options=None): """Creates a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. ...
Upserts a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The upserted Stored Procedure. :rtype: ...
def UpsertStoredProcedure(self, collection_link, sproc, options=None): """Upserts a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. ...
Reads a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The read Stored Procedure. :rtype: dict
def ReadStoredProcedure(self, sproc_link, options=None): """Reads a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The read Stored Procedure. :rtyp...
Reads conflicts. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Conflicts. :rtype: query_iterable.QueryIterable
def ReadConflicts(self, collection_link, feed_options=None): """Reads conflicts. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Conflicts. :rtype: query_iterable.QueryIter...
Reads a conflict. :param str conflict_link: The link to the conflict. :param dict options: :return: The read Conflict. :rtype: dict
def ReadConflict(self, conflict_link, options=None): """Reads a conflict. :param str conflict_link: The link to the conflict. :param dict options: :return: The read Conflict. :rtype: dict """ if options is None: o...
Deletes a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The deleted Collection. :rtype: dict
def DeleteContainer(self, collection_link, options=None): """Deletes a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The deleted Collection. :rt...
Replaces a document and returns it. :param str document_link: The link to the document. :param dict new_document: :param dict options: The request options for the request. :return: The new Document. :rtype: dict
def ReplaceItem(self, document_link, new_document, options=None): """Replaces a document and returns it. :param str document_link: The link to the document. :param dict new_document: :param dict options: The request options for the request. :return: ...
Deletes a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: The deleted Document. :rtype: dict
def DeleteItem(self, document_link, options=None): """Deletes a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: The deleted Document. :rtype: dict ...
Creates an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to create. :param dict options: The request options for the request. :return: The created Attachm...
def CreateAttachment(self, document_link, attachment, options=None): """Creates an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to create. :param dict options: The re...
Upserts an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to upsert. :param dict options: The request options for the request. :return: The upserted Attach...
def UpsertAttachment(self, document_link, attachment, options=None): """Upserts an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to upsert. :param dict options: The re...
Creates an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The created Attachment. :rtype: ...
def CreateAttachmentAndUploadMedia(self, document_link, readable_stream, options=None): """Creates an attachment and upload media. :param str document_link: The link to the d...
Upserts an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The upserted Attachment. :rtype: ...
def UpsertAttachmentAndUploadMedia(self, document_link, readable_stream, options=None): """Upserts an attachment and upload media. :param str document_link: The link to the d...
Reads an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The read Attachment. :rtype: dict
def ReadAttachment(self, attachment_link, options=None): """Reads an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The read Attachment. :rtype: ...
Reads all attachments in a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_iterable.QueryIterable
def ReadAttachments(self, document_link, options=None): """Reads all attachments in a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: Query Iterable of Attachments. ...
Queries attachments in a document. :param str document_link: The link to the document. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_ite...
def QueryAttachments(self, document_link, query, options=None): """Queries attachments in a document. :param str document_link: The link to the document. :param (str or dict) query: :param dict options: The request options for the request. :return: ...
Reads a media. When self.connection_policy.MediaReadMode == documents.MediaReadMode.Streamed, returns a file-like stream object; otherwise, returns a str. :param str media_link: The link to the media. :return: The read Media. :rtype: ...
def ReadMedia(self, media_link): """Reads a media. When self.connection_policy.MediaReadMode == documents.MediaReadMode.Streamed, returns a file-like stream object; otherwise, returns a str. :param str media_link: The link to the media. :return: ...
Updates a media and returns it. :param str media_link: The link to the media. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The updated Media. :rtype: str or f...
def UpdateMedia(self, media_link, readable_stream, options=None): """Updates a media and returns it. :param str media_link: The link to the media. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. ...
Replaces an attachment and returns it. :param str attachment_link: The link to the attachment. :param dict attachment: :param dict options: The request options for the request. :return: The replaced Attachment :rtype: dict
def ReplaceAttachment(self, attachment_link, attachment, options=None): """Replaces an attachment and returns it. :param str attachment_link: The link to the attachment. :param dict attachment: :param dict options: The request options for the request. :r...
Deletes an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The deleted Attachment. :rtype: dict
def DeleteAttachment(self, attachment_link, options=None): """Deletes an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The deleted Attachment. :rtype: ...
Replaces a trigger and returns it. :param str trigger_link: The link to the trigger. :param dict trigger: :param dict options: The request options for the request. :return: The replaced Trigger. :rtype: dict
def ReplaceTrigger(self, trigger_link, trigger, options=None): """Replaces a trigger and returns it. :param str trigger_link: The link to the trigger. :param dict trigger: :param dict options: The request options for the request. :return: The...
Deletes a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The deleted Trigger. :rtype: dict
def DeleteTrigger(self, trigger_link, options=None): """Deletes a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The deleted Trigger. :rtype: dict ...
Replaces a user defined function and returns it. :param str udf_link: The link to the user defined function. :param dict udf: :param dict options: The request options for the request. :return: The new UDF. :rtype: dict
def ReplaceUserDefinedFunction(self, udf_link, udf, options=None): """Replaces a user defined function and returns it. :param str udf_link: The link to the user defined function. :param dict udf: :param dict options: The request options for the request. ...
Deletes a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The deleted UDF. :rtype: dict
def DeleteUserDefinedFunction(self, udf_link, options=None): """Deletes a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The deleted UDF. :...
Executes a store procedure. :param str sproc_link: The link to the stored procedure. :param dict params: List or None :param dict options: The request options for the request. :return: The Stored Procedure response. :rtype: ...
def ExecuteStoredProcedure(self, sproc_link, params, options=None): """Executes a store procedure. :param str sproc_link: The link to the stored procedure. :param dict params: List or None :param dict options: The request options for the request. ...
Replaces a stored procedure and returns it. :param str sproc_link: The link to the stored procedure. :param dict sproc: :param dict options: The request options for the request. :return: The replaced Stored Procedure. :rtype: dict
def ReplaceStoredProcedure(self, sproc_link, sproc, options=None): """Replaces a stored procedure and returns it. :param str sproc_link: The link to the stored procedure. :param dict sproc: :param dict options: The request options for the request. :retur...
Deletes a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The deleted Stored Procedure. :rtype: dict
def DeleteStoredProcedure(self, sproc_link, options=None): """Deletes a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The deleted Stored Procedure. ...
Deletes a conflict. :param str conflict_link: The link to the conflict. :param dict options: The request options for the request. :return: The deleted Conflict. :rtype: dict
def DeleteConflict(self, conflict_link, options=None): """Deletes a conflict. :param str conflict_link: The link to the conflict. :param dict options: The request options for the request. :return: The deleted Conflict. :rtype: dic...
Replaces an offer and returns it. :param str offer_link: The link to the offer. :param dict offer: :return: The replaced Offer. :rtype: dict
def ReplaceOffer(self, offer_link, offer): """Replaces an offer and returns it. :param str offer_link: The link to the offer. :param dict offer: :return: The replaced Offer. :rtype: dict """ CosmosClient.__ValidateResource(of...
Reads an offer. :param str offer_link: The link to the offer. :return: The read Offer. :rtype: dict
def ReadOffer(self, offer_link): """Reads an offer. :param str offer_link: The link to the offer. :return: The read Offer. :rtype: dict """ path = base.GetPathFromLink(offer_link) offer_id = base.GetResourceIdOrFullNameFromLi...
Gets database account info. :return: The Database Account. :rtype: documents.DatabaseAccount
def GetDatabaseAccount(self, url_connection=None): """Gets database account info. :return: The Database Account. :rtype: documents.DatabaseAccount """ if url_connection is None: url_connection = self.url_connection initial_headers = ...
Creates a Azure Cosmos resource and returns it. :param dict body: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The created Azure Cosmos re...
def Create(self, body, path, type, id, initial_headers, options=None): """Creates a Azure Cosmos resource and returns it. :param dict body: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request ...
Replaces a Azure Cosmos resource and returns it. :param dict resource: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The new Azure Cosmos r...
def Replace(self, resource, path, type, id, initial_headers, options=None): """Replaces a Azure Cosmos resource and returns it. :param dict resource: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: Th...
Upserts a Azure Cosmos resource and returns it. :param dict body: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The upserted Azure ...
def Upsert(self, body, path, type, id, initial_headers, options=None): """Upserts a Azure Cosmos resource and returns it. :param dict body: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The ...
Reads a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The upserted Azure Cosmos resource. :rtype: ...
def Read(self, path, type, id, initial_headers, options=None): """Reads a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :r...
Deletes a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The deleted Azure Cosmos resource. :rtype: ...
def DeleteResource(self, path, type, id, initial_headers, options=None): """Deletes a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request....
Azure Cosmos 'GET' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict)
def __Get(self, path, request, headers): """Azure Cosmos 'GET' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronized_requ...
Azure Cosmos 'POST' http request. :params str url: :params str path: :params (str, unicode, dict) body: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict)
def __Post(self, path, request, body, headers): """Azure Cosmos 'POST' http request. :params str url: :params str path: :params (str, unicode, dict) body: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, ...
Azure Cosmos 'DELETE' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict)
def __Delete(self, path, request, headers): """Azure Cosmos 'DELETE' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronize...
Query Feed for Document Collection resource. :param str path: Path to the document collection. :param str collection_id: Id of the document collection. :param (str or dict) query: :param dict options: The request options for the request. :para...
def QueryFeed(self, path, collection_id, query, options, partition_key_range_id = None): """Query Feed for Document Collection resource. :param str path: Path to the document collection. :param str collection_id: Id of the document collection. :param (str or dict...
Query for more than one Azure Cosmos resources. :param str path: :param str type: :param str id: :param function result_fn: :param function create_fn: :param (str or dict) query: :param dict options: The request options for the request. :param...
def __QueryFeed(self, path, type, id, result_fn, create_fn, query, options=None, partition_key_range_id=None): """Query for more than one Azure Cosmos r...
Checks and unifies the format of the query body. :raises TypeError: If query_body is not of expected type (depending on the query compatibility mode). :raises ValueError: If query_body is a dict but doesn\'t have valid query text. :raises SystemError: If the query compatibility mode is undefine...
def __CheckAndUnifyQueryFormat(self, query_body): """Checks and unifies the format of the query body. :raises TypeError: If query_body is not of expected type (depending on the query compatibility mode). :raises ValueError: If query_body is a dict but doesn\'t have valid query text. :ra...
Updates session if necessary. :param dict response_result: :param dict response_headers: :param dict response_headers :return: None, but updates the client session if necessary.
def _UpdateSessionIfRequired(self, request_headers, response_result, response_headers): """ Updates session if necessary. :param dict response_result: :param dict response_headers: :param dict response_headers :return: None, but updates the client sessio...
Gets HTTP request headers. :param cosmos_client.CosmosClient cosmos_client: :param dict default_headers: :param str verb: :param str path: :param str resource_id: :param str resource_type: :param dict options: :param str partition_key_range_id: :return: The HTTP request hea...
def GetHeaders(cosmos_client, default_headers, verb, path, resource_id, resource_type, options, partition_key_range_id = None): """Gets HTTP request headers. :param cosmos_client.CosmosClient cosmos_client:...
Gets resource id or full name from resource link. :param str resource_link: :return: The resource id or full name from the resource link. :rtype: str
def GetResourceIdOrFullNameFromLink(resource_link): """Gets resource id or full name from resource link. :param str resource_link: :return: The resource id or full name from the resource link. :rtype: str """ # For named based, the resource link is the full name if IsNameBased(reso...
Gets attachment id from media id. :param str media_id: :return: The attachment id from the media id. :rtype: str
def GetAttachmentIdFromMediaId(media_id): """Gets attachment id from media id. :param str media_id: :return: The attachment id from the media id. :rtype: str """ altchars = '+-' if not six.PY2: altchars = altchars.encode('utf-8') # altchars for '+' and '/'. We keep '+' ...
Gets path from resource link with optional resource type :param str resource_link: :param str resource_type: :return: Path from resource link with resource type appended (if provided). :rtype: str
def GetPathFromLink(resource_link, resource_type=''): """Gets path from resource link with optional resource type :param str resource_link: :param str resource_type: :return: Path from resource link with resource type appended (if provided). :rtype: str """ resource_link = TrimBegi...
Finds whether the link is name based or not :param str link: :return: True if link is name-based; otherwise, False. :rtype: boolean
def IsNameBased(link): """Finds whether the link is name based or not :param str link: :return: True if link is name-based; otherwise, False. :rtype: boolean """ if not link: return False # trimming the leading "/" if link.startswith('/') and len(link) > 1: lin...
Finds whether the link is a database Self Link or a database ID based link :param str link: Link to analyze :return: True or False. :rtype: boolean
def IsDatabaseLink(link): """Finds whether the link is a database Self Link or a database ID based link :param str link: Link to analyze :return: True or False. :rtype: boolean """ if not link: return False # trimming the leading and trailing "/" from the input str...
Given the self link and alt_content_path from the reponse header and result extract the collection name and collection id Ever response header has alt-content-path that is the owner's path in ascii. For document create / update requests, this can be used to get the collection name, but...
def GetItemContainerInfo(self_link, alt_content_path, id_from_response): """ Given the self link and alt_content_path from the reponse header and result extract the collection name and collection id Ever response header has alt-content-path that is the owner's path in ascii. For document c...
Gets the document collection link :param str link: Resource link :return: Document collection link. :rtype: str
def GetItemContainerLink(link): """Gets the document collection link :param str link: Resource link :return: Document collection link. :rtype: str """ link = TrimBeginningAndEndingSlashes(link) + '/' index = IndexOfNth(link, '/', 4) if index != -1: return...
Gets the index of Nth occurance of a given character in a string :param str s: Input string :param char value: Input char to be searched. :param int n: Nth occurrence of char to be searched. :return: Index of the Nth occurrence in the string. :rtype: int
def IndexOfNth(s, value, n): """Gets the index of Nth occurance of a given character in a string :param str s: Input string :param char value: Input char to be searched. :param int n: Nth occurrence of char to be searched. :return: Index of the Nth occurrence in the...
Verifies if a string is a valid Base64 encoded string, after replacing '-' with '/' :param string string_to_validate: String to validate. :return: Whether given string is a valid base64 string or not. :rtype: str
def IsValidBase64String(string_to_validate): """Verifies if a string is a valid Base64 encoded string, after replacing '-' with '/' :param string string_to_validate: String to validate. :return: Whether given string is a valid base64 string or not. :rtype: str """ # '-' is not ...
Trims beginning and ending slashes :param str path: :return: Path with beginning and ending slashes trimmed. :rtype: str
def TrimBeginningAndEndingSlashes(path): """Trims beginning and ending slashes :param str path: :return: Path with beginning and ending slashes trimmed. :rtype: str """ if path.startswith('/'): # Returns substring starting from index 1 to end of the string path = path[1...
Gets request body from data. When `data` is dict and list into unicode string; otherwise return `data` without making any change. :param (str, unicode, file-like stream object, dict, list or None) data: :rtype: str, unicode, file-like stream object, or None
def _RequestBodyFromData(data): """Gets request body from data. When `data` is dict and list into unicode string; otherwise return `data` without making any change. :param (str, unicode, file-like stream object, dict, list or None) data: :rtype: str, unicode, file-like stream object, or N...
Makes one http request using the requests module. :param _GlobalEndpointManager global_endpoint_manager: :param dict request: contains the resourceType, operationType, endpointOverride, useWriteEndpoint, useAlternateWriteEndpoint information :param documents.ConnectionPolicy connection_poli...
def _Request(global_endpoint_manager, request, connection_policy, requests_session, path, request_options, request_body): """Makes one http request using the requests module. :param _GlobalEndpointManager global_endpoint_manager: :param dict request: contains the resourceType, operationType, endpoi...
Performs one synchronized http request according to the parameters. :param object client: Document client instance :param dict request: :param _GlobalEndpointManager global_endpoint_manager: :param documents.ConnectionPolicy connection_policy: :param requests.Session requests_session: ...
def SynchronizedRequest(client, request, global_endpoint_manager, connection_policy, requests_session, method, path, request_data, ...
Gets the range containing the given partition key :param str effective_partition_key_value: The partition key value. :return: The partition key range. :rtype: dict
def get_range_by_effective_partition_key(self, effective_partition_key_value): """Gets the range containing the given partition key :param str effective_partition_key_value: The partition key value. :return: The partition key range. :rtype: dict """ ...
Gets the partition key range given the partition key range id :param str partition_key_range_id: The partition key range id. :return: The partition key range. :rtype: dict
def get_range_by_partition_key_range_id(self, partition_key_range_id): """Gets the partition key range given the partition key range id :param str partition_key_range_id: The partition key range id. :return: The partition key range. :rtype: dict """ ...
Gets the partition key ranges overlapping the provided ranges :param list provided_partition_key_ranges: List of partition key ranges. :return: List of partition key ranges, where each is a dict. :rtype: list
def get_overlapping_ranges(self, provided_partition_key_ranges): """Gets the partition key ranges overlapping the provided ranges :param list provided_partition_key_ranges: List of partition key ranges. :return: List of partition key ranges, where each is a dict. ...
Gets the authorization header. :param cosmos_client.CosmosClient cosmos_client: :param str verb: :param str path: :param str resource_id_or_fullname: :param str resource_type: :param dict headers: :return: The authorization headers. :rtype: dict
def GetAuthorizationHeader(cosmos_client, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers): """Gets the authorization header. ...
Gets the authorization token using `master_key. :param str verb: :param str resource_id_or_fullname: :param str resource_type: :param dict headers: :param str master_key: :return: The authorization token. :rtype: dict
def __GetAuthorizationTokenUsingMasterKey(verb, resource_id_or_fullname, resource_type, headers, master_key): """Gets the authorization token using `mas...
Get the authorization token using `resource_tokens`. :param dict resource_tokens: :param str path: :param str resource_id_or_fullname: :return: The authorization token. :rtype: dict
def __GetAuthorizationTokenUsingResourceTokens(resource_tokens, path, resource_id_or_fullname): """Get the authorization token using `resource_tokens`. :param dict resource_tokens: :param str path: :param str re...
Execute the most basic Create of collection. This will create a collection with 400 RUs throughput and default indexing policy
def create_Container(client, id): """ Execute the most basic Create of collection. This will create a collection with 400 RUs throughput and default indexing policy """ print("\n2.1 Create Collection - Basic") try: client.CreateContainer(database_link, {"id": id}) ...
Get Session Token for collection_link :param str resource_path: Self link / path to the resource :return: Session Token dictionary for the collection_id :rtype: dict
def get_session_token(self, resource_path): """ Get Session Token for collection_link :param str resource_path: Self link / path to the resource :return: Session Token dictionary for the collection_id :rtype: dict """ ...
Session token must only be updated from response of requests that successfully mutate resource on the server side (write, replace, delete etc) :param dict response_result: :param dict response_headers: :return: - None
def set_session_token(self, response_result, response_headers): """ Session token must only be updated from response of requests that successfully mutate resource on the server side (write, replace, delete etc) :param dict response_result: :param dict response_headers...
Extracts session token from response headers and parses :param dict response_headers: :return: A dictionary of partition id to session lsn for given collection :rtype: dict
def parse_session_token(response_headers): """ Extracts session token from response headers and parses :param dict response_headers: :return: A dictionary of partition id to session lsn for given collection :rtype: dict """ # extract sessio...
Generate color stops array for use with match expression in mapbox template
def generate_vector_color_map(self): """Generate color stops array for use with match expression in mapbox template""" vector_stops = [] # if join data specified as filename or URL, parse JSON to list of Python dicts if type(self.data) == str: self.data = geojson_to_dict_lis...
Generate stops array for use with match expression in mapbox template
def generate_vector_numeric_map(self, numeric_property): """Generate stops array for use with match expression in mapbox template""" vector_stops = [] function_type = getattr(self, '{}_function_type'.format(numeric_property)) lookup_property = getattr(self, '{}_property'.format(...
Determines if features are defined as vector source based on MapViz arguments.
def check_vector_template(self): """Determines if features are defined as vector source based on MapViz arguments.""" if self.vector_url is not None and self.vector_layer_name is not None: self.template = 'vector_' + self.template self.vector_source = True else: ...
Build the HTML representation for the mapviz.
def as_iframe(self, html_data): """Build the HTML representation for the mapviz.""" srcdoc = html_data.replace('"', "'") return ('<iframe id="{div_id}", srcdoc="{srcdoc}" style="width: {width}; ' 'height: {height};"></iframe>'.format( div_id=self.div_id, ...
Create a circle visual from a geojson data source
def create_html(self, filename=None): """Create a circle visual from a geojson data source""" if isinstance(self.style, str): style = "'{}'".format(self.style) else: style = self.style options = dict( gl_js_version=GL_JS_VERSION, ...
Update map template variables specific to circle visual
def add_unique_template_variables(self, options): """Update map template variables specific to circle visual""" options.update(dict( geojson_data=json.dumps(self.data, ensure_ascii=False), colorProperty=self.color_property, colorType=self.color_function_type, ...
Update map template variables specific to graduated circle visual
def add_unique_template_variables(self, options): """Update map template variables specific to graduated circle visual""" options.update(dict( colorProperty=self.color_property, colorStops=self.color_stops, colorType=self.color_function_type, radiusType=se...
Update map template variables specific to heatmap visual
def add_unique_template_variables(self, options): """Update map template variables specific to heatmap visual""" options.update(dict( colorStops=self.color_stops, radiusStops=self.radius_stops, weightProperty=self.weight_property, weightStops=self.weight_s...
Update map template variables specific to a clustered circle visual
def add_unique_template_variables(self, options): """Update map template variables specific to a clustered circle visual""" options.update(dict( colorStops=self.color_stops, colorDefault=self.color_default, radiusStops=self.radius_stops, clusterRadius=self...
Update map template variables specific to heatmap visual
def add_unique_template_variables(self, options): """Update map template variables specific to heatmap visual""" # set line stroke dash interval based on line_stroke property if self.line_stroke in ["dashed", "--"]: self.line_dash_array = [6, 4] elif self.line_stroke in ["do...
Update map template variables specific to image visual
def add_unique_template_variables(self, options): """Update map template variables specific to image visual""" options.update(dict( image=self.image, coordinates=self.coordinates))
Update map template variables specific to a raster visual
def add_unique_template_variables(self, options): """Update map template variables specific to a raster visual""" options.update(dict( tiles_url=self.tiles_url, tiles_size=self.tiles_size, tiles_minzoom=self.tiles_minzoom, tiles_maxzoom=self.tiles_maxzoom,...
Update map template variables specific to linestring visual
def add_unique_template_variables(self, options): """Update map template variables specific to linestring visual""" # set line stroke dash interval based on line_stroke property if self.line_stroke in ["dashed", "--"]: self.line_dash_array = [6, 4] elif self.line_stroke in [...
Convert a pandas dataframe row to a geojson format object. Converts all datetimes to epoch seconds.
def row_to_geojson(row, lon, lat, precision, date_format='epoch'): """Convert a pandas dataframe row to a geojson format object. Converts all datetimes to epoch seconds. """ # Let pandas handle json serialization row_json = json.loads(row.to_json(date_format=date_format, date_unit='s')) return geo...
Serialize a Pandas dataframe to a geojson format Python dictionary / file
def df_to_geojson(df, properties=None, lat='lat', lon='lon', precision=6, date_format='epoch', filename=None): """Serialize a Pandas dataframe to a geojson format Python dictionary / file """ if not properties: # if no properties are selected, use all properties in dataframe properties = [c...
Parse GeoJSON-formatted information in <data> to list of Python dicts
def geojson_to_dict_list(data): """Parse GeoJSON-formatted information in <data> to list of Python dicts""" # return data formatted as list or dict if type(data) in (list, dict): return data # read from data defined as local file address try: with open(data, 'r') as f: ...
Serialize a GeoPandas dataframe to a geojson format Python dictionary / file
def gdf_to_geojson(gdf, date_format='epoch', properties=None, filename=None): """Serialize a GeoPandas dataframe to a geojson format Python dictionary / file """ # convert dates/datetimes to preferred string format if specified gdf = convert_date_columns(gdf, date_format) gdf_out = gdf[['geometry'...
Convert dates/datetimes to preferred string format if specified i.e. '%Y-%m-%d', 'epoch', 'iso'
def convert_date_columns(df, date_format='epoch'): """Convert dates/datetimes to preferred string format if specified i.e. '%Y-%m-%d', 'epoch', 'iso' """ if date_format not in ['epoch', 'iso']: if '%' in date_format: try: datetime.datetime.now().strftime(date_for...
Scale a min and max value to equal interval domain with numStops discrete values
def scale_between(minval, maxval, numStops): """ Scale a min and max value to equal interval domain with numStops discrete values """ scale = [] if numStops < 2: return [minval, maxval] elif maxval < minval: raise ValueError() else: domain = maxval - minval ...
Convert a data breaks into a radius ramp
def create_radius_stops(breaks, min_radius, max_radius): """Convert a data breaks into a radius ramp """ num_breaks = len(breaks) radius_breaks = scale_between(min_radius, max_radius, num_breaks) stops = [] for i, b in enumerate(breaks): stops.append([b, radius_breaks[i]]) return st...
Convert data breaks into a heatmap-weight ramp
def create_weight_stops(breaks): """Convert data breaks into a heatmap-weight ramp """ num_breaks = len(breaks) weight_breaks = scale_between(0, 1, num_breaks) stops = [] for i, b in enumerate(breaks): stops.append([b, weight_breaks[i]]) return stops
Convert data breaks into a general numeric ramp (height, radius, weight, etc.)
def create_numeric_stops(breaks, min_value, max_value): """Convert data breaks into a general numeric ramp (height, radius, weight, etc.) """ weight_breaks = scale_between(min_value, max_value, len(breaks)) return [list(x) for x in zip(breaks, weight_breaks)]
Convert a list of breaks into color stops using colors from colorBrewer or a custom list of color values in RGB, RGBA, HSL, CSS text, or HEX format. See www.colorbrewer2.org for a list of color options to pass
def create_color_stops(breaks, colors='RdYlGn', color_ramps=color_ramps): """Convert a list of breaks into color stops using colors from colorBrewer or a custom list of color values in RGB, RGBA, HSL, CSS text, or HEX format. See www.colorbrewer2.org for a list of color options to pass """ num_brea...
Convert color in format 'rgb(RRR,GGG,BBB)', 'rgba(RRR,GGG,BBB,alpha)', '#RRGGBB', or limited English color name (eg 'red') to tuple (RRR, GGG, BBB)
def rgb_tuple_from_str(color_string): """Convert color in format 'rgb(RRR,GGG,BBB)', 'rgba(RRR,GGG,BBB,alpha)', '#RRGGBB', or limited English color name (eg 'red') to tuple (RRR, GGG, BBB) """ try: # English color names (limited) rgb_string = common_html_colors[color_string] re...
Return an rgb color value interpolated from given color_stops; assumes colors in color_stops provided as strings of form 'rgb(RRR,GGG,BBB)' or in hex: '#RRGGBB'
def color_map(lookup, color_stops, default_color='rgb(122,122,122)'): """Return an rgb color value interpolated from given color_stops; assumes colors in color_stops provided as strings of form 'rgb(RRR,GGG,BBB)' or in hex: '#RRGGBB' """ # if no color_stops, use default color if len(color_stops)...
Return a number value interpolated from given numeric_stops
def numeric_map(lookup, numeric_stops, default=0.0): """Return a number value interpolated from given numeric_stops """ # if no numeric_stops, use default if len(numeric_stops) == 0: return default # dictionary to lookup value from match-type numeric_stops match_map = dict((x, y) fo...
Encode ndarray to base64 string image data Parameters ---------- arr: ndarray (rows, cols, depth) kwargs: passed directly to matplotlib.image.imsave
def img_encode(arr, **kwargs): """Encode ndarray to base64 string image data Parameters ---------- arr: ndarray (rows, cols, depth) kwargs: passed directly to matplotlib.image.imsave """ sio = BytesIO() imsave(sio, arr, **kwargs) sio.seek(0) img_format = kwargs['format'] if ...
Return a height value (in meters) interpolated from given height_stops; for use with vector-based visualizations using fill-extrusion layers
def height_map(lookup, height_stops, default_height=0.0): """Return a height value (in meters) interpolated from given height_stops; for use with vector-based visualizations using fill-extrusion layers """ # if no height_stops, use default height if len(height_stops) == 0: return default_hei...
Loads YAML from docstring.
def load_yaml_from_docstring(docstring): """Loads YAML from docstring.""" split_lines = trim_docstring(docstring).split("\n") # Cut YAML from rest of docstring for index, line in enumerate(split_lines): line = line.strip() if line.startswith("---"): cut_from = index ...
Return a dictionary of OpenAPI operations parsed from a a docstring.
def load_operations_from_docstring(docstring): """Return a dictionary of OpenAPI operations parsed from a a docstring. """ doc_data = load_yaml_from_docstring(docstring) return { key: val for key, val in iteritems(doc_data) if key in PATH_KEYS or key.startswith("x-") }
Return schema instance for given schema (instance or class) :param type|Schema|str schema: instance, class or class name of marshmallow.Schema :return: schema instance of given schema (instance or class)
def resolve_schema_instance(schema): """Return schema instance for given schema (instance or class) :param type|Schema|str schema: instance, class or class name of marshmallow.Schema :return: schema instance of given schema (instance or class) """ if isinstance(schema, type) and issubclass(schema, ...