{ "info": { "author": "Kazuki Otsuka", "author_email": "otsuka.kazuki@googlemail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.7", "Topic :: Database :: Front-Ends", "Topic :: Software Development :: Libraries" ], "description": "![MongoBase Logo](https://github.com/kazukiotsuka/mongobase/blob/master/docs/source/img/mongobase.png)\n\n\nMongoBase is a Python package that provides high-level features:\n- Lightweight OR Mapper (ORM) for MongoDB\n- Simple DataBase Model structure definition with automatic type checking\n- High-level automatic text search indexes generation from multiple keys\n\n### Dependencies\n- pymongo_ 3.7+\n\nMore About MongoBase\n-------------------------\n\n| Component | Description |\n| ---- | --- |\n|**mongobase** | an high-level interface with model definition system from ModelBase and many database operations|\n|**modelbase** | an OR Mapper class with automatic type checking according to the defined structure (MongoBase subclass)|\n\nPhilosophies on MongoBase are\n- enable to use MongoDB on python easily and programatically safely\n- cleary viewable everything about the data model just by a quick looking over the model definition\n- easy to learn how to use. for instance, method names correspond to MongoDB to be able to use them as if on the mongoclient.\n- high performance. it uses the latest connection pool mechanism so that efficiently use client objects\n\n\n\n\nBasic Interfaces\n---------------------------\n\n#### Model Definition\n\nHere is the sample definition of a model.\n\n```python\nclass Bird(MongoBase):\n __collection__ = 'birds'\n __structure__ = {\n '_id': ObjectId,\n 'name': str,\n 'age': int,\n 'is_able_to_fly': bool,\n 'created': dt.datetime,\n 'updated': dt.datetime\n }\n __required_fields__ = ['_id', 'name']\n __default_values__ = {\n '_id': ObjectId(),\n 'is_able_to_fly': False,\n 'created': dt.datetime.now(dt.timezone.utc),\n 'updated': dt.datetime.now(dt.timezone.utc)\n }\n __validators__ = {\n 'name': validate_length(0, 1000),\n }\n __search_text_keys__ = ['name'] \n __search_text_index_type__ = 'bigram'\n __indexes__ = [\n [('item_name', ASCENDING),],\n ]\n```\n\nThe core model structure is defined as `__structure__` by a dictionaly. It is possible to cleary find out how the document structure is.\nOther components of the model definition is:\n\n| Component | Description |\n| ---- | --- |\n| `__collection__`| the collection name of the document. (required)|\n| `__structure__`| the core definition of the model. the type is automatically checked everytime when it is written on the db. the key `_id` is required. (required)|\n| `__required_fields__`| required properties. (optional)|\n| `__default_values__`| set default values for properties. (optional)|\n| `__validators__`| validator methods automatically check the value when the document is written on the db. (optional)|\n| `__search_text_keys__`| multiple keys can be set for the search text index. automatically written as the `search_text` property. (optional)|\n| `__search_text_index_type__`| `bigram`: value of `search_text` is set as bigram strings. `morpheme`: the string in `search_text` is parsed to morphemes (optional)|\n| `__search_text_weight_type__`| `uniform`: each string has the same weight. `weighted`: enable to set weights as `[('key1', 3), ('key2', 1)]` (optional)|\n| `__indexes__`| indexes can be set. `.createIndex()` method creates the indexes on the db. (optional)|\n\n\nNow the basic usages are introduced.\n\n#### Insert & Update\n```python\n>> chicken = Bird({'_id': ObjectId(), 'name': 'chicken', 'age': 3})\n>> chicken.save()\n{'_id': ObjectId('5c80f4fa16fa0d6c102cd2a6'),\n 'name': 'chicken',\n 'age': 3,\n 'is_able_to_fly': False,\n 'created': datetime.datetime(2019, 3, 7, 10, 39, 54, 643685, tzinfo=datetime.timezone.utc),\n 'updated': datetime.datetime(2019, 3, 7, 10, 39, 54, 643690, tzinfo=datetime.timezone.utc)}\n>> chicken.is_able_to_fly = True\n>> chicken.update()\n```\n\n#### Find\n```python\n>>> Bird.findOne({'name': 'mother chicken'})\n{'_id': ObjectId('5c79166716fa0d215968d3ba'),\n 'name': 'mother chicken',\n 'age': 63,\n 'is_able_to_fly': False,\n 'created': datetime.datetime(2019, 3, 1, 11, 20, 21, 306000),\n 'updated': datetime.datetime(2019, 3, 1, 11, 20, 21, 306000)}\n>>> mother_chicken.remove()\n1\n>>> all_chickens = Bird.find({'name': 'chicken'}, sort=[('_id', ASCENDING)])\nlist of mongobase instances are returned.\n>>> len(all_chickens)\n18\n>>> Bird.count()\n201\n```\n\n#### Bulk Operations\n\n- bulk_insert\n```python\n>>> many_pigeon = []\n>>> for i in range(10000):\n>>> many_pigeon += [Bird({'_id': ObjectId(), 'name': f'pigeon', 'age': i})]\n>>> Bird.bulk_insert(many_pigeon)\n10000\n```\n\n- bulk_update\n```\n>>> updates = []\n>>> for pigeon in many_pigeon:\n>>> pigeon.age *= 3\n>>> updates += [pigeon]\n>>> Bird.bulk_update(updates)\n10000\n```\n\n\n\n\n#### Contextual Database\n\n```python\nwith db_context(db_uri='localhost', db_name='test') as db:\n flamingo = Bird({'_id': ObjectId(), 'name': 'flamingo', 'age': 20})\n flamingo.save(db=db)\n\n flamingo.age = 23\n flamingo = flamingo.update(db=db)\n flamingo = Bird.findAndUpdateById(flamingo._id, {'age': 24}, db=db)\n\n n_flamingo = Bird.count({'name': 'flamingo'}, db=db)\n\nBird.count({'name': 'flamingo'})\n\n```\n\n#### Multi Processing\n```python\ndef breed(tasks):\n db = Bird._db() # create a MongoDB Client for the forked process\n for i in range(len(tasks)):\n sparrow = Bird({'_id': ObjectId(), 'name': f'sparrow', 'age': 0})\n sparrow.save(db=db)\n\ntasks = [[f'task {i}' for i in range(N_BATCH)] for j in range(N_PROCESS)\nprocess_pool = multiprocessing.Pool(N_PROCESS)\nprocess_pool.map(breed, tasks)\n```\n\n\n#### MongoBase has Many Other Features\nIf you'd like to know other features, please check the file mongobase.py.\n\nDB Settings\n---------------------------\nsimply write to mongobase/config.py\n```python\nMONGO_DB_URI = \"101.21.434.121\"\nMONGO_DB_URI_TEST = \"localhost\"\nMONGO_DB_NAME = \"zoo\"\nMONGO_DB_NAME_TEST = \"zoo-test\"\nMONGO_DB_CONNECT_TIMEOUT_MS = 3000\nMONGO_DB_SERVER_SELECTION_TIMEOUT_MS = 3000\nMONGO_DB_SOCKET_TIMEOUT_MS = 300000\nMONGO_DB_SOCKET_KEEP_ALIVE = True\nMONGO_DB_MAX_IDLE_TIME_MS = 40000\nMONGO_DB_MAX_POOL_SIZE = 200\nMONGO_DB_MIN_POOL_SIZE = 10\nMONGO_DB_WAIT_QUEUE_MULTIPLE = 12\nMONGO_DB_WAIT_QUEUE_TIMEOUT_MS = 100\n```\n\n\nGetting Started\n------------------\nIf you start MongoBase, there is a tutorial jupyter notebook here. \nHighly recommend to check it.\nhttps://github.com/kazukiotsuka/mongobase/blob/master/tutorial/MongoBase_starting_guide.ipynb\n\n\nRelease and Contributing\n---------------------------\nMany methods are the wrapper of pymongo. \nThere are a lot of features that this library is covering. \nWould appreciate if you add their methods anytime.\n\n\n\n#### version 0.3.0\n##### New features\n- bulk_insert()\n- bulk_update()\n- performance improvement with ConnectionPool (single MongoClient for each process)\n- MongoBase_start_guide.ipynb\n- contextual db client mode by `with db_context() as db`\n- code efficiency improvement\n- abolished `insert_if_not_exists` parameter for `save(), update()`\n- changed some method names (e.g. remove -> delete)\n- using pymongo > 3.5 methods (e.g. insert_one()) \n- enhance documents\n\n#### version 0.2.0\n##### New features\n- MongoBase and ModelBase class are separated\n- enable to use MongoClient instance dynamically\n- some useful mongodb operations are added\n\n#### version 0.1.0\n##### New features\n- The initial implementation\n- automatic type checking mechanism\n- basic mongodb operations\n\n\nLicense\n--------------------\nMongoBase is MIT-style licensed, as found in the LICENSE file.\n\n", "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/kazukiotsuka/mongobase", "keywords": "mongodb,mongo,pymongo,orm,or mapper", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "mongobase", "package_url": "https://pypi.org/project/mongobase/", "platform": "", "project_url": "https://pypi.org/project/mongobase/", "project_urls": { "Homepage": "https://github.com/kazukiotsuka/mongobase" }, "release_url": "https://pypi.org/project/mongobase/0.3.1a0/", "requires_dist": [ "pymongo (>=3.6.0)" ], "requires_python": "~=3.6", "summary": "A lightweight Pythonic OR Mapper for MongoDB.", "version": "0.3.1a0" }, "last_serial": 4915000, "releases": { "0.3.0a0": [ { "comment_text": "", "digests": { "md5": "549a9b5ab650c317940149e5b40e31ba", "sha256": "cf084e2aa400ca1076d85d1c031a0f406ee2a57c41c015362bede0504b205e61" }, "downloads": -1, "filename": "mongobase-0.3.0a0-py3-none-any.whl", "has_sig": false, "md5_digest": "549a9b5ab650c317940149e5b40e31ba", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": "~=3.6", "size": 14398, "upload_time": "2019-03-08T09:10:01", "url": "https://files.pythonhosted.org/packages/9e/9d/abbec7833b185528775306b7a153f65520d51fc6b4085908b745be1dffd3/mongobase-0.3.0a0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6533d8885d67dbd7ef95dae2446f6e56", "sha256": "0867cf68e8e633baa602bfb9bc5838c522595b5d88b96a5b8e9288c5d94b8152" }, "downloads": -1, "filename": "mongobase-0.3.0a0.tar.gz", "has_sig": false, "md5_digest": "6533d8885d67dbd7ef95dae2446f6e56", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.6", "size": 15201, "upload_time": "2019-03-08T09:10:03", "url": "https://files.pythonhosted.org/packages/47/32/6b5e25287d2f72846d690c4a57c400f0ebcb3f05c171dbb509a52847087f/mongobase-0.3.0a0.tar.gz" } ], "0.3.1a0": [ { "comment_text": "", "digests": { "md5": "eb4e73e6c20f14c5cca4bf642cb02da9", "sha256": "d9b67d021da1686e1be16bfcf102e92db6f2d44690adbb29ce3c3089c20dd8cc" }, "downloads": -1, "filename": "mongobase-0.3.1a0-py3-none-any.whl", "has_sig": false, "md5_digest": "eb4e73e6c20f14c5cca4bf642cb02da9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": "~=3.6", "size": 14457, "upload_time": "2019-03-08T10:53:01", "url": "https://files.pythonhosted.org/packages/72/47/c17d714068d2b251e5323c5d10a001ac90712ba0a739e0a5eb52a956a171/mongobase-0.3.1a0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "19d26ea7fec0229f728e371ce3156a29", "sha256": "d54c9ec0467f2fdc7a2b49e646f0da9481d23a828dcbeaeb64a7d3253e1ac2a4" }, "downloads": -1, "filename": "mongobase-0.3.1a0.tar.gz", "has_sig": false, "md5_digest": "19d26ea7fec0229f728e371ce3156a29", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.6", "size": 15307, "upload_time": "2019-03-08T10:53:03", "url": "https://files.pythonhosted.org/packages/b1/71/45b362896619b95818f225b34d59ca6afab4f8483a16aed18144cb6ff5fb/mongobase-0.3.1a0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "eb4e73e6c20f14c5cca4bf642cb02da9", "sha256": "d9b67d021da1686e1be16bfcf102e92db6f2d44690adbb29ce3c3089c20dd8cc" }, "downloads": -1, "filename": "mongobase-0.3.1a0-py3-none-any.whl", "has_sig": false, "md5_digest": "eb4e73e6c20f14c5cca4bf642cb02da9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": "~=3.6", "size": 14457, "upload_time": "2019-03-08T10:53:01", "url": "https://files.pythonhosted.org/packages/72/47/c17d714068d2b251e5323c5d10a001ac90712ba0a739e0a5eb52a956a171/mongobase-0.3.1a0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "19d26ea7fec0229f728e371ce3156a29", "sha256": "d54c9ec0467f2fdc7a2b49e646f0da9481d23a828dcbeaeb64a7d3253e1ac2a4" }, "downloads": -1, "filename": "mongobase-0.3.1a0.tar.gz", "has_sig": false, "md5_digest": "19d26ea7fec0229f728e371ce3156a29", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.6", "size": 15307, "upload_time": "2019-03-08T10:53:03", "url": "https://files.pythonhosted.org/packages/b1/71/45b362896619b95818f225b34d59ca6afab4f8483a16aed18144cb6ff5fb/mongobase-0.3.1a0.tar.gz" } ] }