jaraco.modb


Namejaraco.modb JSON
Version 6.1.0 PyPI version JSON
download
home_pagehttps://github.com/jaraco/jaraco.modb
SummaryMongoDB Object DataBase (MODB) for Python objects
upload_time2023-11-27 16:31:22
maintainer
docs_urlNone
authorJason R. Coombs
requires_python>=3.8
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            .. image:: https://img.shields.io/pypi/v/jaraco.modb.svg
   :target: https://pypi.org/project/jaraco.modb

.. image:: https://img.shields.io/pypi/pyversions/jaraco.modb.svg

.. image:: https://github.com/jaraco/jaraco.modb/workflows/tests/badge.svg
   :target: https://github.com/jaraco/jaraco.modb/actions?query=workflow%3A%22tests%22
   :alt: tests

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
    :target: https://github.com/astral-sh/ruff
    :alt: Ruff

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
   :target: https://github.com/psf/black
   :alt: Code style: Black

.. .. image:: https://readthedocs.org/projects/PROJECT_RTD/badge/?version=latest
..    :target: https://PROJECT_RTD.readthedocs.io/en/latest/?badge=latest

.. image:: https://img.shields.io/badge/skeleton-2023-informational
   :target: https://blog.jaraco.com/skeleton


``jaraco.modb`` is a small, pure-Python library for persisting Python
objects to `MongoDB <https://www.mongodb.org/>`_.

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
<https://nbviewer.jupyter.org/github/jaraco/jaraco.modb/blob/master/tutorial.ipynb>`_.


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).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jaraco/jaraco.modb",
    "name": "jaraco.modb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jason R. Coombs",
    "author_email": "jaraco@jaraco.com",
    "download_url": "https://files.pythonhosted.org/packages/be/c4/d93330b6f0d93b78d6644dc926fe7c07c3d3314b891df5ed2e53a25ccb6f/jaraco.modb-6.1.0.tar.gz",
    "platform": null,
    "description": ".. image:: https://img.shields.io/pypi/v/jaraco.modb.svg\n   :target: https://pypi.org/project/jaraco.modb\n\n.. image:: https://img.shields.io/pypi/pyversions/jaraco.modb.svg\n\n.. image:: https://github.com/jaraco/jaraco.modb/workflows/tests/badge.svg\n   :target: https://github.com/jaraco/jaraco.modb/actions?query=workflow%3A%22tests%22\n   :alt: tests\n\n.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json\n    :target: https://github.com/astral-sh/ruff\n    :alt: Ruff\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :target: https://github.com/psf/black\n   :alt: Code style: Black\n\n.. .. image:: https://readthedocs.org/projects/PROJECT_RTD/badge/?version=latest\n..    :target: https://PROJECT_RTD.readthedocs.io/en/latest/?badge=latest\n\n.. image:: https://img.shields.io/badge/skeleton-2023-informational\n   :target: https://blog.jaraco.com/skeleton\n\n\n``jaraco.modb`` is a small, pure-Python library for persisting Python\nobjects to `MongoDB <https://www.mongodb.org/>`_.\n\nManual Usage\n============\n\n``jaraco.modb`` facilitates using `jsonpickle` to produce MongoDB-friendly\nrepresentations of pickleable Python objects for easy storage in a MongoDB\ndatabase.\n\nOne may simply encode and decode Python objects to MongoDB\nBSON-friendly representations::\n\n    class MyObject(object):\n        def __init__(self, val):\n            self.val = val\n\n    import jaraco.modb\n    import pymongo\n    mongo_collection = pymongo.MongoClient().mydb.mycollection\n    val = MyObject(3)\n    # save the object to the DB\n    id = mongo_collection.save(jaraco.modb.encode(val))\n    # retrieve the object from the DB\n    new_val = jaraco.modb.decode(mongo_collection.find_one(id))\n    assert isinstance(new_val, MyObject)\n    assert new_val.val == 3\n\nA more detailed tutorial is now `published as a Jupyter Notebook\n<https://nbviewer.jupyter.org/github/jaraco/jaraco.modb/blob/master/tutorial.ipynb>`_.\n\n\nAutomatic Usage\n===============\n\n``jaraco.modb`` also provides an SON Manipulator suitable for automatically\nencoding arbitrary objects for a pymongo.Database::\n\n    jaraco.modb.SONManipulator.install(mongo_collection.database)\n    mongo_collection.save({'val': val})\n\nUnfortunately, due to a limitation with the API of the SONManipulator,\nit's not possible to save a custom object as the document itself (the\ndocument must always be a dict).\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "MongoDB Object DataBase (MODB) for Python objects",
    "version": "6.1.0",
    "project_urls": {
        "Homepage": "https://github.com/jaraco/jaraco.modb"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98413e8ffe61520c112fc740b57a3f24c36429d3bac83cfac782e8cd89cc2ee5",
                "md5": "132adfc277061d0ccd16c1deb186889d",
                "sha256": "fc59eb0e81ef1a6964102813adb9b23129c6401b8dfcddd5c20497ead23c4b12"
            },
            "downloads": -1,
            "filename": "jaraco.modb-6.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "132adfc277061d0ccd16c1deb186889d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 3644,
            "upload_time": "2023-11-27T16:31:20",
            "upload_time_iso_8601": "2023-11-27T16:31:20.517414Z",
            "url": "https://files.pythonhosted.org/packages/98/41/3e8ffe61520c112fc740b57a3f24c36429d3bac83cfac782e8cd89cc2ee5/jaraco.modb-6.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bec4d93330b6f0d93b78d6644dc926fe7c07c3d3314b891df5ed2e53a25ccb6f",
                "md5": "3b88ef86df27be9f25583428dcb20946",
                "sha256": "55f0d730c05150012b33b814746561bf574bc2399fb5e69a50b13d8c6cb8f8b5"
            },
            "downloads": -1,
            "filename": "jaraco.modb-6.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3b88ef86df27be9f25583428dcb20946",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 13792,
            "upload_time": "2023-11-27T16:31:22",
            "upload_time_iso_8601": "2023-11-27T16:31:22.260015Z",
            "url": "https://files.pythonhosted.org/packages/be/c4/d93330b6f0d93b78d6644dc926fe7c07c3d3314b891df5ed2e53a25ccb6f/jaraco.modb-6.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-27 16:31:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jaraco",
    "github_project": "jaraco.modb",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "jaraco.modb"
}
        
Elapsed time: 0.14220s