{ "info": { "author": "Johan Nestaas", "author_email": "johannestaas@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Console", "Environment :: MacOS X", "Environment :: Win32 (MS Windows)", "Environment :: X11 Applications :: Qt", "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Programming Language :: Python" ], "description": "dongo\n=====\n\nA Django-ORM inspired Mongo ODM.\n\nPython 2.7 and 3.x compatible, and requires the database server running at least MongoDB 2.6, as PyMongo does.\n\nInstallation\n------------\n\nFrom PyPI::\n\n $ pip install dongo\n\nFrom the project root directory::\n\n $ python setup.py install\n\nUsage\n-----\n\nDongo is a Django-ORM inspired ODM for mongodb.\n\nHere are a few examples of the query and class syntax.\n\nSetup\n-----\n\nYou will need to first connect to a database and host. By default, localhost\nport 27017 will be selected, but you will still need to specify the default\ndatabase::\n\n from dongo import connect\n\n # For the mydatabase named database on localhost\n connect('mydatabase')\n\n # For your mongodb in the private network\n connect('mydatabase', host='192.168.1.200')\n\n # For multiple hosts in a replica set\n connect('mydatabase', hosts=['10.0.0.100', '10.0.0.101', '10.0.0.102:27018'], replica_set='myrepset0')\n\n # A uri can explicitly be specified as well\n connect('mydatabase', uri='mongodb://localhost:27017/')\n\n\nYou can separate collections into different databases, but those connections select\nthe default database that collections will use if database is unspecified.\n\nNext you will need to declare some sort of collection classes::\n\n from dongo import DongoCollection\n from datetime import datetime\n\n class MusicArtist(DongoCollection):\n # if a specific database other than the default is desired, uncomment this:\n # database = 'myotherdatabase'\n collection = 'music_artists'\n\n # That is all you need to query and read records from the collection \"music_artists\",\n # and the following would create new records and insert them and query for them.\n\n queen = MusicArtist({\n 'name': 'queen',\n 'lead': 'freddie',\n 'songs': ['we are the champions', 'we will rock you'],\n 'fans': ['jack', 'jill'],\n 'nested': {\n 'field1': 1,\n 'field2': 2,\n },\n })\n # insert must be called manually\n queen.insert()\n\n # you can use keywords and auto-insert with the \"new\" classmethod.\n queen_stoneage = MusicArtist.new(\n name='queens of the stone age',\n lead='josh',\n songs=['go with the flow', 'little sister'],\n start=datetime(year=1996, month=1, day=1),\n fans=['jack'],\n nested={\n 'field1': 1,\n 'field2': 222,\n },\n )\n\n # queries are simple\n for ma in MusicArtist.filter(fans='jack'):\n print('jack likes ' + ma['name'])\n\n # you can even do regex queries and bulk updates\n MusicArtist.filter(name__regex='^queen').update(new_field='this is a new field')\n\n # There are many operators, like __gt, __gte, __lt, __lte, __in, __nin, all corresponding to mongo's\n # operators like $gt.\n\n # you can do set logic as well with operators: |, &, ~\n # for example less than comparisons and checking field existence:\n for ma in (MusicArtist.filter(start__lt=datetime(2000, 1, 1)) | MusicArtist.filter(start__exists=0)):\n print('either this music artist started before the year 2000 or their startdate is unknown: ' + ma['name'])\n\n # And you can query inside nested dictionaries\n\n for ma in MusicArtist.filter(nested__field1=1):\n print(ma)\n\n # updating the database or fetching fields is as easy as dictionary access\n ma = MusicArtist.filter(name='queen').first()\n ma['new_field'] = 'new_value'\n print(ma['name'])\n ma.set(new_field_2='a', new_field_3='b', new_field_4={'foo': 'bar'})\n ma['nested.field1'] = 'new value in nested field'\n ma.set(nested__field1='reset that nested field to this value')\n\n\nYou will likely want methods associated with records, and to do that you just extend your\nclass definition::\n\n class Person(DongoCollection):\n collection = 'persons'\n\n def print_name(self):\n print(self.get('name', 'unknown'))\n\n def serialize(self):\n return {\n 'name': self.get('name'),\n 'age': self.get('age', 0),\n 'birthday': self.get('start', datetime.min).isoformat(),\n 'favorite_color': self.get('color'),\n }\n\n def change_color(self, new_color):\n # updates record in database as well\n self['color'] = new_color\n\n @classmethod\n def start_new_year(cls):\n # add 1 to all age values for every record with a field \"age\"\n cls.filter(age__exists=1).inc(age=1)\n # kill off those 110 and older\n cls.filter(age__gte=110).delete()\n\n @classmethod\n def startswith(cls, prefix):\n # find all persons with a name that starts with ``prefix``\n regex = '^{}'.format(prefix)\n return cls.filter(name__regex=regex)\n\n @classmethod\n def endswith(cls, suffix):\n # find all persons with a name that ends with ``suffix``\n regex = '{}$'.format(suffix)\n return cls.filter(name__regex=regex)\n\n @classmethod\n def first_10(cls):\n return cls.filter().iter(limit=10, sort='name')\n\n @classmethod\n def sort_by_oldest_first_then_alphabetically(cls):\n return cls.filter().iter(sort=[('age', -1), ('name', 1)])\n\n\n\nRelease Notes\n-------------\n\n:0.4.0:\n Added DongoBulk functionality, with lazy and bulk operations.\n:0.3.0:\n Added Dongo references feature, with instance.ref() and deref\n:0.2.3:\n Removed unnecessary dependency\n:0.2.2:\n Released alpha with python 2.7 and 3.x compatibility\n:0.2.1:\n Released alpha with python 3.x compatibility", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/johannestaas/dongo", "keywords": "", "license": "LGPLv3+", "maintainer": "", "maintainer_email": "", "name": "dongo", "package_url": "https://pypi.org/project/dongo/", "platform": "", "project_url": "https://pypi.org/project/dongo/", "project_urls": { "Homepage": "https://github.com/johannestaas/dongo" }, "release_url": "https://pypi.org/project/dongo/0.4.0/", "requires_dist": null, "requires_python": "", "summary": "A Django-ORM inspired Mongo ODM.", "version": "0.4.0" }, "last_serial": 3856361, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "3612e78f6024b20a4368fc5389d764d6", "sha256": "8a9ab124096f8c21ee9288c9e0baa5769c1a5c0ae9ec0467a315a9a2beccd1b0" }, "downloads": -1, "filename": "dongo-0.2.0.tar.gz", "has_sig": false, "md5_digest": "3612e78f6024b20a4368fc5389d764d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16251, "upload_time": "2018-04-29T02:34:49", "url": "https://files.pythonhosted.org/packages/43/4b/c3cb03cf42d40c5be39ed20094b855d7fa8cbc0c3f3ff85796bf8df4f52f/dongo-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "e7b368ab611738748e9b034754766983", "sha256": "bcd5c9f2bdade0aaa4c0454283fab61a8868c298128dc8fb9adfddb1a88d6e73" }, "downloads": -1, "filename": "dongo-0.2.1.tar.gz", "has_sig": false, "md5_digest": "e7b368ab611738748e9b034754766983", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16239, "upload_time": "2018-04-29T02:36:56", "url": "https://files.pythonhosted.org/packages/94/1d/e06962d17542e86c77c05fa0387f3a5d4ddfeabec1f68907f7356758b6a0/dongo-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "51b2fa47213dfda01d58cecad42d8e53", "sha256": "dd1be0da3e379b0aa62583144f181b32b2323ef5e08e11b3a05b8ea638182a4b" }, "downloads": -1, "filename": "dongo-0.2.2.tar.gz", "has_sig": false, "md5_digest": "51b2fa47213dfda01d58cecad42d8e53", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16392, "upload_time": "2018-04-29T07:52:00", "url": "https://files.pythonhosted.org/packages/37/dc/98c7c6c81b9941728732554654ac9fe79df6998bb581df9626bb035804d9/dongo-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "505260f033f1e62fb2cc43bae6bae64a", "sha256": "96754f1b5480f394eaa5f135a7d69152397b6e4fa7e5320af5628af4fecabc49" }, "downloads": -1, "filename": "dongo-0.2.3.tar.gz", "has_sig": false, "md5_digest": "505260f033f1e62fb2cc43bae6bae64a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16430, "upload_time": "2018-04-29T07:58:15", "url": "https://files.pythonhosted.org/packages/ec/a2/5f5fd600f5bd2a830178168e1e26e2ad93fa6f14f0e231df7e49875b115e/dongo-0.2.3.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "70f235d32df92d7750225b572db1726e", "sha256": "2a91f8a872665944ce8913d700747306972d689f417cd724faa8b298b2e00c08" }, "downloads": -1, "filename": "dongo-0.3.0.tar.gz", "has_sig": false, "md5_digest": "70f235d32df92d7750225b572db1726e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17201, "upload_time": "2018-05-04T09:53:10", "url": "https://files.pythonhosted.org/packages/d4/80/f5499b2c0d16ef10e12d5ee8fbf01990454326c33cca191aa0617456a8ba/dongo-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "3ead92bb39763050f4960aee273a5d84", "sha256": "83a08244ea9ff65f7fb8faa33bd9afc84c4ceb12a69f99c6f44250935423deaa" }, "downloads": -1, "filename": "dongo-0.4.0.tar.gz", "has_sig": false, "md5_digest": "3ead92bb39763050f4960aee273a5d84", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19693, "upload_time": "2018-05-12T09:37:20", "url": "https://files.pythonhosted.org/packages/e3/16/5a56df7eb25f7a1e79c554bf8c3b58e4ee039ef83881f95d3bbaa19041e6/dongo-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3ead92bb39763050f4960aee273a5d84", "sha256": "83a08244ea9ff65f7fb8faa33bd9afc84c4ceb12a69f99c6f44250935423deaa" }, "downloads": -1, "filename": "dongo-0.4.0.tar.gz", "has_sig": false, "md5_digest": "3ead92bb39763050f4960aee273a5d84", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19693, "upload_time": "2018-05-12T09:37:20", "url": "https://files.pythonhosted.org/packages/e3/16/5a56df7eb25f7a1e79c554bf8c3b58e4ee039ef83881f95d3bbaa19041e6/dongo-0.4.0.tar.gz" } ] }