Skip to main content

MDocument

pipeline status coverage report pypi link

MDocument is a simple ORM for MongoDB with addition of relations.

Usage

There are two ways of using mdocument: 1. Specify database, colleciton and client in class. 2. Use modified mongo motor client.

Specifying document parameters in class

import asyncio

import motor.motor_asyncio

from mdocument import MDocument, relations, model

client = motor.motor_asyncio.AsyncIOMotorClient()

class Video(MDocument):
    __collection__ = "videos"
    __database__ = "mdocument"
    __client__ = client

    class Model(MDocument.Model):
        title = model.Field(str)
        views_count = model.Field(int)
        public_id = model.Field(str, unique=True)

class Comment(MDocument):
    __collection__ = "comments"
    __database__ = "mdocument"
    __client__ = client

    class Model(MDocument.Model):
        text = model.Field(str)
        video = model.FieldSync(Video, relation=relations.RelationOneToMany, synced_fields=["_id", "title"])


async def main():
    video = await Video.create({"title": "Test"})

    comment1 = await Comment.create(
        video=video._id,
        message="First!",
    )

    comment2 = await Comment.create(
        video=video._id,
        message="Second!"
    )

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Now we can easily access our comments using our related documents

TODO: REWRITE DOCUMENTATION!

Metadata

Release files for mdocument 4.0.1611941755

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

Source distribution (sdist)

Source distribution for mdocument 4.0.1611941755
File Size Uploaded
mdocument-4.0.1611941755.tar.gz 7.2 kB Details

Built distribution (wheel)

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

Total release size: 15.5 kB

Release files / mdocument-4.0.1611941755.tar.gz

Download URL mdocument-4.0.1611941755.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4eaa70138349887a9ef0d4062704a5455ac4f4dc5be45d0d08e1100f3ec61544
BLAKE2b-256 checksum
How to use checksums
ea2727d3e4084fbfeeed6463854685ef21e6f31206f0d7935e246dbeedb0fd0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release files / mdocument-4.0.1611941755-py3-none-any.whl

Download URL mdocument-4.0.1611941755-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59ab800d9260f19e8bae07a651b4c49f6cff961f44fbf1e777aca20e0002fe46
BLAKE2b-256 checksum
How to use checksums
6fd03a11585df5721f992657206553c46da5192e7ebe9b58bb7bcd9d640a40d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release history Release notifications | RSS feed

This release

4.0.1611941755 This release

2 release files

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

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