{ "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": "![image](https://cloud.githubusercontent.com/assets/250750/5323889/4f7cf454-7cdd-11e4-81f0-7e3eee8f9556.png)\n\n### _All your mongos in one place_ \n[![Build Status](https://travis-ci.org/uberVU/mongo-pool.svg?branch=master)](https://travis-ci.org/uberVU/mongo-pool)\n\n- [Description](#description)\n- [Install](#install)\n- [Usage](#usage)\n - [Basic Example](#basic-example)\n - [Multiple databases on the same cluster](#multiple-databases-on-the-same-cluster)\n - [Dynamic paths](#dynamic-paths)\n - [Setting a timeout](#setting-a-timeout)\n - [Custom connection classes support](#custom-connection-classes-support)\n- [Setting it up](#setting-it-up)\n\n##Description\nMongoPool is the tool that manages your connections to different clusters, maps databases to clients and allows you to work only with database names without worrying about creating and managing connections.\n\nYou will never have to create a MongoClient everywhere you want to access a database again which enables you to write beautiful and maintainable code. Using MongoPool, you will keep connection regarding information in a single place and allows you to easily modify it when needed.\n\nAt UberVU, we are confidently using it to manage over 25 mongo instances to provide quality services to our customers.\n## Install\n\n### PyPi\n```bash\n$ sudo pip install mongopool\n```\n### Manual\n```bash\n$ git clone https://github.com/uberVU/mongo-pool\n$ cd mongo-pool\n$ sudo python setup.py install\n```\n\n## Usage\n\n#### Basic example\nAll you have to do in order to get started is to build a list of dictionaries which contains the necessary information to connect to the clusters, instantiate MongoPool and access databases through dot notation.\n```python\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\nDatabase(MongoClient('127.0.0.1', 27017), u'blogs')\n>>> mongopool.posts\nDatabase(MongoClient('127.0.0.1', 27018), u'posts')\n```\n\n#### Multiple databases on the same cluster\nBut what if you want to work with multiple databases on the same cluster?\nYou can specify the dbpath as an array containing the database names as in the following example:\n```python\n>>> config = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': ['blogs', 'posts']}}]\n>>> mongopool = MongoPool(config)\n>>> mongopool.blogs\nDatabase(MongoClient('127.0.0.1', 27017), u'blogs')\n>>> mongopool.posts\nDatabase(MongoClient('127.0.0.1', 27017), u'posts')\n```\n\n#### Dynamic paths\nYou might have databases created automatically, following a certain naming pattern. In this case, it would be impossible to add all databases on a cluster in dbpath. For this reason, you can pass it as a regexp pattern. Let's say that you save the comments in a separate database for each month, named comments_monthyear:\n```python\n>>> config = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': 'comments_\\d*'}}]\n>>> mongopool = MongoPool(config)\n>>> mongopool.comments_012014\nDatabase(MongoClient('127.0.0.1', 27017), u'comments_012014')\n>>> mongopool.comments_032014\nDatabase(MongoClient('127.0.0.1', 27017), u'comments_032014')\n```\n\n**Caution**: This is a strong feature, but it should be used carefully. Dbpaths will be matched in the order you put them in the configurations list, so make sure you order them from the most particular to the most general in order to avoid creating incorrect mappings and connect to the wrong cluster.\n\n**Wrong**\n```python\nconfig = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': '.*'}},\n {'cluster2': {'host': '127.0.0.1', 'port': 27017, 'dbpath': ['blogs', 'comments'}}]\n```\n**Correct**\n```python\nconfig = [{'cluster1': {'host': '127.0.0.1', 'port': 27017, 'dbpath': ['blogs', 'comments'}},\n {'cluster2': {'host': '127.0.0.1', 'port': 27017, 'dbpath': '.*'}}]\n```\n#### Setting a timeout\nBy default, MongoClient does 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 recreate all connections with the new timeout and create all new connections with the new value.\n```python\nmongopool = MongoPool(config, network_timeout=2)\n...\nmongopool.set_timeout(network_timeout=5)\n```\n\n#### Custom connection classes support\nIf you want to use your custom connection classes instead of MongoClient you can do this by passing the optional argument: connection_class.\n```python\nmongopool = MongoPool(config, connection_class=MyClass)\n```\n## Setting it up\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```bash\n# make sure that you are in the mongopool main directory\n$ cd mongo-pool\n# run the provided script or modify sample_config.yml file\n$ ./start_instances.sh\n$ python\n```\nAnd then run the following commands:\n```python\nimport os\nimport yaml\nfrom mongo-pool import MongoPool\n\nfilename = os.path.join(os.getcwd(), 'sample_config.yml')\noptions = yaml.load(open(filename))\nconfig = options['mongopool']\npool = MongoPool(config)\n```\nNow you should have a working mongopool instance which you can play with.\nWhen you are done, run:\n```bash\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/mongo-pool/", "keywords": null, "license": "Apache Software License", "maintainer": null, "maintainer_email": null, "name": "mongo-pool", "package_url": "https://pypi.org/project/mongo-pool/", "platform": "any", "project_url": "https://pypi.org/project/mongo-pool/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/ubervu/mongo-pool/" }, "release_url": "https://pypi.org/project/mongo-pool/0.4.2/", "requires_dist": null, "requires_python": null, "summary": "The tool that keeps all your mongos in one place", "version": "0.4.2" }, "last_serial": 2037562, "releases": { "0.3": [ { "comment_text": "", "digests": { "md5": "4ef944ef7922eecb4c45661c12c971d5", "sha256": "5ddf6f0bcdee2e4b86f02218df5052ce03e5abaaed44033f3253c2a6432fe146" }, "downloads": -1, "filename": "mongo-pool-0.3.tar.gz", "has_sig": false, "md5_digest": "4ef944ef7922eecb4c45661c12c971d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11763, "upload_time": "2014-08-05T08:21:41", "url": "https://files.pythonhosted.org/packages/5a/1c/5847ccf26ada07b6b78eb37b5b3d09823266c93c9a0a336d3d081f8958ec/mongo-pool-0.3.tar.gz" } ], "0.4": [], "0.4.1": [ { "comment_text": "", "digests": { "md5": "98f0a26e78513e2c987ab79e727eb34c", "sha256": "94a851964c17a9dec9042b3a8c7f1cd98e6263e5505f398a21a65614b4ce3f77" }, "downloads": -1, "filename": "mongo-pool-0.4.1.tar.gz", "has_sig": false, "md5_digest": "98f0a26e78513e2c987ab79e727eb34c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11247, "upload_time": "2015-07-13T14:22:40", "url": "https://files.pythonhosted.org/packages/2f/61/98d8bd9f071a66a89fcb4e50e0dec8f94ced364f87d35f66c0e02f23484f/mongo-pool-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "9dbc96ed291d1a4a8d3c645eba590856", "sha256": "d522f9214faa395bbfa2c039731e8d44ec741a8cc7e0ff6b92ea9242ed60fda9" }, "downloads": -1, "filename": "mongo-pool-0.4.2.tar.gz", "has_sig": false, "md5_digest": "9dbc96ed291d1a4a8d3c645eba590856", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11281, "upload_time": "2016-03-31T08:20:35", "url": "https://files.pythonhosted.org/packages/7c/2c/5e235fd447bb0f52620e178831522fccf11cf229e1a75ed6edd243c5e798/mongo-pool-0.4.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9dbc96ed291d1a4a8d3c645eba590856", "sha256": "d522f9214faa395bbfa2c039731e8d44ec741a8cc7e0ff6b92ea9242ed60fda9" }, "downloads": -1, "filename": "mongo-pool-0.4.2.tar.gz", "has_sig": false, "md5_digest": "9dbc96ed291d1a4a8d3c645eba590856", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11281, "upload_time": "2016-03-31T08:20:35", "url": "https://files.pythonhosted.org/packages/7c/2c/5e235fd447bb0f52620e178831522fccf11cf229e1a75ed6edd243c5e798/mongo-pool-0.4.2.tar.gz" } ] }