aiocouchdb 0.8.0 documentation

CouchDB 1.x API

«  Welcome to aiocouchdb’s documentation!   ::   Contents   ::   Common Base Objects  »

CouchDB 1.x API

Server

class aiocouchdb.v1.server.Server(url_or_resource='http://localhost:5984', *, authdb_class=None, authdb_name=None, config_class=None, database_class=None, session_class=None)[source]

Implementation of CouchDB Server API.

active_tasks(*, auth=None)[source]

Returns list of active tasks which runs on server.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:list
all_dbs(*, auth=None)[source]

Returns list of available databases on server.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:list
authdb[source]

Proxy to the authentication database instance.

authdb_class

Authentication database class

alias of AuthDatabase

authdb_name = '_users'

Authentication database name

config[source]

Proxy to the related config_class instance.

config_class

Default ServerConfig instance class

alias of ServerConfig

database_class

Default Database instance class

alias of Database

db(dbname, *, auth=None)[source]

Returns Database instance against specified database name.

If database isn’t accessible for provided auth credentials, this method raises aiocouchdb.errors.HttpErrorException with the related response status code.

Parameters:
  • dbname (str) – Database name
  • authaiocouchdb.authn.AuthProvider instance
Return type:

aiocouchdb.v1.server.Server.database_class

db_updates(*, auth=None, feed_buffer_size=None, feed=None, timeout=None, heartbeat=None)[source]

Emits databases events for the related server instance.

Parameters:
  • authaiocouchdb.authn.AuthProvider instance
  • feed_buffer_size (int) – Internal buffer size for fetched feed items
  • feed (str) – Feed type
  • timeout (int) – Timeout in milliseconds
  • heartbeat (bool) – Whenever use heartbeats to keep connection alive

Depending on feed type returns:

info(*, auth=None)[source]

Returns server meta information and welcome message.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
log(*, bytes=None, offset=None, auth=None)[source]

Returns a chunk of data from the tail of CouchDB’s log file.

Parameters:
  • bytes (int) – Bytes to return
  • offset (int) – Offset in bytes where the log tail should be started
  • authaiocouchdb.authn.AuthProvider instance
Return type:

str

replicate(source, target, *, auth=None, authobj=None, cancel=None, continuous=None, create_target=None, doc_ids=None, filter=None, headers=None, proxy=None, query_params=None, since_seq=None, checkpoint_interval=None, connection_timeout=None, http_connections=None, retries_per_request=None, socket_options=None, use_checkpoints=None, worker_batch_size=None, worker_processes=None)[source]

Runs a replication from source to target.

Parameters:
  • source (str) – Source database name or URL
  • target (str) – Target database name or URL
  • authaiocouchdb.authn.AuthProvider instance (don’t confuse with authobj which belongs to replication options)
  • authobj (dict) – Authentication object for the target database
  • cancel (bool) – Cancels active replication
  • continuous (bool) – Runs continuous replication
  • create_target (bool) – Creates target database if it not exists
  • doc_ids (list) – List of specific document ids to replicate
  • filter (str) – Filter function name
  • headers (dict) – Custom replication request headers
  • proxy (str) – Proxy server URL
  • query_params (dict) – Custom query parameters for filter function
  • since_seq – Start replication from specified sequence number
  • checkpoint_interval (int) – Tweaks checkpoint_interval option
  • connection_timeout (int) – Tweaks connection_timeout option
  • http_connections (int) – Tweaks http_connections option
  • retries_per_request (int) – Tweaks retries_per_request option
  • socket_options (str) – Tweaks socket_options option
  • use_checkpoints (bool) – Tweaks use_checkpoints option
  • worker_batch_size (int) – Tweaks worker_batch_size option
  • worker_processes (int) – Tweaks worker_processes option
Return type:

dict

restart(*, auth=None)[source]

Restarts server instance.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
session[source]

Proxy to the related session_class instance.

session_class

Default Session instance class

alias of Session

stats(metric=None, *, auth=None, flush=None, range=None)[source]

Returns server statistics.

Parameters:
  • metric (str) – Metrics name in format group/name. For instance, httpd/requests. If omitted, all metrics will be returned
  • flush (bool) – If True, collects samples right for this request
  • range (int) – Sampling range
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

uuids(*, auth=None, count=None)[source]

Returns UUIDs generated on server.

Parameters:
  • count (int) – Amount of UUIDs to generate
  • authaiocouchdb.authn.AuthProvider instance
Return type:

list

Configuration

class aiocouchdb.v1.config.ServerConfig(resource)[source]

Implements /_config/* API. Should be used via server.config property.

delete(section, key, *, auth=None)[source]

Deletes specific configuration option and returns it value back.

Parameters:
  • section (string) – Configuration section name
  • key (string) – Option name
  • authaiocouchdb.authn.AuthProvider instance
Return type:

str

exists(section, key, *, auth=None)[source]

Checks if configuration option exists.

Parameters:
  • section (str) – Section name
  • key (str) – Option name
  • authaiocouchdb.authn.AuthProvider instance
Return type:

bool

get(section=None, key=None, *, auth=None)[source]

Returns server configuration. Depending on specified arguments returns:

Parameters:
  • section (str) – Section name (optional)
  • key (str) – Option name (optional)
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict or str

update(section, key, value, *, auth=None)[source]

Updates specific configuration option value and returns the old one back.

Parameters:
  • section (str) – Configuration section name
  • key (str) – Option name
  • value (str) – New option value
  • authaiocouchdb.authn.AuthProvider instance
Return type:

str

Session

class aiocouchdb.v1.session.Session(resource)[source]

Implements /_session API. Should be used via server.session property.

close(*, auth=None)[source]

Closes active cookie session. Uses for aiocouchdb.authn.CookieAuthProvider.

cookie_auth_provider_class

alias of CookieAuthProvider

info(*, auth=None)[source]

Returns information about authenticated user. Usable for any AuthProvider.

Return type:dict
open(name, password)[source]

Opens session for cookie auth provider and returns the auth provider back for usage in further requests.

Parameters:
  • name (str) – Username
  • password (str) – User’s password
Return type:

aiocouchdb.authn.CookieAuthProvider

Database

class aiocouchdb.v1.database.Database(url_or_resource, *, dbname=None, document_class=None, design_document_class=None, security_class=None, view_class=None)[source]

Implementation of CouchDB Database API.

all_docs(*keys, auth=None, feed_buffer_size=None, att_encoding_info=None, attachments=None, conflicts=None, descending=None, endkey=Ellipsis, endkey_docid=None, include_docs=None, inclusive_end=None, limit=None, skip=None, stale=None, startkey=Ellipsis, startkey_docid=None, update_seq=None)[source]

Iterates over all documents view.

Parameters:
  • keys (str) – List of document ids to fetch. This method is smart enough to use GET or POST request depending on amount of keys
  • authaiocouchdb.authn.AuthProvider instance
  • feed_buffer_size (int) – Internal buffer size for fetched feed items
  • att_encoding_info (bool) – Includes encoding information in an attachment stubs
  • attachments (bool) – Includes attachments content into documents. Warning: use with caution!
  • conflicts (bool) – Includes conflicts information into documents
  • descending (bool) – Return rows in descending by key order
  • endkey (str) – Stop fetching rows when the specified key is reached
  • endkey_docid (str) – Stop fetching rows when the specified document ID is reached
  • include_docs (str) – Include document body for each row
  • inclusive_end (bool) – When False, doesn’t includes endkey in returned rows
  • limit (int) – Limits the number of the returned rows by the specified number
  • skip (int) – Skips specified number of rows before starting to return the actual result
  • stale (str) – Allow to fetch the rows from a stale view, without triggering index update. Supported values: ok and update_after
  • startkey (str) – Return rows starting with the specified key
  • startkey_docid (str) – Return rows starting with the specified document ID
  • update_seq (bool) – Include an update_seq value into view results header
Return type:

aiocouchdb.feeds.ViewFeed

bulk_docs(docs, *, auth=None, all_or_nothing=None, new_edits=None)[source]

Updates multiple documents using a single request.

Parameters:
  • docs (Iterable) – Sequence of document objects (dict)
  • authaiocouchdb.authn.AuthProvider instance
  • all_or_nothing (bool) – Sets the database commit mode to use all-or-nothing semantics
  • new_edits (bool) – If False, prevents the database from assigning them new revision for updated documents
Return type:

list

changes(*doc_ids, auth=None, feed_buffer_size=None, att_encoding_info=None, attachments=None, conflicts=None, descending=None, feed=None, filter=None, headers=None, heartbeat=None, include_docs=None, limit=None, params=None, since=None, style=None, timeout=None, view=None)[source]

Emits database changes events.

Parameters:
  • doc_ids (str) – Document IDs to filter for. This method is smart enough to use GET or POST request depending if any doc_ids were provided or not and automatically sets filter param to _doc_ids value.
  • authaiocouchdb.authn.AuthProvider instance
  • feed_buffer_size (int) – Internal buffer size for fetched feed items
  • att_encoding_info (bool) – Includes encoding information in an attachment stubs
  • attachments (bool) – Includes the Base64-encoded content of an attachments in the documents
  • conflicts (bool) – Includes conflicts information in the documents
  • descending (bool) – Return changes in descending order
  • feed (str) – Changes feed type
  • filter (str) – Filter function name
  • headers (dict) – Custom request headers
  • heartbeat (int) – Period in milliseconds after which an empty line will be sent from server as the result to keep connection alive
  • include_docs (bool) – Includes the associated document for each emitted event
  • limit (int) – Limits a number of returned events by the specified value
  • since – Starts listening changes feed since given update sequence value
  • params (dict) – Custom request query parameters
  • style (str) – Changes feed output style: all_docs, main_only
  • timeout (int) – Period in milliseconds to await for new changes before close the feed. Works for continuous feeds
  • view (str) – View function name which would be used as filter. Implicitly sets filter param to _view value
Return type:

aiocouchdb.feeds.ChangesFeed

compact(ddoc_name=None, *, auth=None)[source]

Initiates database or view index compaction.

Parameters:
  • ddoc_name (str) – Design document name. If specified initiates view index compaction instead of database
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

create(*, auth=None)[source]

Creates a database.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
ddoc(docid, *, auth=None)[source]

Returns DesignDocument instance against specified document ID. This ID may startswith with _design/ prefix and if it’s not prefix will be added automatically.

If document isn’t accessible for auth provided credentials, this method raises aiocouchdb.errors.HttpErrorException with the related response status code.

Parameters:
  • docid (str) – Document ID
  • authaiocouchdb.authn.AuthProvider instance
Return type:

aiocouchdb.v1.database.Database.design_document_class

delete(*, auth=None)[source]

Deletes a database.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
design_document_class

alias of DesignDocument

doc(docid=None, *, auth=None, idfun=<function uuid4 at 0x7fc15f3f7950>)[source]

Returns Document instance against specified document ID.

If document ID wasn’t specified, the idfun function will be used to generate it.

If document isn’t accessible for auth provided credentials, this method raises aiocouchdb.errors.HttpErrorException with the related response status code.

Parameters:
  • docid (str) – Document ID
  • authaiocouchdb.authn.AuthProvider instance
  • idfun – Document ID generation function. Should return str or other object which could be translated into string
Return type:

aiocouchdb.v1.database.Database.document_class

document_class

alias of Document

ensure_full_commit(*, auth=None)[source]

Ensures that all bits are committed on disk.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
exists(*, auth=None)[source]

Checks if database exists on server. Assumes success on receiving response with 200 OK status.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:bool
info(*, auth=None)[source]

Returns database information.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
missing_revs(id_revs, *, auth=None)[source]

Returns document missed revisions in the database by given document-revisions mapping.

Parameters:
  • id_revs (dict) – Mapping between document ID and list of his revisions to search for.
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

name[source]

Returns a database name specified in class constructor.

purge(id_revs, *, auth=None)[source]

Permanently removes specified document revisions from the database.

Parameters:
  • id_revs (dict) – Mapping between document ID and list of his revisions to purge
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

revs_diff(id_revs, *, auth=None)[source]

Returns document revisions difference in the database by given document-revisions mapping.

Parameters:
  • id_revs (dict) – Mapping between document ID and list of his revisions to compare
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

revs_limit(count=None, *, auth=None)[source]

Returns the limit of database revisions to store or updates it if count parameter was specified.

Parameters:
  • count (int) – Amount of revisions to store
  • authaiocouchdb.authn.AuthProvider instance
Return type:

int or dict

security[source]

Proxy to the related security_class instance.

security_class

alias of DatabaseSecurity

temp_view(map_fun, red_fun=None, language=None, *, auth=None, feed_buffer_size=None, att_encoding_info=None, attachments=None, conflicts=None, descending=None, endkey=Ellipsis, endkey_docid=None, group=None, group_level=None, include_docs=None, inclusive_end=None, keys=Ellipsis, limit=None, reduce=None, skip=None, stale=None, startkey=Ellipsis, startkey_docid=None, update_seq=None)[source]

Executes temporary view and returns it results according specified parameters.

Parameters:
  • map_fun (str) – Map function source code
  • red_fun (str) – Reduce function source code
  • language (str) – Query server language to process the view
  • authaiocouchdb.authn.AuthProvider instance
  • feed_buffer_size (int) – Internal buffer size for fetched feed items
  • att_encoding_info (bool) – Includes encoding information in an attachment stubs
  • attachments (bool) – Includes attachments content into documents. Warning: use with caution!
  • conflicts (bool) – Includes conflicts information into documents
  • descending (bool) – Return rows in descending by key order
  • endkey – Stop fetching rows when the specified key is reached
  • endkey_docid (str) – Stop fetching rows when the specified document ID is reached
  • group (bool) – Reduces the view result grouping by unique keys
  • group_level (int) – Reduces the view result grouping the keys with defined level
  • include_docs (str) – Include document body for each row
  • inclusive_end (bool) – When False, doesn’t includes endkey in returned rows
  • keys (list) – List of view keys to fetch
  • limit (int) – Limits the number of the returned rows by the specified number
  • reduce (bool) – Defines is the reduce function needs to be applied or not
  • skip (int) – Skips specified number of rows before starting to return the actual result
  • stale (str) – Allow to fetch the rows from a stale view, without triggering index update. Supported values: ok and update_after
  • startkey – Return rows starting with the specified key
  • startkey_docid (str) – Return rows starting with the specified document ID
  • update_seq (bool) – Include an update_seq value into view results header
Return type:

aiocouchdb.feeds.ViewFeed

view_class

alias of View

view_cleanup(*, auth=None)[source]

Removes outdated views index files.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
class aiocouchdb.v1.authdb.AuthDatabase(url_or_resource, *, dbname=None, document_class=None, design_document_class=None, security_class=None, view_class=None)[source]

Represents system authentication database. Used via aiocouchdb.v1.server.Server.authdb.

document_class

alias of UserDocument

Security

class aiocouchdb.v1.security.DatabaseSecurity(resource)[source]

Provides set of methods to work with database security API. Should be used via database.security property.

get(*, auth=None)[source]

Returns database security object.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
update(*, auth=None, admins=None, members=None, merge=False)[source]

Updates database security object.

Parameters:
  • authaiocouchdb.authn.AuthProvider instance
  • admins (dict) – Mapping of administrators users/roles
  • members (dict) – Mapping of members users/roles
  • merge (bool) – Merges admins/members mappings with existed ones when is True, otherwise replaces them with the given
Return type:

dict

update_admins(*, auth=None, names=None, roles=None, merge=False)[source]

Helper for update() method to update only database administrators leaving members as is.

Parameters:
  • authaiocouchdb.authn.AuthProvider instance
  • names (list) – List of user names
  • roles (list) – List of role names
  • merge (bool) – Merges user/role lists with existed ones when is True, otherwise replaces them with the given
Return type:

dict

update_members(*, auth=None, names=None, roles=None, merge=False)[source]

Helper for update() method to update only database members leaving administrators as is.

Parameters:
  • authaiocouchdb.authn.AuthProvider instance
  • names (list) – List of user names
  • roles (list) – List of role names
  • merge (bool) – Merges user/role lists with existed ones when is True, otherwise replaces them with the given
Return type:

dict

Document

class aiocouchdb.v1.document.Document(url_or_resource, *, docid=None, attachment_class=None)[source]

Implementation of CouchDB Document API.

att(attname, *, auth=None)[source]

Returns Attachment instance against specified attachment.

If attachment isn’t accessible for auth provided credentials, this method raises aiocouchdb.errors.HttpErrorException with the related response status code.

Parameters:
  • attname (str) – Attachment name
  • authaiocouchdb.authn.AuthProvider instance
Return type:

aiocouchdb.v1.document.Document.attachment_class

attachment_class

alias of Attachment

copy(newid, rev=None, *, auth=None)[source]

Copies a document with the new ID within the same database.

Parameters:
  • newid (str) – New document ID
  • rev (str) – New document ID revision. Used for copying over existed document
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

delete(rev, *, auth=None, preserve_content=None)[source]

Deletes a document from server.

By default document will be deleted using DELETE HTTP method. On this request CouchDB removes all document fields, leaving only system _id and _rev and adding "_deleted": true one. When preserve_content set to True, document will be marked as deleted (by adding "_deleted": true field without removing existed ones) via PUT request. This feature costs two requests to fetch and update the document and also such documents consumes more space by oblivious reasons.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
  • preserve_content (bool) – Whenever to preserve document content on deletion
Return type:

dict

exists(rev=None, *, auth=None)[source]

Checks if document exists in the database. Assumes success on receiving response with 200 OK status.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
Return type:

bool

get(rev=None, *, auth=None, att_encoding_info=None, attachments=None, atts_since=None, conflicts=None, deleted_conflicts=None, local_seq=None, meta=None, open_revs=None, revs=None, revs_info=None)[source]

Returns a document object.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
  • att_encoding_info (bool) – Includes encoding information in an attachment stubs
  • attachments (bool) – Includes the Base64-encoded content of an attachments in the documents
  • atts_since (list) – Includes attachments that was added since the specified revisions
  • conflicts (bool) – Includes conflicts information in the documents
  • deleted_conflicts (bool) – Includes information about deleted conflicted revisions in the document
  • local_seq (bool) – Includes local sequence number in the document
  • meta (bool) – Includes meta information in the document
  • open_revs (list) – Returns the specified leaf revisions
  • revs (bool) – Includes information about all known revisions
  • revs_info (bool) – Includes information about all known revisions and their status
Return type:

dict or list if open_revs specified

get_open_revs(*open_revs, auth=None, att_encoding_info=None, atts_since=None, local_seq=None, revs=None)[source]

Returns document open revisions with their attachments.

Unlike get(open_revs=[...]), this method works with multipart/mixed response returning multipart reader which is more optimized to handle large data sets with lesser memory footprint.

Note, that this method always returns attachments along with leaf revisions.

Parameters:
  • open_revs (list) – Leaf revisions to return. If omitted, all leaf revisions will be returned
  • authaiocouchdb.authn.AuthProvider instance
  • att_encoding_info (bool) – Includes encoding information in an attachments stubs
  • atts_since (list) – Includes attachments that was added since the specified revisions
  • local_seq (bool) – Includes local sequence number in each document
  • revs (bool) – Includes information about all known revisions in each document
Return type:

OpenRevsMultipartReader

get_with_atts(rev=None, *, auth=None, att_encoding_info=None, atts_since=None, conflicts=None, deleted_conflicts=None, local_seq=None, meta=None, revs=None, revs_info=None)[source]

Returns document with attachments.

This method is more optimal than get(attachments=true) since it uses multipart API and doesn’t requires to read all the attachments, extract then from JSON document and decode from base64.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
  • att_encoding_info (bool) – Includes encoding information in an attachment stubs
  • atts_since (list) – Includes attachments that was added since the specified revisions
  • conflicts (bool) – Includes conflicts information in the documents
  • deleted_conflicts (bool) – Includes information about deleted conflicted revisions in the document
  • local_seq (bool) – Includes local sequence number in the document
  • meta (bool) – Includes meta information in the document
  • revs (bool) – Includes information about all known revisions
  • revs_info (bool) – Includes information about all known revisions and their status
Return type:

DocAttachmentsMultipartReader

id[source]

Returns a document id specified in class constructor.

modified(rev, *, auth=None)[source]

Checks if document was modified in database since specified revision.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
Return type:

bool

rev(*, auth=None)[source]

Returns current document revision by using HEAD request.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:str
update(doc, *, atts=None, auth=None, batch=None, new_edits=None, rev=None)[source]

Updates a document on server.

Parameters:
  • doc (dict) – Document object. Should implement MutableMapping interface
  • authaiocouchdb.authn.AuthProvider instance
  • atts (dict) – Attachments mapping where keys are represents attachment name and value is file-like object or bytes
  • batch (str) – Updates in batch mode (asynchronously) This argument accepts only "ok" value.
  • new_edits (bool) – Signs about new document edition. When False allows to create conflicts manually
  • rev (str) – Document revision. Optional, since document _rev field is also respected
Return type:

dict

Warning

Updating document with attachments is not able to use all the advantages of multipart request due to COUCHDB-2295 issue, so don’t even try to update a document with several gigabytes attachments with this method. Put them one-by-one via aiocouchdb.v1.attachment.Attachment.update() method.

class aiocouchdb.v1.authdb.UserDocument(*args, **kwargs)[source]

Represents user document for the authentication database.

name[source]

Returns username.

register(password, *, auth=None, **additional_data)[source]

Helper method over aiocouchdb.v1.document.Document.update() to change a user password.

Parameters:
  • password (str) – User’s password
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

update_password(password, *, auth=None)[source]

Helper method over aiocouchdb.v1.document.Document.update() to change a user password.

Parameters:
  • password (str) – New password
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

class aiocouchdb.v1.document.DocAttachmentsMultipartReader(headers, content)[source]

Special multipart reader optimized for requesting single document with attachments. Matches output with OpenRevsMultipartReader.

next()[source]

Emits a tuple of document object (dict) and multipart reader of the followed attachments (if any).

Return type:tuple
class aiocouchdb.v1.document.OpenRevsMultipartReader(headers, content)[source]

Special multipart reader optimized for reading document`s open revisions with attachments.

multipart_reader_cls

alias of MultipartReader

next()[source]

Emits a tuple of document object (dict) and multipart reader of the followed attachments (if any).

Return type:tuple

Design Document

class aiocouchdb.v1.designdoc.DesignDocument(url_or_resource, *, docid=None, document_class=None, view_class=None)[source]

Implementation of CouchDB Design Document API.

doc[source]

Returns document_class instance to operate with design document as with regular CouchDB document.

Return type:Document
document_class

alias of Document

id[source]

Returns a document id specified in class constructor.

info(*, auth=None)[source]

Returns view index information.

Parameters:authaiocouchdb.authn.AuthProvider instance
Return type:dict
list(list_name, view_name=None, *keys, auth=None, headers=None, data=None, params=None, format=None, att_encoding_info=None, attachments=None, conflicts=None, descending=None, endkey=Ellipsis, endkey_docid=None, group=None, group_level=None, include_docs=None, inclusive_end=None, limit=None, reduce=None, skip=None, stale=None, startkey=Ellipsis, startkey_docid=None, update_seq=None)[source]

Calls a list function and returns a raw response object.

Parameters:
  • list_name (str) – List function name
  • view_name (str) – View function name
  • authaiocouchdb.authn.AuthProvider instance
  • headers (dict) – Additional request headers
  • data – Request payload
  • params (dict) – Additional request query parameters
  • format (str) – List function output format

For other parameters see aiocouchdb.v1.designdoc.DesignDocument.view() method docstring.

Return type:HttpResponse
name[source]

Returns a document id specified in class constructor.

rewrite(*path, auth=None, method=None, headers=None, data=None, params=None)[source]

Requests rewrite resource and returns a raw response object.

Parameters:
  • path (str) – Request path by segments
  • authaiocouchdb.authn.AuthProvider instance
  • method (str) – HTTP request method
  • headers (dict) – Additional request headers
  • data – Request payload
  • params (dict) – Additional request query parameters
Return type:

HttpResponse

show(show_name, docid=None, *, auth=None, method=None, headers=None, data=None, params=None, format=None)[source]

Calls a show function and returns a raw response object.

Parameters:
  • show_name (str) – Show function name
  • docid (str) – Document ID
  • authaiocouchdb.authn.AuthProvider instance
  • method (str) – HTTP request method
  • headers (dict) – Additional request headers
  • data – Request payload
  • params (dict) – Additional request query parameters
  • format (str) – Show function output format
Return type:

HttpResponse

update(update_name, docid=None, *, auth=None, method=None, headers=None, data=None, params=None)[source]

Calls a show function and returns a raw response object.

Parameters:
  • update_name (str) – Update function name
  • docid (str) – Document ID
  • authaiocouchdb.authn.AuthProvider instance
  • method (str) – HTTP request method
  • headers (dict) – Additional request headers
  • data – Request payload
  • params (dict) – Additional request query parameters
Return type:

HttpResponse

view(view_name, *keys, auth=None, feed_buffer_size=None, att_encoding_info=None, attachments=None, conflicts=None, descending=None, endkey=Ellipsis, endkey_docid=None, group=None, group_level=None, include_docs=None, inclusive_end=None, limit=None, reduce=None, skip=None, stale=None, startkey=Ellipsis, startkey_docid=None, update_seq=None)[source]

Queries a stored view by the name with the specified parameters.

Parameters:
  • view_name (str) – Name of view stored in the related design document
  • keys (str) – List of view index keys to fetch. This method is smart enough to use GET or POST request depending on amount of keys
  • authaiocouchdb.authn.AuthProvider instance
  • feed_buffer_size (int) – Internal buffer size for fetched feed items
  • att_encoding_info (bool) – Includes encoding information in an attachment stubs
  • attachments (bool) – Includes attachments content into documents. Warning: use with caution!
  • conflicts (bool) – Includes conflicts information into documents
  • descending (bool) – Return rows in descending by key order
  • endkey – Stop fetching rows when the specified key is reached
  • endkey_docid (str) – Stop fetching rows when the specified document ID is reached
  • group (bool) – Reduces the view result grouping by unique keys
  • group_level (int) – Reduces the view result grouping the keys with defined level
  • include_docs (str) – Include document body for each row
  • inclusive_end (bool) – When False, doesn’t includes endkey in returned rows
  • limit (int) – Limits the number of the returned rows by the specified number
  • reduce (bool) – Defines is the reduce function needs to be applied or not
  • skip (int) – Skips specified number of rows before starting to return the actual result
  • stale (str) – Allow to fetch the rows from a stale view, without triggering index update. Supported values: ok and update_after
  • startkey – Return rows starting with the specified key
  • startkey_docid (str) – Return rows starting with the specified document ID
  • update_seq (bool) – Include an update_seq value into view results header
Return type:

aiocouchdb.feeds.ViewFeed

view_class

alias of View

Attachment

class aiocouchdb.v1.attachment.Attachment(url_or_resource, *, name=None)[source]

Implementation of CouchDB Attachment API.

accepts_range(rev=None, *, auth=None)[source]

Returns True if attachments accepts bytes range requests.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
Return type:

bool

delete(rev, *, auth=None)[source]

Deletes an attachment.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
Return type:

dict

exists(rev=None, *, auth=None)[source]

Checks if attachment exists. Assumes success on receiving response with 200 OK status.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
Return type:

bool

get(rev=None, *, auth=None, range=None)[source]

Returns an attachment reader object.

Parameters:
  • rev (str) – Document revision
  • authaiocouchdb.authn.AuthProvider instance
  • range (slice) – Bytes range. Could be slice() or two-element iterable object like list etc or just int()
Return type:

AttachmentReader

modified(digest, *, auth=None)[source]

Checks if attachment was modified by known MD5 digest.

Parameters:
  • digest (bytes) – Attachment MD5 digest. Optionally, may be passed in base64 encoding form
  • authaiocouchdb.authn.AuthProvider instance
Return type:

bool

update(fileobj, *, auth=None, content_encoding=None, content_type='application/octet-stream', rev=None)[source]

Attaches a file to document.

Parameters:
  • fileobj (file) – File object, should be readable
  • authaiocouchdb.authn.AuthProvider instance
  • content_encoding (str) – Content encoding: gzip or identity
  • content_type (str) – Attachment Content-Type header
  • rev (str) – Document revision
Return type:

dict

class aiocouchdb.v1.attachment.AttachmentReader(resp)[source]

Attachment reader implements io.RawIOBase interface with the exception that all I/O bound methods are coroutines.

close()[source]

Closes attachment reader and underlying connection.

This method has no effect if the attachment is already closed.

closed[source]

Return a bool indicating whether object is closed.

read(size=-1)[source]

Read and return up to n bytes, where size is an int().

Returns an empty bytes object on EOF, or None if the object is set not to block and has no data to read.

readable()[source]

Return a bool indicating whether object was opened for reading.

readall(size=8192)[source]

Read until EOF, using multiple read() call.

readline()[source]

Read and return a line of bytes from the stream.

If limit is specified, at most limit bytes will be read. Limit should be an int().

The line terminator is always b'\n' for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=None)[source]

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

«  Welcome to aiocouchdb’s documentation!   ::   Contents   ::   Common Base Objects  »