Documents

Full description of all available methods

class async_couch.DocEndpoint(http_client: async_couch.http_clients.base_client.BaseHttpClient)

Implement CouchDB documents API

doc_copy(db: str, doc_id: str, destination: str, rev: str = None, batch: str = None) → async_couch.types.UniversalResponse

The COPY (which is non-standard HTTP) copies an existing document to a new or existing document. Copying a document is only possible within the same database.

The source document is specified on the request line, with the Destination header of the request specifying the target document.

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
  • destination (str) – Destination document. Must contain the target document ID, and optionally the target document revision, if copying to an existing document
  • rev (str) – Actual document’s revision
  • batch (str = None) – Stores document in batch mode Possible values: ok
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred

doc_create_or_update(db: str, doc_id: str, doc: dict, rev: str = None, batch: str = None, new_edits: bool = True, attachments: List[async_couch.utils.content_types.MultipartRelatedAttachment] = None) → async_couch.types.UniversalResponse

The PUT method creates a new named document, or creates a new revision of the existing document. Unlike the POST /{db}, you must specify the document ID in the request URL.

When updating an existing document, the current document revision must be included in the document (i.e. the request body), as the rev query parameter, or in the If-Match request header.

Parameters:
  • attachments (List[Attachment]) – For bulk upload. In this case it should be sent as multipart related
  • db (str) – Database name
  • doc_id (str) – Document id
  • doc (dic) – Document data
  • rev (str = None) – Document’s revision if updating an existing document
  • batch (str = None) – Stores document in batch mode. Possible values: ok
  • new_edits (bool = True) – Prevents insertion of a conflicting document. Possible values: true (default) and false. If false, a well-formed _rev must be included in the document. new_edits=false is used by the replicator to insert documents into the target database even if that leads to the creation of conflicts. Optional
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred

doc_delete(db: str, doc_id: str, rev: str, batch: str = None) → async_couch.types.UniversalResponse

Marks the specified document as deleted by adding a field _deleted with the value true. Documents with this field will not be returned within requests anymore, but stay in the database. You must supply the current (latest) revision, either by using the rev parameter or by using the If-Match header to specify the revision.

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
  • rev (str) – Actual document’s revision
  • batch (str = None) – Stores document in batch mode Possible values: ok
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred

doc_exists(db: str, doc_id: str) → async_couch.types.UniversalResponse

Returns the HTTP Headers containing a minimal amount of information about the specified document. The method supports the same query arguments as the GET /{db}/{docid} method, but only the header information (including document size, and the revision as an ETag), is returned.

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred

doc_get(db: str, doc_id: str, attachments: bool = False, att_encoding_info: bool = False, attributes_since: str = None, conflicts: bool = False, deleted_conflicts: bool = False, latest: bool = False, local_seq: bool = False, meta: bool = False, open_revs: str = None, rev: str = None, revs: bool = False, revs_info: bool = False) → async_couch.types.UniversalResponse

Gets information about the specified database.

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
  • attachments (bool = False) – Includes attachments bodies in response
  • att_encoding_info (bool = False) – Includes encoding information in attachment stubs if the particular attachment is compressed
  • attributes_since (str = None) – Includes attachments only since specified revisions. Does not includes attachments for specified revisions
  • conflicts (bool = False) – Includes information about conflicts in document
  • deleted_conflicts (bool = False) – Includes information about deleted conflicted revisions
  • latest (bool = False) – Forces retrieving latest “leaf” revision, no matter what rev was requested.
  • local_seq (bool = False) – Includes last update sequence for the document
  • meta (bool = False) – Acts same as specifying all conflicts, deleted_conflicts and revs_info query parameters
  • open_revs (str = None) – Retrieves documents of specified leaf revisions. Additionally, it accepts value as all to return all leaf revisions
  • rev (str = None) – Retrieves document of specified revision
  • revs (bool = False) – Includes list of all known document revisions
  • revs_info (bool = False) – Includes detailed information for all known document revisions
class async_couch.DocAttachmentEndpoint(http_client: async_couch.http_clients.base_client.BaseHttpClient)

Implement CouchDB document attachments API

attachment_delete(db: str, doc_id: str, attachment_id: str, rev: str = None) → async_couch.types.UniversalResponse

Deletes the attachment with filename {attname} of the specified doc. You must supply the rev query parameter or If-Match with the current revision to delete the attachment.

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
  • attachment_id (str) – Attachment name
  • rev (str = None) – Actual document’s revision
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred

attachment_exists(db: str, doc_id: str, attachment_id: str, rev: str = None) → async_couch.types.UniversalResponse

Returns the HTTP headers containing a minimal amount of information about the specified attachment. The method supports the same query arguments as the GET /{db}/{docid}/{attname} method, but only the header information (including attachment size, encoding and the MD5 hash as an ETag), is returned

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
  • attachment_id (str) – Attachment name
  • rev (str = None) – Actual document’s revision
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred

attachment_get(db: str, doc_id: str, attachment_id: str, rev: str = None) → async_couch.types.UniversalResponse

Returns the file attachment associated with the document. The raw data of the associated attachment is returned (just as if you were accessing a static file. The returned Content-Type will be the same as the content type set when the document attachment was submitted into the database.

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
  • attachment_id (str) – Attachment name
  • rev (str = None) – Actual document’s revision
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred

attachment_upload(db: str, doc_id: str, attachment_id: str, content_type: str, data: bytes, rev: str) → async_couch.types.UniversalResponse

Uploads the supplied content as an attachment to the specified document. The attachment name provided must be a URL encoded string. You must supply the Content-Type header, and for an existing document you must also supply either the rev query argument or the If-Match HTTP header. If the revision is omitted, a new, otherwise empty document will be created with the provided attachment, or a conflict

will occur.

If case when uploading an attachment using an existing attachment name, CouchDB will update the corresponding stored content of the database. Since you must supply the revision information to add an attachment to the document, this serves as validation to update the existing attachment.

Parameters:
  • db (str) – Database name
  • doc_id (str) – Document id
  • attachment_id (str) – Attachment name
  • content_type (str) – Attachment MIME type
  • data (bytes) – Uploading file data
  • rev (str = None) – Actual document’s revision
Returns:

Operating result

Return type:

UniversalResponse

Raises:

exc.CouchResponseError: – If server error occurred