MongoDB Object DataBase (MODB) for Python objects
Project description
Overview
jaraco.modb is a small, pure-Python library for persisting Python objects to MongoDB.
jaraco.modb is written by Jason R. Coombs. It is licensed under an MIT-style permissive license.
You can install it with easy_install jaraco.modb or grab the source code from the mercurial repository.
Usage
jaraco.modb facilitates using jsonpickle to produce MongoDB-friendly representations of pickleable Python objects for easy storage in a MongoDB database.
The jsonpickle module requires initialization to use the backends supplied by jaraco.modb, so the application must first call init():
import jaraco.modb jaraco.modb.init()
Thereafter, one can simply encode and decode Python objects to MongoDB BSON-friendly representations:
class MyObject(object):
def __init__(self, val):
self.val = val
import pymongo
mongo_collection = pymongo.Connection().mydb.mycollection
val = MyObject(3)
# save the object to the DB
id = mongo_collection.save(jaraco.modb.encode(val))
# retrieve the object from the DB
new_val = jaraco.modb.decode(mongo_collection.find_one(id))
assert isinstance(new_val, MyObject)
assert new_val.val == 3
Changes
1.0
Initial release
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
File details
Details for the file jaraco.modb-1.0.5.zip.
File metadata
- Download URL: jaraco.modb-1.0.5.zip
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56412e747fb3ee22b05fe06a0305f3280266aa54beb3fe7827cf64c565a9b7e7
|
|
| MD5 |
6b535215d0f18e21d8edd8ec3841561d
|
|
| BLAKE2b-256 |
c785b80afde71d30e8af5e8df4fedb6658c558d990b8c77491e19de4773c61f4
|