Skip to main content

Pymongoext

Pymongoext is an ORM-like Pymongo extension that adds json schema validation, index management and intermediate data manipulators. Pymongoext simplifies working with MongoDB, while maintaining a syntax very identical to Pymongo.

pymongoext.Model is simply a wrapper around pymongo.Collection. As such, all of the pymongo.Collection API is exposed through pymongoext.Model. If you don’t find what you want in the pymongoext.Model API, please take a look at pymongo’s Collection documentation.

Documentation is available at https://pymongoext.readthedocs.io

The code is hosted on Github https://github.com/musyoka-morris/pymongoext

Features

  • schema validation (which uses MongoDB JSON Schema validation)

  • schema-less feature

  • nested and complex schema declaration

  • untyped field support

  • required fields validation

  • default values

  • custom validators

  • operator for validation (OneOf, AllOf, AnyOf, Not)

  • indexes management

  • data manipulators (transform documents before saving and after retrieval)

  • Easy to create custom data manipulators

  • object-like results instead of dict-like. (i.e. foo.bar instead of foo[‘bar’])

  • No custom-query language or API to learn (If you know how to use pymongo, you already know how to use pymongoext)

Supported MongoDB & Python Versions

Pymongoext uses JSON Schema for validation and thus we only support MongoDB v3.6+.

Pymongoext supports python v3+. Support for python v2.7 is currently under consideration.

Installation

We recommend the use of virtualenv and of pip. You can then use pip install -U pymongoext.

You may also have setuptools and thus you can use easy_install -U pymongoext. Another option is pipenv. You can then use pipenv install pymongoext to both create the virtual environment and install the package.

Alternatively, you can download the source from GitHub and run python setup.py install.

Examples

Some simple examples of what pymongoext code looks like:

from datetime import datetime
from pymongo import MongoClient, IndexModel
from pymongoext import *


class User(Model):
    @classmethod
    def db(cls):
        return MongoClient()['my_database_name']

    __schema__ = DictField(dict(
        email=StringField(required=True),
        name=StringField(required=True),
        yob=IntField(minimum=1900, maximum=2019)
    ))

    __indexes__ = [IndexModel('email', unique=True), 'name']

    class AgeManipulator(Manipulator):
        def transform_outgoing(self, doc, model):
            doc['age'] = datetime.now().year - doc['yob']
            return doc


# Create a user
>>> User.insert_one({'email': 'jane@gmail.com', 'name': 'Jane Doe', 'yob': 1990})

# Fetch one user
>>> user = User.find_one()

# Print the users age
>>> print(user.age)

Contributing

We welcome contributions! See the Contribution guidelines

Release files for pymongoext 2.3.3

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

Source distribution (sdist)

Source distribution for pymongoext 2.3.3
File Size Uploaded
pymongoext-2.3.3.tar.gz 18.9 kB Details

Built distribution (wheel)

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

Total release size: 34.9 kB

Release files / pymongoext-2.3.3.tar.gz

Download URL pymongoext-2.3.3.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e409d5cb6ff7a3d2c9d76b510cef7ed9be4c6d188af981ca9f3dce4048668ae8
BLAKE2b-256 checksum
How to use checksums
09e5510d35effb6a5a4f418619d35889747562383fbb9a50d821da7e8fc438a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Release files / pymongoext-2.3.3-py3-none-any.whl

Download URL pymongoext-2.3.3-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da17eeedeae97079a8238ab52f6b10daac5eb1a6d952f45d178b2242da9cf2a8
BLAKE2b-256 checksum
How to use checksums
c2e34f7025f7594f6f0a20acaa4831120e854b0fbbf592ff07baf6fcd5e65f4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

2.3.3 This release

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

1.0.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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