Package couchdb :: Module client :: Class Server

Class Server

object --+
         |
        Server

Representation of a CouchDB server.

>>> server = Server('http://localhost:5984/')

This class behaves like a dictionary of databases. For example, to get a list of database names on the server, you can simply iterate over the server object.

New databases can be created using the create method:

>>> db = server.create('python-tests')
>>> db
<Database 'python-tests'>

You can access existing databases using item access, specifying the database name as the key:

>>> db = server['python-tests']
>>> db.name
'python-tests'

Databases can be deleted using a del statement:

>>> del server['python-tests']
Instance Methods
 
__init__(self, uri='http://localhost:5984/', cache=None, timeout=None)
Initialize the server object.
 
__contains__(self, name)
Return whether the server contains a database with the specified name.
 
__iter__(self)
Iterate over the names of all databases.
 
__len__(self)
Return the number of databases.
 
__nonzero__(self)
Return whether the server is available.
 
__repr__(self)
repr(x)
 
__delitem__(self, name)
Remove the database with the specified name.
Database
__getitem__(self, name)
Return a Database object representing the database with the specified name.
Database
create(self, name)
Create a new database with the given name.
 
delete(self, name)
Delete the database with the specified name.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties
dict config
The configuration of the CouchDB server.
unicode version
The version string of the CouchDB server.

Inherited from object: __class__

Method Details

__init__(self, uri='http://localhost:5984/', cache=None, timeout=None)
(Constructor)

 
Initialize the server object.
Parameters:
  • uri - the URI of the server (for example http://localhost:5984/)
  • cache - either a cache directory path (as a string) or an object compatible with the httplib2.FileCache interface. If None (the default), no caching is performed.
  • timeout - socket timeout in number of seconds, or None for no timeout
Overrides: object.__init__

__contains__(self, name)
(In operator)

 
Return whether the server contains a database with the specified name.
Parameters:
  • name - the database name
Returns:
True if a database with the name exists, False otherwise

__repr__(self)
(Representation operator)

 
repr(x)
Overrides: object.__repr__
(inherited documentation)

__delitem__(self, name)
(Index deletion operator)

 
Remove the database with the specified name.
Parameters:
  • name - the name of the database
Raises:

__getitem__(self, name)
(Indexing operator)

 
Return a Database object representing the database with the specified name.
Parameters:
  • name - the name of the database
Returns: Database
a Database object representing the database
Raises:

create(self, name)

 
Create a new database with the given name.
Parameters:
  • name - the name of the database
Returns: Database
a Database object representing the created database
Raises:

delete(self, name)

 
Delete the database with the specified name.
Parameters:
  • name - the name of the database
Raises:

Since: 0.6


Property Details

config

The configuration of the CouchDB server.

The configuration is represented as a nested dictionary of sections and options from the configuration files of the server, or the default values for options that are not explicitly configured.

Get Method:
unreachable.config(self) - The configuration of the CouchDB server.
Type:
dict

version

The version string of the CouchDB server.

Note that this results in a request being made, and can also be used to check for the availability of the server.

Get Method:
unreachable.version(self) - The version string of the CouchDB server.
Type:
unicode