{ "info": { "author": "UberVU", "author_email": "development@ubervu.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Database", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "MongoPool\n=========\n\n*All your mongos in one place*\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n- `Description`_\n- `Install`_\n- `Usage`_\n- `Basic Example`_\n- `Multiple databases on the same cluster`_\n- `Dynamic paths`_\n- `Connecting to a replicaSet`_\n- `Setting a timeout`_\n- `Custom connection classes support`_\n- `Setting it up`_\n\n\nDescription\n-----------\n\nMongoPool is the tool that manages your connections to different\nclusters, maps databases to clients and allows you to work only with\ndatabase names without worrying about creating and managing connections.\n\nYou will never have to create a MongoClient everywhere you want to\naccess a database again which enables you to write beautiful and\nmaintainable code. Using MongoPool, you will keep connection regarding\ninformation in a single place and allows you to easily modify it when\nneeded.\n\nAt UberVU, we are confidently using it to manage over 25 mongo instances\nto provide quality services to our customers. ## Install\n\nInstall\n-------\n\nPyPi\n----\n\n.. code:: bash\n\n $ sudo pip install mongopool\n\nManual\n------\n\n.. code:: bash\n\n $ git clone https://github.com/uberVU/mongopool\n $ cd mongopool\n $ sudo python setup.py install\n\nUsage\n~~~~~\n\nBasic example\n-------------\n\nAll you have to do in order to get started is to build a list of\ndictionaries which contains the necessary information to connect to the\nclusters, instantiate MongoPool and access databases through dot\nnotation.\n\n.. code:: python\n\n >>> config = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath':'blogs'}}, \n ... {'cluster2': {'host': '127.0.0.1', 'port': 27018, 'dbpath': 'posts'}}] \n >>> mongopool = MongoPool(config)\n >>> mongopool.blogs\n Database(MongoClient('127.0.0.1', 27017), u'blogs')\n >>> mongopool.posts\n Database(MongoClient('127.0.0.1', 27018), u'posts')\n\nMultiple databases on the same cluster\n--------------------------------------\n\nBut what if you want to work with multiple databases on the same\ncluster? You can specify the dbpath as an array containing the database\nnames as in the following example:\n\n.. code:: python\n\n >>> config = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': ['blogs', 'posts']}}] \n >>> mongopool = MongoPool(config)\n >>> mongopool.blogs\n Database(MongoClient('127.0.0.1', 27017), u'blogs')\n >>> mongopool.posts\n Database(MongoClient('127.0.0.1', 27017), u'posts')``\n\nDynamic paths\n-------------\n\nYou might have databases created automatically, following a certain\nnaming pattern. In this case, it would be impossible to add all\ndatabases on a cluster in dbpath. For this reason, you can pass it as a\nregexp pattern. Let's say that you save the comments in a separate\ndatabase for each month, named comments\\_monthyear:\n\n.. code:: python\n\n >>> config = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': 'comments_\\d*'}}] \n >>> mongopool = MongoPool(config)\n >>> mongopool.comments_012014\n Database(MongoClient('127.0.0.1', 27017), u'comments_012014')\n >>> mongopool.comments_032014\n Database(MongoClient('127.0.0.1', 27017), u'comments_032014')``\n\n**Caution**: This is a strong feature, but it should be used carefully.\nDbpaths will be matched in the order you put them in the configurations\nlist, so make sure you order them from the most particular to the most\ngeneral in order to avoid creating incorrect mappings and connect to the\nwrong cluster.\n\nWrong\n^^^^^\n\n.. code:: python\n\n config = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': '.*'}}, \n {'cluster2': {'host': '127.0.0.1', 'port': 27017, 'dbpath': ['blogs', 'comments'}}]\n\nCorrect\n^^^^^^^\n\n.. code:: python\n\n config = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': ['blogs', 'comments'}},\n {'cluster2': {'host': '127.0.0.1', 'port': 27017, 'dbpath': '.*'}}]\n\nConnecting to a replicaSet\n--------------------------\n\nMongoPool also manages connections to ReplicaSets. All you have to do is to add the name of the replica set in the configuration. Also, if you want a read\\_preference different from PRIMARY, you can specify it in the config.\n\n.. code:: python\n\n >>> config = [{'cluster1': {'host': '127.0.0.1', 'port': 27018, 'replicaSet': 'rset0', \n ...'read_preference': 'secondary','dbpath': 'blogs'}}]\n >>> mongopool = MongoPool(config)\n >>> mongopool.blogs Database(MongoReplicaSetClient([u'127.0.0.1:27019', u'127.0.0.1:27020', u'127.0.0.1:27018']), u'blogs')\n\nSetting a timeout\n-----------------\nBy default, MongoClient and MongoReplicaSetClient do not have a timeout set, though sometimes it is handy. To set a timeout for you connection you can either pass it as a second argument while instantiating MongoPool or use the set\\_timeout method which will\nrecreate all connections with the new timeout and create all new\nconnections with the new value.\n\n.. code:: python\n\n mongopool = MongoPool(config, network_timeout=2)\n ...\n mongopool.set_timeout(network_timeout=5)\n\nCustom connection classes support\n---------------------------------\n\nIf you want to use your custom connection classes instead of MongoClient and MongoReplicaSetClient, you can do this by passing 2 optional arguments: connection\\_class and rset\\_connection\\_class.\n\n.. code:: python\n\n mongopool = MongoPool(config, connection_class=MyClass, rset_connection_class=MyOther(Class)\n\nSetting it up\n~~~~~~~~~~~~~\n\nAlong with the project we provide a sample config file to easily get started. In order to work with it, you have to launch multiple mongod instances on different ports. For this purpose, you can run the **start\\_instances.sh** script. If you don't wish to open many mongod instances, you can change all port values in the config file to 27017 and delete **label3** entry which uses a replicaSet.\n\n.. code:: bash\n\n # make sure that you are in the mongopool main directory\n $ cd mongopool\n # run the provided script or modify sample_config.yml file\n $ ./start_instances.sh $ python\n\nAnd then run the following commands:\n\n.. code:: python\n\n python import os import yaml\n from mongopool import MongoPool\n\n filename = os.path.join(os.getcwd(), 'sample\\_config.yml')\n options = yaml.load(open(filename))\n config = options['mongopool']\n pool = MongoPool(config)\n\nNow you should have a working mongopool instance which you can play with. When you are done, run:\n\n.. code:: bash\n\n $ ./clean\\_instances.sh\n\nThis will ensure that all created databases are deleted and all mongod instances are shutdown.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/ubervu/mongopool/", "keywords": null, "license": "Apache Software License", "maintainer": null, "maintainer_email": null, "name": "mongopool", "package_url": "https://pypi.org/project/mongopool/", "platform": "any", "project_url": "https://pypi.org/project/mongopool/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/ubervu/mongopool/" }, "release_url": "https://pypi.org/project/mongopool/0.2/", "requires_dist": null, "requires_python": null, "summary": "The tool that keeps all your mongos in one place", "version": "0.2" }, "last_serial": 1168884, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "265c74e25ecbb4f503d2b95fdc9cf3f1", "sha256": "2e12f290d1cf32ac15d35c76d71589b386b53cd758f36f8f14668729fdf0d63c" }, "downloads": -1, "filename": "mongopool-0.1.tar.gz", "has_sig": false, "md5_digest": "265c74e25ecbb4f503d2b95fdc9cf3f1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11496, "upload_time": "2014-07-09T11:23:56", "url": "https://files.pythonhosted.org/packages/18/e1/ab04ab6e546adef5e8bc3c9eb1683a349844af7b9845735cc0fda5770069/mongopool-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "7e688c686b047b3f99f2beaa78c5ebb2", "sha256": "77f1943d8fd53239db3da9aaaf59a16d23678b7c0c83b619aea62d708c720cb4" }, "downloads": -1, "filename": "mongopool-0.2.tar.gz", "has_sig": false, "md5_digest": "7e688c686b047b3f99f2beaa78c5ebb2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11663, "upload_time": "2014-07-25T08:01:41", "url": "https://files.pythonhosted.org/packages/fb/d6/4ad67112b3f236bb5238c9bc86768f6c7958a810412f4d217499514a00bb/mongopool-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7e688c686b047b3f99f2beaa78c5ebb2", "sha256": "77f1943d8fd53239db3da9aaaf59a16d23678b7c0c83b619aea62d708c720cb4" }, "downloads": -1, "filename": "mongopool-0.2.tar.gz", "has_sig": false, "md5_digest": "7e688c686b047b3f99f2beaa78c5ebb2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11663, "upload_time": "2014-07-25T08:01:41", "url": "https://files.pythonhosted.org/packages/fb/d6/4ad67112b3f236bb5238c9bc86768f6c7958a810412f4d217499514a00bb/mongopool-0.2.tar.gz" } ] }