Document storage¶
state: | stable |
---|---|
dependencies: | Doqu |
feature: | document_storage |
Doqu is a lightweight Python framework for document databases. It provides a uniform API for modeling, validation and queries across various kinds of storages. It’s the SQLAlchemy for non-relational databases.
Configuration example (in YAML):
extensions:
tool.ext.documents.Documents:
backend: doqu.ext.tokyo_tyrant
host: localhost
port: 1978
Or with defaults:
extensions:
tool.ext.documents.Documents: nil
The configuration is not Tool-specific. You can provide whatever keywords and values Doqu itself accepts.
Default backend chosen by Tool is Shelve and the data is stored in the file doqu_shelve.db. Please note that despite this extension does not require any packages except for Doqu itself, it is also unsuitable for medium to large volumes of data. However, it offers a simple persistence layer. Please refer to the Doqu documentation to choose a more efficient backend (for example, Tokyo Cabinet or MongoDB).
In short, this is what you will get:
import datetime
from tool.ext.documents import db
from doqu import Document, validators
class Person(Document):
structure = {
'name': unicode,
'birth_date': datetime.date
}
validators = {'name': [validators.required()]}
defaults = {'birth_date': datetime.date.today}
labels = {
'name': _('Full name'),
'birth_date': _('Birth date'),
}
use_dot_notation = True
john = Person(name='John')
print john.name
john.save(db)
print Person.objects(db).where(name__startswith='J').count()
Also, Web Admin provides an automatically generated web interface for all your document classes (if you register them).
More details:
- Doqu documentation (usage examples, tutorial, etc.)
- Shelve Doqu extension reference
- Web Admin (complete web interface for documents)