Utilities

Various useful functions. Some can be imported from doqu.utils, some are available directly at doqu.

doqu.utils.get_db(settings_dict=None, **settings_kwargs)

Storage adapter factory. Expects path to storage backend module and optional backend-specific settings. Returns storage adapter instance. If required underlying library is not found, exception pkg_resources.DistributionNotFound is raised with package name and version as the message.

Parameters:
  • backend – string, dotted path to a Doqu storage backend (e.g. doqu.ext.tokyo_tyrant). See Extensions for a list of bundled backends or Backend API for backend API reference.

Usage:

import doqu

db = doqu.get_db(backend='doqu.ext.shelve', path='test.db')

query = SomeDocument.objects(db)

Settings can be also passed as a dictionary:

SETTINGS = {
    'backend': 'doqu.ext.tokyo_cabinet',
    'path': 'test.tct',
}

db = doqu.get_db(SETTINGS)

The two methods can be combined to override certain settings:

db = doqu.get_db(SETTINGS, path='another_db.tct')
doqu.utils.camel_case_to_underscores(class_name)

Returns a pretty readable name based on the class name. For example, “SomeClass” is translated to “some_class”.

doqu.utils.load_fixture(path, db=None)

Reads given file (assuming it is in a known format), loads it into given storage adapter instance and returns that instance.

Parameters:
  • path – absolute or relative path to the fixture file; user constructions (“~/foo”) will be expanded.
  • db – a storage adapter instance (its class must conform to the BaseStorageAdapter API). If not provided, a memory storage will be created.

Usage:

import doqu

db = doqu.load_fixture('account.csv')

query = SomeDocument.objects(db)

Previous topic

Validators

Next topic

Extensions

This Page