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
async 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 exist
- Parameters
id (
str
) – The identifier of the database- Return type
- Returns
The representation of the database
- await check_credentials()¶
Check the provided credentials.
- Raises
UnauthorizedError – if provided credentials aren’t valid
- Return type
- await create(id, exists_ok=False, **kwargs)¶
Creates a new database on the server
- Raises
PreconditionFailedError – if the database already exists and
exists_ok
isFalse
- Parameters
- Return type
- Returns
Returns a representation for the created database