{ "info": { "author": "Spencer Mitchell", "author_email": "", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "################\nFlask-CuttlePool\n################\n\nFlask-CuttlePool provides a convenient interface for using `Cuttle Pool\n`_ with Flask.\n\nHow-to Guide\n============\n\nIf you haven't read the `How-to Guide\n`_ for CuttlePool, you\nreally should before going any further.\n\n``FlaskCuttlePool`` objects accept the same arguments as ``CuttlePool``\nobjects, as well as a Flask ``app`` object. Assume we have the following\nimports and ``app`` object. ::\n\n import sqlite3\n\n from flask import Flask\n from flask_cuttlepool import FlaskCuttlePool\n\n\n app = Flask(__name__)\n\n\nThere are two ways to set up a pool object. On pool initialization ::\n\n pool = FlaskCuttlePool(sqlite3.connect, app=app, database='ricks_lab')\n\nor using ``init_app()`` explicitly ::\n\n pool = FlaskCuttlePool(sqlite3.connect)\n pool.init_app(app)\n\nAny configuration keys that start with ``CUTTLEPOOL_`` will be converted to a\nkey value pair. If the key already exists in the initial arguments passed to\nthe ``__init__()`` method, those will be superceded by the value on\n``app.config``. For example ::\n\n pool = FlaskCuttlePool(sqlite3.connect, database='ricks_lab')\n app.config['CUTTLEPOOL_DATABASE'] = 'citadel_of_ricks'\n pool.init_app(app)\n\nwill result in the connection pool associated with that ``app`` object\nconnecting to ``'citadel_of_ricks'`` instead of ``'ricks_lab'``. Every key\nvalue pair on ``app.config`` of the form ``app.config['CUTTLEPOOL_KEY'] =\nvalue`` is passed to the pool constructor as ``key=value`` where ``key`` is\nlowercase.\n\n``FlaskCuttlePool`` objects should also be provided with two callbacks. The\n``ping`` callback is used to check if a connection is still open. The\n``normalize_connection`` callback ensures each connection has the same state\nwhen it is retrieved from the pool. For more about these methods, see the\n`Cuttle Pool How-to Guide\n`_.\n\nContinuing with the above example, these callbacks could be implemented like\nthis::\n\n @pool.ping\n def ping(connection):\n try:\n rv = connection.execute('SELECT 1').fetchall()\n\t return (1,) in rv\n except sqlite3.Error:\n return False\n\n @pool.normalize_connection\n def normalize_connection(connection):\n connection.row_factory = None\n\nNow the pool can be used as normal. Any calls to ``get_connection()`` will\nreturn a connection in the same manner a ``CuttlePool`` object would.\n\nTo make things more convenient, the ``connection`` getter will store a\nconnection on the application context and reuse that connection whenever the\n``connection`` getter is called again. When the application context is torn\ndown, the connection will be returned to the pool. Therefore, there is no need\nto call ``close()`` on a connection retrieved from the ``connection`` getter,\nbut it's ok if ``close()`` is called. Connections retrieved with\n``get_connection()`` should be explicitly closed.\n\nThe convenience method ``cursor()`` will return a ``Cursor`` instance for the\nconnection stored on the application context.\n\nA full example looks like::\n\n import sqlite3\n\n from flask import Flask\n from flask_cuttlepool import FlaskCuttlePool\n\n\n app = Flask(__name__)\n app.config['CUTTLEPOOL_DATABASE'] = ':memory:'\n\n pool = FlaskCuttlePool(sqlite3.connect)\n pool.init_app(app)\n\n @pool.ping\n def ping(connection):\n try:\n rv = connection.execute('SELECT 1').fetchall()\n\t return (1,) in rv\n except sqlite3.Error:\n return False\n\n @pool.normalize_connection\n def normalize_connection(connection):\n connection.row_factory = None\n\n with app.app_context():\n # Get a connection, store it on the application context and return to\n # user. This connection doesn't need to be explicitly closed.\n con = pool.connection\n # Subsequent calls to pool.connection will get the same connection from\n # the application context.\n con is pool.connection # True\n\n # Get a different connection\n con2 = pool.get_connection()\n con2 is con # False\n # This connection should be explicitly closed since it was retrieved by\n # get_connection().\n con2.close()\n\n # Get a cursor from the connection on the application context.\n cur = pool.cursor()\n cur.execute(SOME_SQL)\n cur.close()\n pool.connection.commit()\n\n # Now the application context has been torn down, so the connection has been\n # returned to the pool.\n pool.connection is None # True\n\nFAQ\n===\n\nThese questions are related to Flask-CuttlePool only, check the `FAQ\n`_ for CuttlePool if you don't\nfind your answers here.\n\nHow do I install it?\n--------------------\n\n``pip install flask-cuttlepool``\n\nWhat is an application contexts?\n--------------------------------\n\nThis is a Flask extension, so it is meant to be used in the context of a Flask\napplication. See `here `_ to\nlearn about Flask's application context.\n\nContributing\n------------\n\nIt's highly recommended to develop in a virtualenv.\n\nFork the repository.\n\nClone the repository::\n\n git clone https://github.com//flask-cuttlepool.git\n\nInstall the package in editable mode::\n\n cd flask-cuttlepool\n pip install -e .[dev]\n\nNow you're set. See the next section for running tests.\n\nRunning the tests\n-----------------\n\nTests can be run with the command ``pytest``.\n\nWhere can I get help?\n---------------------\n\nIf you haven't read the How-to guide above, please do that first. Otherwise,\ncheck the `issue tracker\n`_. Your issue may be\naddressed there and if it isn't please file an issue :)\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/smitchell556/flask-cuttlepool", "keywords": "", "license": "BSD 3-Clause", "maintainer": "", "maintainer_email": "", "name": "Flask-CuttlePool", "package_url": "https://pypi.org/project/Flask-CuttlePool/", "platform": "any", "project_url": "https://pypi.org/project/Flask-CuttlePool/", "project_urls": { "Homepage": "http://github.com/smitchell556/flask-cuttlepool" }, "release_url": "https://pypi.org/project/Flask-CuttlePool/0.2.0/", "requires_dist": [ "cuttlepool (>=0.6.0)", "flask", "pytest; extra == 'dev'" ], "requires_python": "", "summary": "A Flask extension for CuttlePool", "version": "0.2.0" }, "last_serial": 3536830, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "3f6b55eb0235e2f43aea38a02d17a835", "sha256": "e369305a9a092ad68572ef9db772b0025e2a654034696e6db716a3c3cf99475b" }, "downloads": -1, "filename": "Flask_CuttlePool-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3f6b55eb0235e2f43aea38a02d17a835", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6958, "upload_time": "2018-01-16T02:14:29", "url": "https://files.pythonhosted.org/packages/d4/09/ac771a7a0cd54d8d84e11c1be3495da287506b36d8988d2c9bce45c7af90/Flask_CuttlePool-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5ad1db5fd1d01e58e6f808e98620353f", "sha256": "b03204734f641f01b1a67b7bf943ad49a1265aad1be16350f88417db2e85f2a6" }, "downloads": -1, "filename": "Flask-CuttlePool-0.1.0.tar.gz", "has_sig": false, "md5_digest": "5ad1db5fd1d01e58e6f808e98620353f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4569, "upload_time": "2018-01-16T02:14:55", "url": "https://files.pythonhosted.org/packages/c3/fd/e92deb665f8e05e78e9f6b0cbbee521f9e0cb7ad32314d586ed6eb90b47c/Flask-CuttlePool-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "d376b260e8f4f3d0e160825b5f1b04f1", "sha256": "9515a029192790099a0ee4268783b739a7d8aa2edb952d5afb32f3309ff04275" }, "downloads": -1, "filename": "Flask_CuttlePool-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d376b260e8f4f3d0e160825b5f1b04f1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9072, "upload_time": "2018-01-31T00:49:51", "url": "https://files.pythonhosted.org/packages/ef/4e/14407dc2be9802484418ab4f0e7c4066ffdc12f3ad34cbc0895ccfba48df/Flask_CuttlePool-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72312737fe7c788930ebda0c7d2f813b", "sha256": "3bd2f8af0f3aeaf4b91b7ad16dcda83cea8fd97e6f14cc1108e91272c174cf00" }, "downloads": -1, "filename": "Flask-CuttlePool-0.2.0.tar.gz", "has_sig": false, "md5_digest": "72312737fe7c788930ebda0c7d2f813b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6233, "upload_time": "2018-01-31T00:49:52", "url": "https://files.pythonhosted.org/packages/a3/2d/2ae14e815039f0c45d7e8eb42641c109eb611f77669d6dee24fc636ff682/Flask-CuttlePool-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d376b260e8f4f3d0e160825b5f1b04f1", "sha256": "9515a029192790099a0ee4268783b739a7d8aa2edb952d5afb32f3309ff04275" }, "downloads": -1, "filename": "Flask_CuttlePool-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d376b260e8f4f3d0e160825b5f1b04f1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9072, "upload_time": "2018-01-31T00:49:51", "url": "https://files.pythonhosted.org/packages/ef/4e/14407dc2be9802484418ab4f0e7c4066ffdc12f3ad34cbc0895ccfba48df/Flask_CuttlePool-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72312737fe7c788930ebda0c7d2f813b", "sha256": "3bd2f8af0f3aeaf4b91b7ad16dcda83cea8fd97e6f14cc1108e91272c174cf00" }, "downloads": -1, "filename": "Flask-CuttlePool-0.2.0.tar.gz", "has_sig": false, "md5_digest": "72312737fe7c788930ebda0c7d2f813b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6233, "upload_time": "2018-01-31T00:49:52", "url": "https://files.pythonhosted.org/packages/a3/2d/2ae14e815039f0c45d7e8eb42641c109eb611f77669d6dee24fc636ff682/Flask-CuttlePool-0.2.0.tar.gz" } ] }