HumbleDB - MongoDB Object-Document Mapper
Project description
HumbleDB is an extremely lightweight ODM that works with pymongo to provide a convenient and easy to use interface. It enforces strict explictness when a connection to a MongoDB cluster or replica set is being used, by disallowing any read or write interaction outside of a context manager’s context block.
Quick Example
>>> from humbledb import Mongo, Document
>>> # config_database and config_collection are required attributes
>>> class TestDoc(Document):
... config_database = 'test'
... config_collection = 'testdoc'
... test_key = 't'
... other_key = 'o'
...
>>> # When you create a Document instance, you can set its keys via any
>>> # mapped attributes you create
>>> doc = TestDoc()
>>> doc.test_key = 'Hello'
>>> doc.other_key = 'World'
>>> # The __repr__ for the instance shows the actual doc
>>> doc
TestDoc({'t': 'Hello', 'o': 'World'})
>>> # A Document instance is also a dict, but you have to access the key
>>> # names directly
>>> doc['o']
u'World'
>>> # Or use the mapped attribute
>>> doc[TestDoc.test_key]
u'Hello'
>>> # The Mongo class manages database connection and is a context manager
>>> with Mongo:
... TestDoc.insert(doc)
...
>>> with Mongo:
... found = TestDoc.find_one()
...
>>> found
TestDoc({u'_id': ObjectId('50ad81586112797f89b99606'), u't': u'Hello', u'o': u'World'})
>>> doc
TestDoc({'_id': ObjectId('50ad81586112797f89b99606'), 't': 'Hello', 'o': 'World'})
>>> found['_id']
ObjectId('50ad81586112797f89b99606')
>>> found['t']
u'Hello'
>>> found.test_key
u'Hello'
See the documentation for more examples and detailed explanations.
Documentation
The complete documentation can be found on http://humbledb.readthedocs.org.
License
See LICENSE.rst.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
humbledb-3.0.0.tar.gz
(17.2 kB
view details)
File details
Details for the file humbledb-3.0.0.tar.gz
.
File metadata
- Download URL: humbledb-3.0.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
39eee11826d615a051054c32bc03c43b303c9c1cd67f5b1f533a7dfee66e4a06
|
|
MD5 |
00ee2df93f7e2a32bbb73d09fc8ddede
|
|
BLAKE2b-256 |
7efcaecd8c751b0c6ce5f86525b061878862040b71babb9f0e58a927d7e1f42e
|