{ "info": { "author": "Matej Ramuta", "author_email": "matej.ramuta@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# SmartNinja Mongo\n\nA simple **wrapper** for MongoDB (`pymongo`) and TinyDB (`tinymongo`). It also provides a lightweight **object-document mapper** (ODM).\n\nUse it if you don't want to (or can't) install MongoDB locally.\n\n## Installation\n\nInstall the package via pip:\n\n\tpip install smartninja-mongo\n\nOr add it in your `requirements.txt` and run `pip install -r requirements.txt`.\n\n### Dependencies\n\nSmartNinja Mongo automatically installs the following dependencies:\n\n- `tinymongo`\n- `pymongo`\n- `tinydb`\n- `tinydb_serialization` (used to easily convert datetime objects)\n\n## How it works\n\nYou write your code as you would using the `pymongo` package. Except that you get the `MongoClient` class from the `smartninja_mongo` library (see examples below).\n\nSmartNinja Mongo **automatically** figures out whether you're the program is running on **localhost** or on a **production** server.\n\nIf it's on **localhost**, TinyDB will be used instead of MongoDB via the `tinymongo` package (except if you set the `CUSTOM_MONGO_SERVER` env var).\n\nIf the app runs on **Heroku** or on **Azure**, the `smartninja_mongo` package automatically recognizes this and returns the `pymongo` client class instead of the one from `tinymongo`.\n\nIf your program runs in **some other production environment**, just set the `CUSTOM_MONGO_SERVER` env var (add any value to it that comes back as `True`, like for example `\"1\"`) and `pymongo` client will be used.\n\n## Usage\n\nSmartNinja Mongo's only task is to get you the right Mongo client:\n\n```python\nfrom smartninja_mongo.connection import MongoClient\n\nclient = MongoClient('mongodb://ds012345.mlab.com:56789/')\n```\n\nIf your Python program runs on Heroku (for example), you'll get back a `MongoClient` from the `pymongo` library which has a connection to the production MongoDB database (in this case the mLab's Mongo database).\n\nBut if your app runs on localhost, a TinyDB instance will be created (you'll see a `localhost.db` folder created, put it in `.gitignore`).\n\nEven if TinyDB is used on localhost instead of the MongoDB, you can write your code in the MongoDB way (or `pymongo` way).\n\nSee the following examples:\n\n```python\ndb = client.my_database\n\ncollection = db.users\n\nuser_id = collection.insert_one({\"first_name\": \"Matej\", \"last_name\": \"Ramuta\", \"year_born\": 1987, \"created\": datetime.datetime.now()}).inserted_id\n\nuser_info = collection.find_one({\"_id\": user_id})\n\nprint(user_info)\n```\n\n### More usage examples\n\nFor more usage examples see PyMongo docs: [https://api.mongodb.com/python/current/](https://api.mongodb.com/python/current/).\n\n### Beware\n\nThere might be some incompatibilities between TinyMongo and PyMongo. Make sure to also check the [TinyMongo docs](https://tinydb.readthedocs.io/en/latest/index.html) to identify the problem if weird behavior occurs.\n\n### ODM\n\nMongoDB accepts data as dictionaries and also returns data as dicts. If you'd like to use model classes in your project, you can use a base model from the SmartNinja Mongo library:\n\n```python\nfrom smartninja_mongo.odm import Model\n\n\nclass User(Model):\n def __init__(self, first_name, **kwargs):\n self.first_name = first_name\n\n super().__init__(**kwargs)\n```\n\nMake sure to add `**kwargs` as a parameter and call `super()` at the end of the `__init__` method.\n\nAlternatively you can skip `__init__` completely\n\n```python\nclass User(Model):\n\tpass\n```\n\n#### The benefit of using SmartNinja Mongo ODM `Model`\n\nThe main benefit is that you get a method called: `convert_dict_to_object()`:\n\n```python\nuser_info = collection.find_one({\"_id\": user_id})\n\nuser_obj = User.convert_dict_to_object(data_dict=user_info)\n\nprint(user_obj.first_name)\n```\n\nThis `Model` class provides a very lightweight and simple **object-document mapping** (ODM).\n\n## Contributions\n\nContributions via pull requests are warmly welcome!\n\n### TODO\n\n- tests\n- CI", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/smartninja/smartninja-mongo", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "smartninja-mongo", "package_url": "https://pypi.org/project/smartninja-mongo/", "platform": "", "project_url": "https://pypi.org/project/smartninja-mongo/", "project_urls": { "Homepage": "https://github.com/smartninja/smartninja-mongo" }, "release_url": "https://pypi.org/project/smartninja-mongo/0.5/", "requires_dist": null, "requires_python": "", "summary": "SmartNinja Mongo - a simple MongoDB & TinyDB wrapper.", "version": "0.5" }, "last_serial": 4837526, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "7ed43c10b5ea0f394d1520d7b19d8e82", "sha256": "b58297db98a3c2692b5abf46a5356398aba3e9a9859095fea08094e4bf0632b1" }, "downloads": -1, "filename": "smartninja-mongo-0.1.tar.gz", "has_sig": false, "md5_digest": "7ed43c10b5ea0f394d1520d7b19d8e82", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2869, "upload_time": "2019-02-10T17:33:34", "url": "https://files.pythonhosted.org/packages/99/1d/57acd556463fcbdc913a5450ad4bd02fb4aea2072edf49b25a706a5c6ebc/smartninja-mongo-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "cc082d06ee9216b42b7495b06588fceb", "sha256": "8c7074d0831d074aca1e0e558c03f7295fc7ebea62b37284956a36f13c843d9d" }, "downloads": -1, "filename": "smartninja-mongo-0.2.tar.gz", "has_sig": false, "md5_digest": "cc082d06ee9216b42b7495b06588fceb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2872, "upload_time": "2019-02-10T17:41:58", "url": "https://files.pythonhosted.org/packages/1a/23/9541e79679b112c0c29a074aee3ba6a33f3c342a1ccd5ff2ae098e702bc1/smartninja-mongo-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "d061cde5ed91f6b419b604fb5bc39fa2", "sha256": "110c2a820994cca080c65d1b9be3fae53b07261bdb896db1189c53d980893768" }, "downloads": -1, "filename": "smartninja-mongo-0.3.tar.gz", "has_sig": false, "md5_digest": "d061cde5ed91f6b419b604fb5bc39fa2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3502, "upload_time": "2019-02-15T01:12:17", "url": "https://files.pythonhosted.org/packages/bf/dd/a368361252eefa5a9df3914e7294b4054d62f1197d2ba4e88669cfcc5f5a/smartninja-mongo-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "e3d11ec6aed5ea5e323b7bcfe40bc773", "sha256": "1532720753a5e5d0baefe54ca15e9783da055304958de333a236e8215851dea7" }, "downloads": -1, "filename": "smartninja-mongo-0.4.tar.gz", "has_sig": false, "md5_digest": "e3d11ec6aed5ea5e323b7bcfe40bc773", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3758, "upload_time": "2019-02-18T16:47:58", "url": "https://files.pythonhosted.org/packages/5f/39/a121da25c59a6ec7c4cef602ca8ff1bd1fb2d6a8fb323ae4fdbf8939f1ce/smartninja-mongo-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "35bf8345fbaf278a8b5e42d6afbb4ef7", "sha256": "c4f862e07183dfe06154904115b0df81da448cbfc99b33e2e0f487e1313fc415" }, "downloads": -1, "filename": "smartninja-mongo-0.5.tar.gz", "has_sig": false, "md5_digest": "35bf8345fbaf278a8b5e42d6afbb4ef7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3834, "upload_time": "2019-02-18T23:59:34", "url": "https://files.pythonhosted.org/packages/8d/6e/719226e517ae95fabd1cfaaccb2784d1f4f82ff053e17d27010402782426/smartninja-mongo-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "35bf8345fbaf278a8b5e42d6afbb4ef7", "sha256": "c4f862e07183dfe06154904115b0df81da448cbfc99b33e2e0f487e1313fc415" }, "downloads": -1, "filename": "smartninja-mongo-0.5.tar.gz", "has_sig": false, "md5_digest": "35bf8345fbaf278a8b5e42d6afbb4ef7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3834, "upload_time": "2019-02-18T23:59:34", "url": "https://files.pythonhosted.org/packages/8d/6e/719226e517ae95fabd1cfaaccb2784d1f4f82ff053e17d27010402782426/smartninja-mongo-0.5.tar.gz" } ] }