asyncio Interface

The asyncio interface is for use with the Async IO Python standard library that ships with Python 3.4 and greater. This documentation contains the API reference for how to use the acouchbase module with asyncio.

For the most part, the acouchbase API functions like its synchronous counterpart, couchbase, except for its asynchronous nature. Where the synchronous API returns a Result object, the acouchbase API returns an AsyncResult which will have its callback invoked with a result.

As such, we will omit the mentions of the normal key value operations, which function identially to their synchronous conterparts documented in the Cluster Bucket, and Collection classes.

class acouchbase.cluster.AIOClientMixin[source]
__init__(connstr=None, *args, **kwargs)[source]
on_connect()[source]
connected

Boolean read only property indicating whether this instance has been connected.

Note that this will still return true even if it is subsequently closed via _close()

class acouchbase.cluster.Cluster
__init__(connection_string, *options, **kwargs)

Create a new Async Bucket. An async Bucket is an object which functions like a normal synchronous bucket connection, except that it returns future objects (i.e. AsyncResult objects) instead of Result. These objects are actually MultiResult objects which are empty upon retun. As operations complete, this object becomes populated with the relevant data.

Note that the AsyncResult object must currently have valid callback and errback fields initialized after they are returned from the API methods. If this is not the case then an exception will be raised when the callbacks are about to arrive. This behavior is the primary reason why this interface isn’t public, too :)

Parameters
  • iops – An IOPS-interface conforming object. This object must not be used between two instances, and is owned by the connection object.

  • kwargs – Additional arguments to pass to the Bucket constructor

analytics_query(*args, **kwargs)

Executes an Analytics query against the remote cluster and returns a AnalyticsResult with the results of the query.

Parameters
  • statement – the analytics statement to execute

  • options – the optional parameters that the Analytics service takes based on the Analytics RFC.

Returns

An AnalyticsResult object with the results of the query or error message if the query failed on the server.

Raise

AnalyticsException errors associated with the analytics query itself. Also, any exceptions raised by the underlying platform - TimeoutException for example.

search_query(*args, **kwargs)

Executes a Search or FTS query against the remote cluster and returns a SearchResult implementation with the results of the query.

from couchbase.search import MatchQuery, SearchOptions

it = cb.search('name', MatchQuery('nosql'), SearchOptions(limit=10))
for hit in it:
    print(hit)
Parameters
  • index (str) – Name of the index to use for this query.

  • query – the fluent search API to construct a query for FTS.

  • options – the options to pass to the cluster with the query.

  • kwargs – Overrides corresponding value in options.

Returns

A SearchResult object with the results of the query or error message if the query failed on the server.

Raise

SearchException Errors related to the query itself. Also, any exceptions raised by the underlying platform - TimeoutException for example.

query(*args, **kwargs)

Perform a N1QL query.

Parameters
  • statement – the N1QL query statement to execute

  • options – A QueryOptions object or the positional parameters in the query.

  • kwargs – Override the corresponding value in the Options. If they don’t match any value in the options, assumed to be named parameters for the query.

Returns

The results of the query or error message if the query failed on the server.

Raise

QueryException - for errors involving the query itself. Also any exceptions raised by underlying system - TimeoutException for instance.

class acouchbase.cluster.Bucket
view_query(*args, **kwargs)

Reimplemented from base class.

This method does not add additional functionality of the base class’ query() method (all the functionality is encapsulated in the view class anyway). However it does require one additional keyword argument

Parameters

itercls (class) – A class used for instantiating the view object. This should be a subclass of AsyncViewBase.

class acouchbase.cluster.Collection
__init__(*args, **kwargs)

Couchbase collection.

param parent_scope

parent scope

param name

name of collection

param options

miscellaneous options

Warning

This is an internal API call.

Components external to Couchbase Python Client should not rely on it is not intended for use outside the module, even to other Couchbase components.

class acouchbase.iterator.AQueryResult[source]
__iter__()

Unlike our base class, iterating does not make sense here

__init__(*args, **kwargs)[source]
class acouchbase.iterator.ASearchResult[source]
__iter__()

Unlike our base class, iterating does not make sense here

__init__(*args, **kwargs)[source]

Initialize a new AsyncViewBase object. This is intended to be subclassed in order to implement the require methods to be invoked on error, data, and row events.

Usage of this class is not as a standalone, but rather as an itercls parameter to the query() method of the connection object.

class acouchbase.iterator.AViewResult[source]
__iter__()

Unlike our base class, iterating does not make sense here

__init__(*args, **kwargs)[source]

Initialize a new AsyncViewBase object. This is intended to be subclassed in order to implement the require methods to be invoked on error, data, and row events.

Usage of this class is not as a standalone, but rather as an itercls parameter to the query() method of the connection object.

class acouchbase.iterator.AAnalyticsResult[source]
__iter__()

Unlike our base class, iterating does not make sense here

__init__(*args, **kwargs)[source]