{"id":13708327,"url":"https://github.com/psycopg/psycogreen","last_synced_at":"2025-04-06T06:09:30.913Z","repository":{"id":56159693,"uuid":"242395828","full_name":"psycopg/psycogreen","owner":"psycopg","description":"Integration of psycopg2 with coroutine libraries","archived":false,"fork":false,"pushed_at":"2023-12-04T12:22:00.000Z","size":30,"stargazers_count":103,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T04:09:27.781Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/psycopg.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["dvarrazzo"],"custom":["https://www.paypal.me/dvarrazzo"]}},"created_at":"2020-02-22T19:01:29.000Z","updated_at":"2025-03-09T16:53:53.000Z","dependencies_parsed_at":"2024-06-18T19:44:53.569Z","dependency_job_id":"ac896e8a-dd0a-43cb-a2ff-31f1d5a65e95","html_url":"https://github.com/psycopg/psycogreen","commit_stats":{"total_commits":37,"total_committers":2,"mean_commits":18.5,"dds":"0.027027027027026973","last_synced_commit":"39a258cb4040b88b60a7600f6942e651a28db9a7"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psycopg%2Fpsycogreen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psycopg%2Fpsycogreen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psycopg%2Fpsycogreen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psycopg%2Fpsycogreen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/psycopg","download_url":"https://codeload.github.com/psycopg/psycogreen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441052,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T23:00:20.542Z","updated_at":"2025-04-06T06:09:30.888Z","avatar_url":"https://github.com/psycopg.png","language":"Python","funding_links":["https://github.com/sponsors/dvarrazzo","https://www.paypal.me/dvarrazzo"],"categories":["Database"],"sub_categories":["Tools"],"readme":"psycogreen -- psycopg2 integration with coroutine libraries\n===========================================================\n\nThe `psycogreen`_ package enables psycopg2 to work with coroutine libraries,\nusing asynchronous calls internally but offering a blocking interface so that\nregular code can run unmodified.\n\n`Psycopg`_ offers `coroutines support`__ since release 2.2. Because the main\nmodule is a C extension it cannot be monkey-patched to become\ncoroutine-friendly. Instead it exposes `a hook`__ that coroutine libraries can\nuse to install a function integrating with their event scheduler. Psycopg will\ncall the function whenever it executes a libpq call that may block.\n`psycogreen` is a collection of \"wait callbacks\" useful to integrate Psycopg\nwith different coroutine libraries.\n\n.. _psycogreen: https://github.com/psycopg/psycogreen\n.. _Psycopg: https://www.psycopg.org/docs/\n.. __: https://www.psycopg.org/docs/advanced.html#support-for-coroutine-libraries\n.. __: https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.set_wait_callback\n\n\nWhat about Psycopg 3?\n---------------------\n\nThe `Psycopg 3`_ module doesn't require psycogreen; psycogreen has no effect on\nPsycopg 3.\n\nIn Psycopg 3:\n\n- gevent `is supported`__ automatically from 3.1.14 on. Please avoid to use\n  older versions.\n- Eventlet is currently not supported, as the project doesn't seem very active\n  anymore. Support can be added if requested.\n- uWsgi is currently in maintenance mode, so Psycopg 3 support doesn't seem\n  necessary.\n\n.. _Psycopg 3: https://www.psycopg.org/psycopg3/docs/\n.. __: https://www.psycopg.org/psycopg3/docs/advanced/async.html#gevent-support\n\n\nInstallation\n------------\n\n``pip install psycogreen``\n\n\nModule ``psycogreen.eventlet``\n------------------------------\n\n`Eventlet`_ currently supports ```psycopg2` out-of-the-box and ``psycogreen``\nis not necessary. See `the documentation`__ for patching instruction.\n\n.. _Eventlet: https://eventlet.net/\n.. __: https://eventlet.net/doc/patching.html#monkeypatching-the-standard-library\n\nIf for any reason you want to avoid using Eventlet monkeypatching you can use\n``psycogreen.eventlet.patch_psycopg()``.\n\nFunction ``psycogreen.eventlet.patch_psycopg()``\n    Enable async processing in Psycopg integrated with the Eventlet events\n    loop.  It is performed by registering ``eventlet_wait_callback()`` as\n    psycopg2 wait callback.\n\nFunction ``psycogreen.eventlet.eventlet_wait_callback(conn)``\n    A wait callback integrating with Eventlet events loop.\n\nAn example script showing concurrent usage of ``psycopg2`` with ``urlopen()``\nwith Eventlet is available in |tests/test_eventlet.py|__.\n\n.. |tests/test_eventlet.py| replace:: ``tests/test_eventlet.py``\n.. __: https://github.com/psycopg/psycogreen/blob/master/tests/test_eventlet.py\n\n\nModule ``psycogreen.gevent``\n----------------------------\n\nIn order to use psycopg2 asynchronously with `gevent`_ you can use\n``psycogreen.gevent.patch_psycopg()``.\n\nFunction ``psycogreen.gevent.patch_psycopg()``\n    Enable async processing in Psycopg integrated with the gevent events\n    loop.  It is performed by registering ``gevent_wait_callback()`` as\n    psycopg2 wait callback.\n\nFunction ``psycogreen.gevent.gevent_wait_callback(conn)``\n    A wait callback integrating with gevent events loop.\n\nAn example script showing concurrent usage of ``psycopg2`` with ``urlopen()``\nwith gevent is available in |tests/test_gevent.py|__.\n\n.. _gevent: https://www.gevent.org/\n.. |tests/test_gevent.py| replace:: ``tests/test_gevent.py``\n.. __: https://github.com/psycopg/psycogreen/blob/master/tests/test_gevent.py\n\n\nuWSGI green threads\n-------------------\n\nRoberto De Ioris is writing uGreen__, a green thread implementation on top of\nthe `uWSGI async platform`__.\n\n.. __: https://projects.unbit.it/uwsgi/wiki/uGreen\n.. __: https://projects.unbit.it/uwsgi/\n\nHe has performed some tests using both `psycopg2 async support`__ and\n`psycopg2 green support`__ and has reported no problem in their stress tests\nwith both the async styles.\n\n.. __: https://projects.unbit.it/uwsgi/browser/tests/psycopg2_green.py\n.. __: https://projects.unbit.it/uwsgi/browser/tests/psycogreen_green.py\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsycopg%2Fpsycogreen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsycopg%2Fpsycogreen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsycopg%2Fpsycogreen/lists"}