Session

Every request to the CouchDB server is embedded into a session. A session is represented by an instance of aiocouch.CouchDB. A session can be created using the constructor of the class or by using the class as a context manager.

Examples

Create a session with the context manager

with aiocouch.CouchDB("http://localhost") as couchdb:
    await couchdb.check_credentials()

Note that the session will be closed, once the scope of the with statement is left.

A session can also be handled using variables. The session needs to be closed manually.

couchdb = aiocouch.CouchDB("http://localhost")
await couchdb.check_credentials()
await couchdb.close()

Reference

class aiocouch.CouchDB(*args, **kwargs)

CouchDB Server Connection Session

The

Parameters
  • server (str) – URL of the CouchDB server

  • user (str) – user used for authentication

  • password (str) – password for authentication

  • cookie (str) – The session cookie used for authentication

  • kwargs (Any) – Any other kwargs are passed to aiohttp.ClientSession

await __getitem__(id)

Returns a representation for the given database identifier

Raises

NotFoundError – if the database does not exists

Parameters

id (str) – The identifier of the database

Return type

Database

Returns

The representation of the database

await check_credentials()

Check the provided credentials.

Raises

UnauthorizedError – if provided credentials aren’t valid

await close()

Closes the connection to the CouchDB server

await create(id, exists_ok=False, **kwargs)

Creates a new database on the server

Raises

PreconditionFailedError – if the database already exists and exists_ok is False

Parameters
  • id (str) – the identifier of the database

  • exists_ok (bool) – If True, don’t raise if the database exists

Return type

Database

Returns

Returns a representation for the created database

await info()

Returns the meta information about the connected CouchDB server.

See also GET /

Return type

dict

Returns

A dict containing the response json.

await keys(**params)

Returns all database names

Return type

list

Returns

A list containing the names of all databases on the server