PYDOCUMENTDB(1) | pydocumentdb | PYDOCUMENTDB(1) |
NAME¶
pydocumentdb - pydocumentdb 2.3.3
SYSTEM REQUIREMENTS:¶
Python Tools for Visual Studio is required when using Microsoft Visual Studio to develop Python applications. To download Python Tools for Visual Studio, please visit http://microsoft.github.io/PTVS.
INSTALLATION:¶
- 1.
- Download the Azure DocumentDB Python SDK source from https://github.com/Azure/azure-documentdb-python which is needed to manage the Azure DocumentDB database service.
- 2.
- Execute the following setup script in bash shell:
$ python setup.py install
Method 2:
- 1.
- Install the Azure DocumentDB Python SDK using pip. For more information on pip, please visit https://pypi.python.org/pypi/pip
- 2.
- Execute the following in bash shell:
$ pip install pydocumentdb
TO RUN TESTS:¶
$ python -m unittest discover -s .\test -p "*.py"
If you use Microsoft Visual Studio, open the project file python.pyproj, and run all the tests in Test Explorer.
TO GENERATE DOCUMENTATIONS:¶
$ cd doc $ sphinx-apidoc -f -e -o api ..\pydocumentdb $ make.bat html
- genindex
- modindex
- search
PYDOCUMENTDB PACKAGE¶
Subpackages¶
pydocumentdb.execution_context package¶
Submodules¶
pydocumentdb.execution_context.aggregators module¶
Internal class for aggregation queries implementation in the Azure Cosmos DB database service.
pydocumentdb.execution_context.base_execution_context module¶
Internal class for query execution context implementation in the Azure Cosmos DB database service.
pydocumentdb.execution_context.document_producer module¶
Internal class for document producer implementation in the Azure Cosmos DB database service.
pydocumentdb.execution_context.endpoint_component module¶
Internal class for query execution endpoint component implementation in the Azure Cosmos DB database service.
pydocumentdb.execution_context.execution_dispatcher module¶
Internal class for proxy query execution context implementation in the Azure Cosmos DB database service.
pydocumentdb.execution_context.multi_execution_aggregator module¶
Internal class for multi execution context aggregator implementation in the Azure Cosmos DB database service.
pydocumentdb.execution_context.query_execution_info module¶
Internal class for partitioned query execution info implementation in the Azure Cosmos DB database service.
Module contents¶
pydocumentdb.routing package¶
Submodules¶
pydocumentdb.routing.collection_routing_map module¶
Internal class for collection routing map implementation in the Azure Cosmos DB database service.
pydocumentdb.routing.routing_map_provider module¶
Internal class for partition key range cache implementation in the Azure Cosmos DB database service.
pydocumentdb.routing.routing_range module¶
Internal class for partition key range implementation in the Azure Cosmos DB database service.
Module contents¶
Submodules¶
pydocumentdb.auth module¶
Authorization helper functions in the Azure Cosmos DB database service.
- pydocumentdb.auth.GetAuthorizationHeader(document_client, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers)
- Gets the authorization header.
- document_client (document_client.DocumentClient) --
- verb (str) --
- path (str) --
- resource_id_or_fullname (str) --
- resource_type (str) --
- headers (dict) --
- Returns
- The authorization headers.
- Return type
- dict
pydocumentdb.base module¶
Base functions in the Azure Cosmos DB database service.
- pydocumentdb.base.DecodeBase64String(string_to_decode)
- Decodes a Base64 encoded string by replacing '-' with '/'
- Parameters
- string_to_decode (string) -- String to decode.
- Returns
- Path with beginning and ending slashes trimmed.
- Return type
- str
- pydocumentdb.base.GenerateGuidId()
- Gets a random GUID.
Note that here we use python's UUID generation library. Basically UUID is the same as GUID when represented as a string.
- Returns
- The generated random GUID.
- Return type
- str
- pydocumentdb.base.GetAttachmentIdFromMediaId(media_id)
- Gets attachment id from media id.
- Parameters
- media_id (str) --
- Returns
- The attachment id from the media id.
- Return type
- 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 for collection create response, we can't use it. So we also rely on
- self_link (str) -- Self link of the resource, as obtained from response result.
- alt_content_path (str) -- Owner path of the resource, as obtained from response header.
- resource_id (str) -- .INDENT 2.0
- 'id' as returned from the response result. This is only used if it is deduced that the
- request was to create a collection.
- Returns
- tuple of (collection rid, collection name)
- Return type
- tuple
- pydocumentdb.base.GetDocumentCollectionLink(link)
- Gets the document collection link
- Parameters
- link (str) -- Resource link
- Returns
- Document collection link.
- Return type
- str
- pydocumentdb.base.GetHeaders(document_client, default_headers, verb, path, resource_id, resource_type, options, partition_key_range_id=None)
- Gets HTTP request headers.
- document_client (document_client.DocumentClient) --
- default_headers (dict) --
- verb (str) --
- path (str) --
- resource_id (str) --
- resource_type (str) --
- options (dict) --
- partition_key_range_id (str) --
- Returns
- The HTTP request headers.
- Return type
- dict
- pydocumentdb.base.GetPathFromLink(resource_link, resource_type='')
- Gets path from resource link with optional resource type
- resource_link (str) --
- resource_type (str) --
- Returns
- Path from resource link with resource type appended (if provided).
- Return type
- str
- pydocumentdb.base.GetResourceIdOrFullNameFromLink(resource_link)
- Gets resource id or full name from resource link.
- Parameters
- resource_link (str) --
- Returns
- The resource id or full name from the resource link.
- Return type
- str
- pydocumentdb.base.IndexOfNth(s, value, n)
- Gets the index of Nth occurance of a given character in a string
- s (str) -- Input string
- value (char) -- Input char to be searched.
- n (int) -- Nth occurrence of char to be searched.
- Returns
- Index of the Nth occurrence in the string.
- Return type
- int
- pydocumentdb.base.IsDatabaseLink(link)
- Finds whether the link is a database Self Link or a database ID based link
- Parameters
- link (str) -- Link to analyze
- Returns
- True or False.
- Return type
- boolean
- pydocumentdb.base.IsDocumentCollectionLink(link)
- Finds whether the link is a document colllection Self Link or a document colllection ID based link
- Parameters
- link (str) -- Link to analyze
- Returns
- True or False.
- Return type
- boolean
- pydocumentdb.base.IsNameBased(link)
- Finds whether the link is name based or not
- Parameters
- link (str) --
- Returns
- True if link is name-based; otherwise, False.
- Return type
- boolean
- pydocumentdb.base.TrimBeginningAndEndingSlashes(path)
- Trims beginning and ending slashes
- Parameters
- path (str) --
- Returns
- Path with beginning and ending slashes trimmed.
- Return type
- str
pydocumentdb.consistent_hash_ring module¶
Internal class for consistent hash ring implementation in the Azure Cosmos DB database service.
pydocumentdb.constants module¶
Class for defining internal constants in the Azure Cosmos DB database service.
pydocumentdb.default_retry_policy module¶
Internal class for connection reset retry policy implementation in the Azure Cosmos DB database service.
pydocumentdb.document_client module¶
Document client class for the Azure Cosmos DB database service.
- class pydocumentdb.document_client.DocumentClient(url_connection, auth, connection_policy=None, consistency_level='Session')
- Bases: object
Represents a document client.
Provides a client-side logical representation of the Azure Cosmos DB service. This client is used to configure and execute requests against the service.
The service client encapsulates the endpoint and credentials used to access the Azure Cosmos DB service.
- url_connection (str) -- The URL for connecting to the DB server.
- auth (dict) -- Contains 'masterKey' or 'resourceTokens', where auth['masterKey'] is the default authorization key to use to create the client, and auth['resourceTokens'] is the alternative authorization key.
- connection_policy (documents.ConnectionPolicy) -- The connection policy for the client.
- consistency_level (documents.ConsistencyLevel) -- The default consistency policy for client operations.
- Create(body, path, type, id, initial_headers, options=None)
- Creates a Azure Cosmos DB resource and returns it.
- body (dict) --
- path (str) --
- type (str) --
- id (str) --
- initial_headers (dict) --
- options (dict) -- The request options for the request.
- Returns
- The created Azure Cosmos DB resource.
- Return type
- dict
- CreateAttachment(document_link, attachment, options=None)
- Creates an attachment in a document.
- document_link (str) -- The link to the document.
- attachment (dict) -- The Azure Cosmos DB attachment to create.
- options (dict) -- The request options for the request.
- Returns
- The created Attachment.
- Return type
- dict
- CreateAttachmentAndUploadMedia(document_link, readable_stream, options=None)
- Creates an attachment and upload media.
- document_link (str) -- The link to the document.
- stream object) readable_stream ((file-like) --
- options (dict) -- The request options for the request.
- Returns
- The created Attachment.
- Return type
- dict
- CreateCollection(database_link, collection, options=None)
- Creates a collection in a database.
- database_link (str) -- The link to the database.
- collection (dict) -- The Azure Cosmos DB collection to create.
- options (dict) -- The request options for the request.
- Returns
- The Collection that was created.
- Return type
- dict
- CreateDatabase(database, options=None)
- Creates a database.
- database (dict) -- The Azure Cosmos DB database to create.
- options (dict) -- The request options for the request.
- Returns
- The Database that was created.
- Return type
- dict
- CreateDocument(database_or_collection_link, document, options=None)
- Creates a document in a collection.
- database_or_collection_link (str) -- The link to the database when using partitioning, otherwise link to the document collection.
- document (dict) -- The Azure Cosmos DB document to create.
- options (dict) -- The request options for the request.
- options['disableAutomaticIdGeneration'] (bool) -- Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned.
- Returns
- The created Document.
- Return type
- dict
- CreatePermission(user_link, permission, options=None)
- Creates a permission for a user.
- user_link (str) -- The link to the user entity.
- permission (dict) -- The Azure Cosmos DB user permission to create.
- options (dict) -- The request options for the request.
- Returns
- The created Permission.
- Return type
- dict
- CreateStoredProcedure(collection_link, sproc, options=None)
- Creates a stored procedure in a collection.
- collection_link (str) -- The link to the document collection.
- sproc (str) --
- options (dict) -- The request options for the request.
- Returns
- The created Stored Procedure.
- Return type
- dict
- CreateTrigger(collection_link, trigger, options=None)
- Creates a trigger in a collection.
- collection_link (str) -- The link to the document collection.
- trigger (dict) --
- options (dict) -- The request options for the request.
- Returns
- The created Trigger.
- Return type
- dict
- CreateUser(database_link, user, options=None)
- Creates a user.
- database_link (str) -- The link to the database.
- user (dict) -- The Azure Cosmos DB user to create.
- options (dict) -- The request options for the request.
- Returns
- The created User.
- Return type
- dict
- CreateUserDefinedFunction(collection_link, udf, options=None)
- Creates a user defined function in a collection.
- collection_link (str) -- The link to the collection.
- udf (str) --
- options (dict) -- The request options for the request.
- Returns
- The created UDF.
- Return type
- dict
- DeleteAttachment(attachment_link, options=None)
- Deletes an attachment.
- attachment_link (str) -- The link to the attachment.
- options (dict) -- The request options for the request.
- Returns
- The deleted Attachment.
- Return type
- dict
- DeleteCollection(collection_link, options=None)
- Deletes a collection.
- collection_link (str) -- The link to the document collection.
- options (dict) -- The request options for the request.
- Returns
- The deleted Collection.
- Return type
- dict
- DeleteConflict(conflict_link, options=None)
- Deletes a conflict.
- conflict_link (str) -- The link to the conflict.
- options (dict) -- The request options for the request.
- Returns
- The deleted Conflict.
- Return type
- dict
- DeleteDatabase(database_link, options=None)
- Deletes a database.
- database_link (str) -- The link to the database.
- options (dict) -- The request options for the request.
- Returns
- The deleted Database.
- Return type
- dict
- DeleteDocument(document_link, options=None)
- Deletes a document.
- document_link (str) -- The link to the document.
- options (dict) -- The request options for the request.
- Returns
- The deleted Document.
- Return type
- dict
- DeletePermission(permission_link, options=None)
- Deletes a permission.
- permission_link (str) -- The link to the permission.
- options (dict) -- The request options for the request.
- Returns
- The deleted Permission.
- Return type
- dict
- DeleteResource(path, type, id, initial_headers, options=None)
- Deletes a Azure Cosmos DB resource and returns it.
- path (str) --
- type (str) --
- id (str) --
- initial_headers (dict) --
- options (dict) -- The request options for the request.
- Returns
- The deleted Azure Cosmos DB resource.
- Return type
- dict
- DeleteStoredProcedure(sproc_link, options=None)
- Deletes a stored procedure.
- sproc_link (str) -- The link to the stored procedure.
- options (dict) -- The request options for the request.
- Returns
- The deleted Stored Procedure.
- Return type
- dict
- DeleteTrigger(trigger_link, options=None)
- Deletes a trigger.
- trigger_link (str) -- The link to the trigger.
- options (dict) -- The request options for the request.
- Returns
- The deleted Trigger.
- Return type
- dict
- DeleteUser(user_link, options=None)
- Deletes a user.
- user_link (str) -- The link to the user entity.
- options (dict) -- The request options for the request.
- Returns
- The deleted user.
- Return type
- dict
- DeleteUserDefinedFunction(udf_link, options=None)
- Deletes a user defined function.
- udf_link (str) -- The link to the user defined function.
- options (dict) -- The request options for the request.
- Returns
- The deleted UDF.
- Return type
- dict
- ExecuteStoredProcedure(sproc_link, params, options=None)
- Executes a store procedure.
- sproc_link (str) -- The link to the stored procedure.
- params (dict) -- List or None
- options (dict) -- The request options for the request.
- Returns
- The Stored Procedure response.
- Return type
- dict
- GetDatabaseAccount(url_connection=None)
- Gets database account info.
- Returns
- The Database Account.
- Return type
- documents.DatabaseAccount
- GetPartitionResolver(database_link)
- Gets the partition resolver associated with the database link
- Parameters
- database_link (str) -- Database self link or ID based link.
- Returns
- An instance of PartitionResolver.
- Return type
- object
- QueryAttachments(document_link, query, options=None)
- Queries attachments in a document.
- document_link (str) -- The link to the document.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Attachments.
- Return type
- query_iterable.QueryIterable
- QueryCollections(database_link, query, options=None)
- Queries collections in a database.
- database_link (str) -- The link to the database.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Collections.
- Return type
- query_iterable.QueryIterable
- QueryConflicts(collection_link, query, options=None)
- Queries conflicts in a collection.
- collection_link (str) -- The link to the document collection.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Conflicts.
- Return type
- query_iterable.QueryIterable
- QueryDatabases(query, options=None)
- Queries databases.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Databases.
- Return type
- query_iterable.QueryIterable
- QueryDocuments(database_or_collection_link, query, options=None, partition_key=None)
- Queries documents in a collection.
- database_or_collection_link (str) -- The link to the database when using partitioning, otherwise link to the document collection.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- partition_key (str) -- Partition key for the query(default value None)
- Returns
- Query Iterable of Documents.
- Return type
- query_iterable.QueryIterable
- QueryDocumentsChangeFeed(collection_link, options=None)
- Queries documents change feed in a collection.
- collection_link (str) -- The link to the document collection.
- options (dict) -- The request options for the request. options may also specify partition key range id.
- Returns
- Query Iterable of Documents.
- Return type
- query_iterable.QueryIterable
- QueryFeed(path, collection_id, query, options, partition_key_range_id=None)
- Query Feed for Document Collection resource.
- path (str) -- Path to the document collection.
- collection_id (str) -- Id of the document collection.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- partition_key_range_id (str) -- Partition key range id.
- Return type
- tuple
- QueryOffers(query, options=None)
- Query for all offers.
- or dict) query ((str) --
- options (dict) -- The request options for the request
- Returns
- Query Iterable of Offers.
- Return type
- query_iterable.QueryIterable
- QueryPermissions(user_link, query, options=None)
- Queries permissions for a user.
- user_link (str) -- The link to the user entity.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Permissions.
- Return type
- query_iterable.QueryIterable
- QueryStoredProcedures(collection_link, query, options=None)
- Queries stored procedures in a collection.
- collection_link (str) -- The link to the document collection.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Stored Procedures.
- Return type
- query_iterable.QueryIterable
- QueryTriggers(collection_link, query, options=None)
- Queries triggers in a collection.
- collection_link (str) -- The link to the document collection.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Triggers.
- Return type
- query_iterable.QueryIterable
- QueryUserDefinedFunctions(collection_link, query, options=None)
- Queries user defined functions in a collection.
- collection_link (str) -- The link to the collection.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of UDFs.
- Return type
- query_iterable.QueryIterable
- QueryUsers(database_link, query, options=None)
- Queries users in a database.
- database_link (str) -- The link to the database.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Users.
- Return type
- query_iterable.QueryIterable
- Read(path, type, id, initial_headers, options=None)
- Reads a Azure Cosmos DB resource and returns it.
- path (str) --
- type (str) --
- id (str) --
- initial_headers (dict) --
- options (dict) -- The request options for the request.
- Returns
- The upserted Azure Cosmos DB resource.
- Return type
- dict
- ReadAttachment(attachment_link, options=None)
- Reads an attachment.
- attachment_link (str) -- The link to the attachment.
- options (dict) -- The request options for the request.
- Returns
- The read Attachment.
- Return type
- dict
- ReadAttachments(document_link, options=None)
- Reads all attachments in a document.
- document_link (str) -- The link to the document.
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Attachments.
- Return type
- query_iterable.QueryIterable
- ReadCollection(collection_link, options=None)
- Reads a collection.
- collection_link (str) -- The link to the document collection.
- options (dict) -- The request options for the request.
- Returns
- The read Collection.
- Return type
- dict
- ReadCollections(database_link, options=None)
- Reads all collections in a database.
- database_link (str) -- The link to the database.
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Collections.
- Return type
- query_iterable.QueryIterable
- ReadConflict(conflict_link, options=None)
- Reads a conflict.
- conflict_link (str) -- The link to the conflict.
- options (dict) --
- Returns
- The read Conflict.
- Return type
- dict
- ReadConflicts(collection_link, feed_options=None)
- Reads conflicts.
- collection_link (str) -- The link to the document collection.
- feed_options (dict) --
- Returns
- Query Iterable of Conflicts.
- Return type
- query_iterable.QueryIterable
- ReadDatabase(database_link, options=None)
- Reads a database.
- database_link (str) -- The link to the database.
- options (dict) -- The request options for the request.
- Returns
- The Database that was read.
- Return type
- dict
- ReadDatabases(options=None)
- Reads all databases.
- Parameters
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Databases.
- Return type
- query_iterable.QueryIterable
- ReadDocument(document_link, options=None)
- Reads a document.
- document_link (str) -- The link to the document.
- options (dict) -- The request options for the request.
- Returns
- The read Document.
- Return type
- dict
- ReadDocuments(collection_link, feed_options=None)
- Reads all documents in a collection.
- collection_link (str) -- The link to the document collection.
- feed_options (dict) --
- Returns
- Query Iterable of Documents.
- Return type
- query_iterable.QueryIterable
- ReadEndpoint
- Gets the curent read endpoint for a geo-replicated database account.
- ReadMedia(media_link)
- Reads a media.
When self.connection_policy.MediaReadMode == documents.MediaReadMode.Streamed, returns a file-like stream object; otherwise, returns a str.
- Parameters
- media_link (str) -- The link to the media.
- Returns
- The read Media.
- Return type
- str or file-like stream object
- ReadOffer(offer_link)
- Reads an offer.
- Parameters
- offer_link (str) -- The link to the offer.
- Returns
- The read Offer.
- Return type
- dict
- ReadOffers(options=None)
- Reads all offers.
- Parameters
- options (dict) -- The request options for the request
- Returns
- Query Iterable of Offers.
- Return type
- query_iterable.QueryIterable
- ReadPermission(permission_link, options=None)
- Reads a permission.
- permission_link (str) -- The link to the permission.
- options (dict) -- The request options for the request.
- Returns
- The read permission.
- Return type
- dict
- ReadPermissions(user_link, options=None)
- Reads all permissions for a user.
- user_link (str) -- The link to the user entity.
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Permissions.
- Return type
- query_iterable.QueryIterable
- ReadStoredProcedure(sproc_link, options=None)
- Reads a stored procedure.
- sproc_link (str) -- The link to the stored procedure.
- options (dict) -- The request options for the request.
- Returns
- The read Stored Procedure.
- Return type
- dict
- ReadStoredProcedures(collection_link, options=None)
- Reads all store procedures in a collection.
- collection_link (str) -- The link to the document collection.
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Stored Procedures.
- Return type
- query_iterable.QueryIterable
- ReadTrigger(trigger_link, options=None)
- Reads a trigger.
- trigger_link (str) -- The link to the trigger.
- options (dict) -- The request options for the request.
- Returns
- The read Trigger.
- Return type
- dict
- ReadTriggers(collection_link, options=None)
- Reads all triggers in a collection.
- collection_link (str) -- The link to the document collection.
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of Triggers.
- Return type
- query_iterable.QueryIterable
- ReadUser(user_link, options=None)
- Reads a user.
- user_link (str) -- The link to the user entity.
- options (dict) -- The request options for the request.
- Returns
- The read User.
- Return type
- dict
- ReadUserDefinedFunction(udf_link, options=None)
- Reads a user defined function.
- udf_link (str) -- The link to the user defined function.
- options (dict) -- The request options for the request.
- Returns
- The read UDF.
- Return type
- dict
- ReadUserDefinedFunctions(collection_link, options=None)
- Reads all user defined functions in a collection.
- collection_link (str) -- The link to the document collection.
- options (dict) -- The request options for the request.
- Returns
- Query Iterable of UDFs.
- Return type
- query_iterable.QueryIterable
- ReadUsers(database_link, options=None)
- Reads all users in a database.
- Params str database_link
- The link to the database.
- Params dict options
- The request options for the request.
- Returns
- Query iterable of Users.
- Return type
- query_iterable.QueryIterable
- RegisterPartitionResolver(database_link, partition_resolver)
- Registers the partition resolver associated with the database link
- database_link (str) -- Database Self Link or ID based link.
- partition_resolver (object) -- An instance of PartitionResolver.
- Replace(resource, path, type, id, initial_headers, options=None)
- Replaces a Azure Cosmos DB resource and returns it.
- resource (dict) --
- path (str) --
- type (str) --
- id (str) --
- initial_headers (dict) --
- options (dict) -- The request options for the request.
- Returns
- The new Azure Cosmos DB resource.
- Return type
- dict
- ReplaceAttachment(attachment_link, attachment, options=None)
- Replaces an attachment and returns it.
- attachment_link (str) -- The link to the attachment.
- attachment (dict) --
- options (dict) -- The request options for the request.
- Returns
- The replaced Attachment
- Return type
- dict
- ReplaceCollection(collection_link, collection, options=None)
- Replaces a collection and return it.
- collection_link (str) -- The link to the collection entity.
- collection (dict) -- The collection to be used.
- options (dict) -- The request options for the request.
- Returns
- The new Collection.
- Return type
- dict
- ReplaceDocument(document_link, new_document, options=None)
- Replaces a document and returns it.
- document_link (str) -- The link to the document.
- new_document (dict) --
- options (dict) -- The request options for the request.
- Returns
- The new Document.
- Return type
- dict
- ReplaceOffer(offer_link, offer)
- Replaces an offer and returns it.
- offer_link (str) -- The link to the offer.
- offer (dict) --
- Returns
- The replaced Offer.
- Return type
- dict
- ReplacePermission(permission_link, permission, options=None)
- Replaces a permission and return it.
- permission_link (str) -- The link to the permission.
- permission (dict) --
- options (dict) -- The request options for the request.
- Returns
- The new Permission.
- Return type
- dict
- ReplaceStoredProcedure(sproc_link, sproc, options=None)
- Replaces a stored procedure and returns it.
- sproc_link (str) -- The link to the stored procedure.
- sproc (dict) --
- options (dict) -- The request options for the request.
- Returns
- The replaced Stored Procedure.
- Return type
- dict
- ReplaceTrigger(trigger_link, trigger, options=None)
- Replaces a trigger and returns it.
- trigger_link (str) -- The link to the trigger.
- trigger (dict) --
- options (dict) -- The request options for the request.
- Returns
- The replaced Trigger.
- Return type
- dict
- ReplaceUser(user_link, user, options=None)
- Replaces a user and return it.
- user_link (str) -- The link to the user entity.
- user (dict) --
- options (dict) -- The request options for the request.
- Returns
- The new User.
- Return type
- dict
- ReplaceUserDefinedFunction(udf_link, udf, options=None)
- Replaces a user defined function and returns it.
- udf_link (str) -- The link to the user defined function.
- udf (dict) --
- options (dict) -- The request options for the request.
- Returns
- The new UDF.
- Return type
- dict
- Session
- Gets the session object from the client
- UpdateMedia(media_link, readable_stream, options=None)
- Updates a media and returns it.
- media_link (str) -- The link to the media.
- stream object) readable_stream ((file-like) --
- options (dict) -- The request options for the request.
- Returns
- The updated Media.
- Return type
- str or file-like stream object
- Upsert(body, path, type, id, initial_headers, options=None)
- Upserts a Azure Cosmos DB resource and returns it.
- body (dict) --
- path (str) --
- type (str) --
- id (str) --
- initial_headers (dict) --
- options (dict) -- The request options for the request.
- Returns
- The upserted Azure Cosmos DB resource.
- Return type
- dict
- UpsertAttachment(document_link, attachment, options=None)
- Upserts an attachment in a document.
- document_link (str) -- The link to the document.
- attachment (dict) -- The Azure Cosmos DB attachment to upsert.
- options (dict) -- The request options for the request.
- Returns
- The upserted Attachment.
- Return type
- dict
- UpsertAttachmentAndUploadMedia(document_link, readable_stream, options=None)
- Upserts an attachment and upload media.
- document_link (str) -- The link to the document.
- stream object) readable_stream ((file-like) --
- options (dict) -- The request options for the request.
- Returns
- The upserted Attachment.
- Return type
- dict
- UpsertDocument(database_or_collection_link, document, options=None)
- Upserts a document in a collection.
- database_or_collection_link (str) -- The link to the database when using partitioning, otherwise link to the document collection.
- document (dict) -- The Azure Cosmos DB document to upsert.
- options (dict) -- The request options for the request.
- options['disableAutomaticIdGeneration'] (bool) -- Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned.
- Returns
- The upserted Document.
- Return type
- dict
- UpsertPermission(user_link, permission, options=None)
- Upserts a permission for a user.
- user_link (str) -- The link to the user entity.
- permission (dict) -- The Azure Cosmos DB user permission to upsert.
- options (dict) -- The request options for the request.
- Returns
- The upserted permission.
- Return type
- dict
- UpsertStoredProcedure(collection_link, sproc, options=None)
- Upserts a stored procedure in a collection.
- collection_link (str) -- The link to the document collection.
- sproc (str) --
- options (dict) -- The request options for the request.
- Returns
- The upserted Stored Procedure.
- Return type
- dict
- UpsertTrigger(collection_link, trigger, options=None)
- Upserts a trigger in a collection.
- collection_link (str) -- The link to the document collection.
- trigger (dict) --
- options (dict) -- The request options for the request.
- Returns
- The upserted Trigger.
- Return type
- dict
- UpsertUser(database_link, user, options=None)
- Upserts a user.
- database_link (str) -- The link to the database.
- user (dict) -- The Azure Cosmos DB user to upsert.
- options (dict) -- The request options for the request.
- Returns
- The upserted User.
- Return type
- dict
- UpsertUserDefinedFunction(collection_link, udf, options=None)
- Upserts a user defined function in a collection.
- collection_link (str) -- The link to the collection.
- udf (str) --
- options (dict) -- The request options for the request.
- Returns
- The upserted UDF.
- Return type
- dict
- WriteEndpoint
- Gets the curent write endpoint for a geo-replicated database account.
pydocumentdb.documents module¶
AzureDocument classes and enums for the Azure Cosmos DB database service.
- class pydocumentdb.documents.ConnectionMode
- Bases: object
Represents the connection mode to be used by the client.
- Variables
- Gateway (int) -- Use the Azure Cosmos DB gateway to route all requests. The gateway proxies requests to the right data partition.
- class pydocumentdb.documents.ConnectionPolicy
- Bases: object
Represents the Connection policy assocated with a DocumentClient.
- RequestTimeout (int) -- Gets or sets the request timeout (time to wait for response from network peer).
- MediaRequestTimeout (int) -- Gets or sets Time to wait for response from network peer for attachment content (aka media) operations.
- ConnectionMode (documents.ConnectionMode) -- Gets or sets the connection mode used in the client. Currently only Gateway is supported.
- MediaReadMode (MediaReadMode.Buffered) -- Gets or sets the attachment content (aka media) download mode.
- SSLConfiguration (documents.SSLConfiguration) -- Gets or sets the SSL configuration.
- ProxyConfiguration (documents.ProxyConfiguration) -- Gets or sets the proxy configuration.
- EnableEndpointDiscovery (boolean) -- Gets or sets endpoint discovery flag for geo-replicated database accounts. When EnableEndpointDiscovery is true, the client will automatically discover the current write and read locations and direct the requests to the correct location taking into consideration of the user's preference(if provided) as PreferredLocations.
- PreferredLocations (list) -- Gets or sets the preferred locations for geo-replicated database accounts. When EnableEndpointDiscovery is true and PreferredLocations is non-empty, the client will use this list to evaluate the final location, taking into consideration the order specified in PreferredLocations list. The locations in this list are specified as the names of the azure cosmos db locations like, 'West US', 'East US', 'Central India' and so on.
- RetryOptions (RetryOptions) -- Gets or sets the retry options to be applied to all requests when retrying.
- DisableSSLVerification (boolean) -- Flag to disable SSL verification for the requests. SSL verification is enabled by default. Don't set this when targeting production endpoints. This is intended to be used only when targeting emulator endpoint to avoid failing your requests with SSL related error.
- class pydocumentdb.documents.ConsistencyLevel
- Bases: object
Represents the consistency levels supported for Azure Cosmos DB client operations.
The requested ConsistencyLevel must match or be weaker than that provisioned for the database account. Consistency levels.
Consistency levels by order of strength are Strong, BoundedStaleness, Session, ConsistentPrefix and Eventual.
- Strong (str) -- Strong Consistency guarantees that read operations always return the value that was last written.
- BoundedStaleness (str) -- Bounded Staleness guarantees that reads are not too out-of-date. This can be configured based on number of operations (MaxStalenessPrefix) or time (MaxStalenessIntervalInSeconds).
- Session (str) -- Session Consistency guarantees monotonic reads (you never read old data, then new, then old again), monotonic writes (writes are ordered) and read your writes (your writes are immediately visible to your reads) within any single session.
- Eventual (str) -- Eventual Consistency guarantees that reads will return a subset of writes. All writes will be eventually be available for reads.
- ConsistentPrefix (str) -- ConsistentPrefix Consistency guarantees that reads will return some prefix of all writes with no gaps. All writes will be eventually be available for reads.
- Session = 'Session'
- class pydocumentdb.documents.DataType
- Bases: object
Specifies the data type of index specs.
- Number (str) -- Represents a numeric data type.
- String (str) -- Represents a string data type.
- Point (str) -- Represents a point data type.
- LineString (str) -- Represents a line string data type.
- Polygon (str) -- Represents a polygon data type.
- class pydocumentdb.documents.DatabaseAccount
- Bases: object
Database account. A DatabaseAccount is the container for databases.
- DatabaseLink (str) -- The self-link for Databases in the databaseAccount.
- MediaLink (str) -- The self-link for Media in the databaseAccount.
- MaxMediaStorageUsageInMB (int) -- Attachment content (media) storage quota in MBs (Retrieved from gateway).
- CurrentMediaStorageUsageInMB (int) -- Current attachment content (media) usage in MBs (Retrieved from gateway). Value is returned from cached information updated periodically and is not guaranteed to be real time.
- ConsistencyPolicy (dict) -- UserConsistencyPolicy settings.
- ConsistencyPolicy['defaultConsistencyLevel'] (dict) -- The default consistency level.
- ConsistencyPolicy['maxStalenessPrefix'] (int) -- In bounded staleness consistency, the maximum allowed staleness in terms difference in sequence numbers (aka version).
- ConsistencyPolicy['maxStalenessIntervalInSeconds'] (int) -- In bounded staleness consistency, the maximum allowed staleness in terms time interval.
- ReadableLocations
- Gets the list of readable locations for a geo-replicated database account.
- WritableLocations
- Gets the list of writable locations for a geo-replicated database account.
- class pydocumentdb.documents.IndexKind
- Bases: object
Specifies the index kind of index specs.
- Hash (str) -- The index entries are hashed to serve point look up queries. Can be used to serve queries like: SELECT * FROM docs d WHERE d.prop = 5
- Range (str) -- The index entries are ordered. Range indexes are optimized for inequality predicate queries with efficient range scans. Can be used to serve queries like: SELECT * FROM docs d WHERE d.prop > 5
- class pydocumentdb.documents.IndexingDirective
- Bases: object
Specifies whether or not the resource is to be indexed.
- Default (int) -- Use any pre-defined/pre-configured defaults.
- Exclude (int) -- Index the resource.
- Include (int) -- Do not index the resource.
- class pydocumentdb.documents.IndexingMode
- Bases: object
Specifies the supported indexing modes.
- Consistent (str) --
Index is updated synchronously with a create or update operation. With consistent indexing, query behavior is the same as the default consistency level for the collection.
The index is always kept up to date with the data.
- Lazy (str) --
Index is updated asynchronously with respect to a create or update operation.
With lazy indexing, queries are eventually consistent. The index is updated when the collection is idle.
- NoIndex (str) --
No index is provided.
Setting IndexingMode to "None" drops the index. Use this if you don't want to maintain the index for a document collection, to save the storage cost or improve the write throughput. Your queries will degenerate to scans of the entire collection.
- class pydocumentdb.documents.MediaReadMode
- Bases: object
Represents the mode for use with downloading attachment content (aka media).
- Buffered (str) --
Content is buffered at the client and not directly streamed from the content store.
Use Buffered to reduce the time taken to read and write media files.
- Streamed (str) --
Content is directly streamed from the content store without any buffering at the client.
Use Streamed to reduce the client memory overhead of reading and writing media files.
- class pydocumentdb.documents.PartitionKind
- Bases: object
Specifies the kind of partitioning to be applied.
- Variables
- Hash (str) -- The partition key definition path is hashed.
- class pydocumentdb.documents.PermissionMode
- Bases: object
Enumeration specifying applicability of permission.
- NoneMode (str) -- None.
- Read (str) -- Permission applicable for read operations only.
- All (str) -- Permission applicable for all operations.
- class pydocumentdb.documents.ProxyConfiguration
- Bases: object
Configurations for proxy.
- class pydocumentdb.documents.SSLConfiguration
- Bases: object
Configurations for SSL connections.
Please refer to http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification for more detail.
- SSLKeyFIle (str) -- The path of the key file for ssl connection.
- SSLCertFile (str) -- The path of the cert file for ssl connection.
- SSLCaCerts (str) -- The path of the CA_BUNDLE file with certificates of trusted CAs.
- class pydocumentdb.documents.TriggerOperation
- Bases: object
Specifies the operations on which a trigger should be executed.
- All (str) -- All operations.
- Create (str) -- Create operations only.
- Update (str) -- Update operations only.
- Delete (str) -- Delete operations only.
- Replace (str) -- Replace operations only.
- class pydocumentdb.documents.TriggerType
- Bases: object
Specifies the type of the trigger.
- Pre (str) -- Trigger should be executed before the associated operation(s).
- Post (str) -- Trigger should be executed after the associated operation(s).
- class pydocumentdb.documents.Undefined
- Bases: object
Represents undefined value for partitionKey when it's mising.
pydocumentdb.endpoint_discovery_retry_policy module¶
Internal class for endpoint discovery retry policy implementation in the Azure Cosmos DB database service.
pydocumentdb.errors module¶
PyDocumentDB Exceptions in the Azure Cosmos DB database service.
- exception pydocumentdb.errors.DocumentDBError
- Bases: Exception
Base class for all Azure Cosmos DB errors.
- exception pydocumentdb.errors.HTTPFailure(status_code, message='', headers=None)
- Bases: pydocumentdb.errors.DocumentDBError
Raised when a HTTP request to the Azure Cosmos DB has failed.
- exception pydocumentdb.errors.JSONParseFailure
- Bases: pydocumentdb.errors.DocumentDBError
Raised when fails to parse JSON message.
- exception pydocumentdb.errors.UnexpectedDataType
- Bases: pydocumentdb.errors.DocumentDBError
Raised when unexpected data type is provided as parameter.
pydocumentdb.global_endpoint_manager module¶
Internal class for global endpoint manager implementation in the Azure Cosmos DB database service.
pydocumentdb.hash_partition_resolver module¶
Hash partition resolver implementation in the Azure Cosmos DB database service.
- class pydocumentdb.hash_partition_resolver.HashPartitionResolver(partition_key_extractor, collection_links, default_number_of_virtual_nodes_per_collection=128, hash_generator=None)
- Bases: object
HashPartitionResolver implements partitioning based on the value of a hash function, allowing you to evenly distribute requests and data across a number of partitions.
- partition_key_extractor (lambda) -- Returning the partition key from the document passed.
- collection_links (list) -- The links of collections participating in partitioning.
- default_number_of_virtual_nodes_per_collection (int) -- Number of virtual nodes per collection.
- hash_generator (HashGenerator) -- The hash generator to be used for hashing algorithm.
- ResolveForCreate(document)
- Resolves the collection for creating the document based on the partition key.
- Parameters
- document (dict) -- The document to be created.
- Returns
- Collection Self link or Name based link which should handle the Create operation.
- Return type
- str
- ResolveForRead(partition_key)
- Resolves the collection for reading/querying the documents based on the partition key.
- Parameters
- document (dict) -- The document to be read/queried.
- Returns
- Collection Self link(s) or Name based link(s) which should handle the Read operation.
- Return type
- list
pydocumentdb.http_constants module¶
HTTP Constants in the Azure Cosmos DB database service.
- class pydocumentdb.http_constants.CookieHeaders
- Bases: object
Constants of cookie headers.
- class pydocumentdb.http_constants.HttpContextProperties
- Bases: object
Constants of http context properties.
- class pydocumentdb.http_constants.HttpHeaderPreferenceTokens
- Bases: object
Constants of http header preference tokens.
- class pydocumentdb.http_constants.HttpListenerErrorCodes
- Bases: object
Constants of http listener error codes.
- class pydocumentdb.http_constants.HttpStatusDescriptions
- Bases: object
Constants of http status descriptions.
- class pydocumentdb.http_constants.StatusCodes
- Bases: object
HTTP status codes returned by the REST operations
- class pydocumentdb.http_constants.SubStatusCodes
- Bases: object
Sub status codes returned by the REST operations specifying the details of the operation
pydocumentdb.murmur_hash module¶
Internal class for Murmur hash implementation in the Azure Cosmos DB database service.
pydocumentdb.partition module¶
Internal class for client side partition implementation in the Azure Cosmos DB database service.
pydocumentdb.query_iterable module¶
Iterable query results in the Azure Cosmos DB database service.
- class pydocumentdb.query_iterable.QueryIterable(client, query, options, fetch_function, collection_link=None)
- Bases: object
Represents an iterable object of the query results. QueryIterable is a wrapper for query execution context.
Instantiates a QueryIterable for non-client side partitioning queries. _ProxyQueryExecutionContext will be used as the internal query execution context
- client (DocumentClient) -- Instance of document client.
- or dict) query ((str) --
- options (dict) -- The request options for the request.
- fetch_function (method) --
- collection_link (str) -- If this is a Document query/feed collection_link is required.
Example of fetch_function:
>>> def result_fn(result): >>> return result['Databases']
- classmethod PartitioningQueryIterable(client, query, options, database_link, partition_key)
- Represents a client side partitioning query iterable.
This constructor instantiates a QueryIterable for client side partitioning queries, and sets _MultiCollectionQueryExecutionContext as the internal execution context. :param DocumentClient client:
- or dict) options ((str) --
- options (dict) -- The request options for the request.
- database_link (str) -- Database self link or ID based link
- partition_key (str) -- Partition key for the query
- fetch_next_block()
- Returns a block of results with respecting retry policy.
This method only exists for backward compatibility reasons. (Because QueryIterable has exposed fetch_next_block api).
- Returns
- List of results.
- Return type
- list
pydocumentdb.range module¶
Range class implementation in the Azure Cosmos DB database service.
- class pydocumentdb.range.Range(low, high)
- Bases: object
Represents the Range class used to map the partition key of the document to their associated collection.
- Contains(other)
- Checks if the passed parameter is in the range of this object.
- Intersect(other)
- Checks if the passed parameter intersects the range of this object.
pydocumentdb.range_partition_resolver module¶
Range partition resolver implementation in the Azure Cosmos DB database service.
- class pydocumentdb.range_partition_resolver.RangePartitionResolver(partition_key_extractor, partition_map)
- Bases: object
RangePartitionResolver implements partitioning based on the ranges, allowing you to distribute requests and data across a number of partitions.
- partition_key_extractor (lambda) -- Returning the partition key from the document passed.
- partition_map (dict) -- The dictionary of ranges mapped to their associated collection
- ResolveForCreate(document)
- Resolves the collection for creating the document based on the partition key.
- Parameters
- document (dict) -- The document to be created.
- Returns
- Collection Self link or Name based link which should handle the Create operation.
- Return type
- str
- ResolveForRead(partition_key)
- Resolves the collection for reading/querying the documents based on the partition key.
- Parameters
- document (dict) -- The document to be read/queried.
- Returns
- Collection Self link(s) or Name based link(s) which should handle the Read operation.
- Return type
- list
pydocumentdb.resource_throttle_retry_policy module¶
Internal class for resource throttle retry policy implementation in the Azure Cosmos DB database service.
pydocumentdb.retry_options module¶
Class for retry options in the Azure Cosmos DB database service.
- class pydocumentdb.retry_options.RetryOptions(max_retry_attempt_count=9, fixed_retry_interval_in_milliseconds=None, max_wait_time_in_seconds=30)
- Bases: object
The retry options to be applied to all requests when retrying
- MaxRetryAttemptCount (int) -- Max number of retries to be performed for a request. Default value 9.
- FixedRetryIntervalInMilliseconds (int) -- Fixed retry interval in milliseconds to wait between each retry ignoring the retryAfter returned as part of the response.
- MaxWaitTimeInSeconds (int) -- Max wait time in seconds to wait for a request while the retries are happening. Default value 30 seconds.
pydocumentdb.retry_utility module¶
Internal methods for executing functions in the Azure Cosmos DB database service.
pydocumentdb.runtime_constants module¶
Runtime Constants in the Azure Cosmos DB database service.
- class pydocumentdb.runtime_constants.MediaTypes
- Bases: object
Constants of media types.
http://www.iana.org/assignments/media-types/media-types.xhtml
pydocumentdb.session module¶
Session Consistency Tracking in the Azure Cosmos DB database service.
- class pydocumentdb.session.Session(url_connection)
- Bases: object
State of a Azure Cosmos DB session. This session object can be shared across clients within the same process
- class pydocumentdb.session.SessionContainer
- Bases: object
- get_session_token(resource_path)
- Get Session Token for collection_link
- Parameters
- resource_path (str) -- Self link / path to the resource
- Returns
- Session Token dictionary for the collection_id
- Return type
- dict
- static parse_session_token(response_headers)
- Extracts session token from response headers and parses
- Parameters
- response_headers (dict) --
- Returns
- A dictionary of partition id to session lsn for given collection
- Return type
- dict
- set_session_token(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)
pydocumentdb.synchronized_request module¶
Synchronized request in the Azure Cosmos DB database service.
- pydocumentdb.synchronized_request.SynchronizedRequest(client, global_endpoint_manager, connection_policy, requests_session, method, base_url, path, request_data, query_params, headers)
- Performs one synchronized http request according to the parameters.
- client (object) -- Document client instance
- global_endpoint_manager (_GlobalEndpointManager) --
- connection_policy (documents.ConnectionPolicy) --
- requests_session (requests.Session) -- Session object in requests module
- method (str) --
- base_url (str) --
- path (str) --
- unicode, file-like stream object, dict, list or None) request_data ((str,) --
- query_params (dict) --
- headers (dict) --
- Returns
- tuple of (result, headers)
- Return type
- tuple of (dict dict)
pydocumentdb.utils module¶
Internal Helper functions in the Azure Cosmos DB database service.
Module contents¶
PYDOCUMENTDB¶
COPYRIGHT¶
2019, Microsoft
November 20, 2019 | 2.3.3 |