{ "info": { "author": "Ted Kaemming, Disqus", "author_email": "ted@disqus.com", "bugtrack_url": null, "classifiers": [], "description": "psycopg2-managed-connection\n###########################\n\nThis package includes a managed connection for psycopg2_ that provides\nthread-safe exclusive access to an underlying ``psycopg2.connection`` object.\n\nThis allows many threads to share the same connection instance (avoiding the\nTCP and process startup cost associated with establishing a new PostgreSQL\nconnection) and ensures that threads do not release the connection with a\ntransaction still in progress -- either due to developer error, or an unhandled\nexception while a thread is interacting with the database.\n\n``ManagedConnection`` also will ensure that a connection that is closed upon\nentering the managed context will be opened.\n\nUsage\n=====\n\nCreating a Managed Connection\n-----------------------------\n\n.. code:: python\n\n >>> from pgmanagedconnection import ManagedConnection\n >>>\n >>> dsn = 'postgres:///postgres' # a libpq connection string\n >>> manager = ManagedConnection(dsn)\n >>> manager\n \n\nMaking Queries\n--------------\n\n.. code:: python\n\n >>> with manager() as connection:\n ... cursor = connection.cursor()\n ... cursor.execute('SELECT 1')\n ... cursor.fetchone()\n ... connection.commit()\n (1,)\n\nDealing with Uncommitted Transactions\n-------------------------------------\n\nLeaving a transaction open when exiting the context manager will lead to a\n``RuntimeError``. This also results in any open transactions implicitly being\nrolled back.\n\n.. code:: python\n\n >>> with manager() as connection:\n ... cursor = connection.cursor()\n ... cursor.execute('SELECT 1')\n Traceback (most recent call last):\n ...\n RuntimeError: Did not commit or rollback open transaction before releasing connection.\n\nDealing with Errors\n-------------------\n\nThe currently open transaction will be rolled back if an unhandled exception is\nencountered.\n\n.. code:: python\n\n >>> import psycopg2\n >>> with manager() as connection:\n ... cursor = connection.cursor()\n ... cursor.execute('SELECT 1')\n ... assert manager.status is psycopg2.extensions.TRANSACTION_STATUS_INTRANS\n ... raise NotImplementedError()\n Traceback (most recent call last):\n ...\n NotImplementedError\n >>> manager.status is psycopg2.extensions.TRANSACTION_STATUS_IDLE\n True\n\nDevelopment\n===========\n\nTesting\n-------\n\nThe test suite can be run with ``make test``.\n\nIt assumes a running and accessible PostgreSQL server. The connection details\nare deferred to the underlying ``libpq`` implementation, and default values can\nbe specified using `libpq environment variables`_.\n\ntox_ is also supported as a test runner (if installed.)\n\nTesting with Docker\n~~~~~~~~~~~~~~~~~~~\n\n.. code:: bash\n\n $ export PGPORT=5432\n $ docker run -dp $PGPORT:5432 postgres\n $ PGUSER=postgres make test\n\nIf using boot2docker_, the ``PGHOST`` environment variable will also need to be\nset to the virtual machine IP address.\n\n.. code:: bash\n\n $ PGUSER=postgres PGHOST=$(boot2docker ip) make test\n\n\n.. _boot2docker: https://github.com/boot2docker/boot2docker\n.. _psycopg2: https://pypi.python.org/pypi/psycopg2/\n.. _`libpq environment variables`: http://www.postgresql.org/docs/9.3/static/libpq-envars.html\n.. _tox: https://pypi.python.org/pypi/tox\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": null, "license": "Apache License 2.0", "maintainer": null, "maintainer_email": null, "name": "psycopg2-managed-connection", "package_url": "https://pypi.org/project/psycopg2-managed-connection/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/psycopg2-managed-connection/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/psycopg2-managed-connection/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Thread-safe connection manager for psycopg2 connections.", "version": "1.0.0" }, "last_serial": 2243438, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "8874d826b1fe51981829e997ff7fa550", "sha256": "5159e4ffaf9bb102c5d7d0e2a7bfff8e7e422aa9a06c282558db5b456d6a1215" }, "downloads": -1, "filename": "psycopg2-managed-connection-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8874d826b1fe51981829e997ff7fa550", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3426, "upload_time": "2015-07-02T23:14:20", "url": "https://files.pythonhosted.org/packages/51/7e/23a9b380daeda1ebc1fe127cc4d1fe49eba87aaae853e904f05ede820972/psycopg2-managed-connection-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8874d826b1fe51981829e997ff7fa550", "sha256": "5159e4ffaf9bb102c5d7d0e2a7bfff8e7e422aa9a06c282558db5b456d6a1215" }, "downloads": -1, "filename": "psycopg2-managed-connection-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8874d826b1fe51981829e997ff7fa550", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3426, "upload_time": "2015-07-02T23:14:20", "url": "https://files.pythonhosted.org/packages/51/7e/23a9b380daeda1ebc1fe127cc4d1fe49eba87aaae853e904f05ede820972/psycopg2-managed-connection-1.0.0.tar.gz" } ] }