Skip to main content
https://img.shields.io/pypi/v/jaraco.modb.svg https://img.shields.io/pypi/pyversions/jaraco.modb.svg tests Ruff Code style: Black https://img.shields.io/badge/skeleton-2023-informational

jaraco.modb is a small, pure-Python library for persisting Python objects to MongoDB.

Manual Usage

jaraco.modb facilitates using jsonpickle to produce MongoDB-friendly representations of pickleable Python objects for easy storage in a MongoDB database.

One may simply encode and decode Python objects to MongoDB BSON-friendly representations:

class MyObject(object):
    def __init__(self, val):
        self.val = val

import jaraco.modb
import pymongo
mongo_collection = pymongo.MongoClient().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

A more detailed tutorial is now published as a Jupyter Notebook.

Automatic Usage

jaraco.modb also provides an SON Manipulator suitable for automatically encoding arbitrary objects for a pymongo.Database:

jaraco.modb.SONManipulator.install(mongo_collection.database)
mongo_collection.save({'val': val})

Unfortunately, due to a limitation with the API of the SONManipulator, it’s not possible to save a custom object as the document itself (the document must always be a dict).

Release files for jaraco.modb 6.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jaraco.modb 6.1.0
File Size Uploaded
jaraco.modb-6.1.0.tar.gz 13.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jaraco.modb 6.1.0
File Interpreter ABI Platform
jaraco.modb-6.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / jaraco.modb-6.1.0.tar.gz

Download URL jaraco.modb-6.1.0.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
55f0d730c05150012b33b814746561bf574bc2399fb5e69a50b13d8c6cb8f8b5
BLAKE2b-256 checksum
How to use checksums
bec4d93330b6f0d93b78d6644dc926fe7c07c3d3314b891df5ed2e53a25ccb6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / jaraco.modb-6.1.0-py3-none-any.whl

Download URL jaraco.modb-6.1.0-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc59eb0e81ef1a6964102813adb9b23129c6401b8dfcddd5c20497ead23c4b12
BLAKE2b-256 checksum
How to use checksums
98413e8ffe61520c112fc740b57a3f24c36429d3bac83cfac782e8cd89cc2ee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release history Release notifications | RSS feed

This release

6.1.0 This release

2 release files

6.0.0

2 release files

5.0.0

2 release files

4.1.0

2 release files

4.0

2 release files

3.6

2 release files

3.5.1

2 release files

3.5

2 release files

3.4

1 release file

3.3.2

1 release file

3.3

1 release file

3.2

1 release file

3.1

1 release file

3.0

1 release file

2.1.1

1 release file

2.1

1 release file

2.0

1 release file

1.2.1

1 release file

1.2

1 release file

1.1

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page