mongoclass


Namemongoclass JSON
Version 1.6 PyPI version JSON
download
home_pagehttps://github.com/bossauh/mongoclass
SummaryA basic ORM like interface for mongodb in python that uses dataclasses.
upload_time2023-06-15 01:13:43
maintainer
docs_urlNone
authorPhilippe Mathew
requires_python
licenseMIT
keywords pymongo orm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Mongoclass
A basic ORM like interface for mongodb in python that uses dataclasses.

## Installation
To get started, install mongoclass using pip like so.
```bash
pip install -U mongoclass
```

# Getting Started
This section will explain the basics of how to use mongoclass. After reading this, read the API Reference for more information.
```py
from mongoclass import MongoClassClient
client = MongoClassClient("mongoclass", "localhost:27017")
```
This will create a MongoClassClient instance that exposes the features of mongoclass. MongoClassClient inherits from pymongo.MongoClient so you can also use it like you'd normally use pymongo.

## Schemas
To create a schema (or a preferred term, mongoclass), this is all you have to do.
```py
from dataclasses import dataclass

@client.mongoclass()
@dataclass
class User:
    name: str
    email: str
    phone: int
    country: str = "US"
```
This creates a User mongoclass that belongs in the user collection inside the default database. To create an actual User object and have it be inserted in the database, create an instance of User and call the .insert() method like so
```py
john = User("John Dee", "johndee@gmail.com", 5821)
insert_result = john.insert()
```
The first line creates the user John Dee with the provided information. Notice how we didn't need to provide a country, that is because country defaults to US.

The second line inserts it to the user collection in the default database and then returns a pymongo.InsertOneResult

> As an alternative to having to call .insert(), you can pass _insert=True to User() which will automatically insert as soon as the object is initialized. You do loose the ability to receive the pymongo.InsertOneResult

For the remaining guide and full documentation, click [here](https://oppenheimer.gitbook.io/mongoclass/)

# LICENSE
MIT License

Copyright (c) 2022 Philippe Mathew

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bossauh/mongoclass",
    "name": "mongoclass",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pymongo,orm",
    "author": "Philippe Mathew",
    "author_email": "philmattdev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9d/6a/2b705bead2d0155768a811cffca61c494fb5c55fac8a92b8bf494693b619/mongoclass-1.6.tar.gz",
    "platform": null,
    "description": "# Mongoclass\r\nA basic ORM like interface for mongodb in python that uses dataclasses.\r\n\r\n## Installation\r\nTo get started, install mongoclass using pip like so.\r\n```bash\r\npip install -U mongoclass\r\n```\r\n\r\n# Getting Started\r\nThis section will explain the basics of how to use mongoclass. After reading this, read the API Reference for more information.\r\n```py\r\nfrom mongoclass import MongoClassClient\r\nclient = MongoClassClient(\"mongoclass\", \"localhost:27017\")\r\n```\r\nThis will create a MongoClassClient instance that exposes the features of mongoclass. MongoClassClient inherits from pymongo.MongoClient so you can also use it like you'd normally use pymongo.\r\n\r\n## Schemas\r\nTo create a schema (or a preferred term, mongoclass), this is all you have to do.\r\n```py\r\nfrom dataclasses import dataclass\r\n\r\n@client.mongoclass()\r\n@dataclass\r\nclass User:\r\n    name: str\r\n    email: str\r\n    phone: int\r\n    country: str = \"US\"\r\n```\r\nThis creates a User mongoclass that belongs in the user collection inside the default database. To create an actual User object and have it be inserted in the database, create an instance of User and call the .insert() method like so\r\n```py\r\njohn = User(\"John Dee\", \"johndee@gmail.com\", 5821)\r\ninsert_result = john.insert()\r\n```\r\nThe first line creates the user John Dee with the provided information. Notice how we didn't need to provide a country, that is because country defaults to US.\r\n\r\nThe second line inserts it to the user collection in the default database and then returns a pymongo.InsertOneResult\r\n\r\n> As an alternative to having to call .insert(), you can pass _insert=True to User() which will automatically insert as soon as the object is initialized. You do loose the ability to receive the pymongo.InsertOneResult\r\n\r\nFor the remaining guide and full documentation, click [here](https://oppenheimer.gitbook.io/mongoclass/)\r\n\r\n# LICENSE\r\nMIT License\r\n\r\nCopyright (c) 2022 Philippe Mathew\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A basic ORM like interface for mongodb in python that uses dataclasses.",
    "version": "1.6",
    "project_urls": {
        "Download": "https://github.com/bossauh/mongoclass/archive/refs/tags/v_16.tar.gz",
        "Homepage": "https://github.com/bossauh/mongoclass"
    },
    "split_keywords": [
        "pymongo",
        "orm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d6a2b705bead2d0155768a811cffca61c494fb5c55fac8a92b8bf494693b619",
                "md5": "5cefe0ee51dd85db94420f5d8db65e5e",
                "sha256": "5aeb1669d63d96548dc8cfa6f06edf0ac01cf141a62d83208f0f458188667330"
            },
            "downloads": -1,
            "filename": "mongoclass-1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "5cefe0ee51dd85db94420f5d8db65e5e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10642,
            "upload_time": "2023-06-15T01:13:43",
            "upload_time_iso_8601": "2023-06-15T01:13:43.214959Z",
            "url": "https://files.pythonhosted.org/packages/9d/6a/2b705bead2d0155768a811cffca61c494fb5c55fac8a92b8bf494693b619/mongoclass-1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-15 01:13:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bossauh",
    "github_project": "mongoclass",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mongoclass"
}
        
Elapsed time: 0.10209s