{"id":22030874,"url":"https://github.com/python-trio/triopg","last_synced_at":"2025-05-07T12:13:16.971Z","repository":{"id":54228244,"uuid":"142667333","full_name":"python-trio/triopg","owner":"python-trio","description":"PostgreSQL client for Trio based on asyncpg","archived":false,"fork":false,"pushed_at":"2024-02-01T19:57:06.000Z","size":130,"stargazers_count":44,"open_issues_count":5,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-27T03:31:50.189Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/python-trio.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":"python-trio","open_collective":"python-trio"}},"created_at":"2018-07-28T10:10:01.000Z","updated_at":"2024-11-28T16:34:01.000Z","dependencies_parsed_at":"2022-08-13T09:40:35.787Z","dependency_job_id":"a019ff5e-f4b9-49cb-b7fe-bc19599ac973","html_url":"https://github.com/python-trio/triopg","commit_stats":{"total_commits":74,"total_committers":6,"mean_commits":"12.333333333333334","dds":0.3783783783783784,"last_synced_commit":"6575b2212aca2e86c5c91d9f39cf912b6dc40396"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftriopg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftriopg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftriopg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftriopg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-trio","download_url":"https://codeload.github.com/python-trio/triopg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252631626,"owners_count":21779467,"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-11-30T08:11:24.748Z","updated_at":"2025-05-07T12:13:16.938Z","avatar_url":"https://github.com/python-trio.png","language":"Python","funding_links":["https://github.com/sponsors/python-trio","https://opencollective.com/python-trio"],"categories":[],"sub_categories":[],"readme":".. image:: https://travis-ci.org/python-trio/triopg.svg?branch=master\n   :target: https://travis-ci.org/python-trio/triopg\n   :alt: Automated test status (Linux and MacOS)\n\n.. image:: https://ci.appveyor.com/api/projects/status/4t8ydnax9p6ehauj/branch/master?svg=true\n   :target: https://ci.appveyor.com/project/touilleMan/triopg/history\n   :alt: Automated test status (Windows)\n\n.. image:: https://codecov.io/gh/python-trio/triopg/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/python-trio/triopg\n   :alt: Test coverage\n\ntriopg\n======\n\nWARNING: this project is not actively maintained\n================================================\n\nWelcome to `triopg \u003chttps://github.com/python-trio/triopg\u003e`__!\n\nPostgreSQL client for `Trio \u003chttps://trio.readthedocs.io/\u003e`__ based on\n`asyncpg \u003chttps://magicstack.github.io/asyncpg/\u003e`__.\n\nLicense: Your choice of MIT or Apache License 2.0\n\nQuick example:\n\n.. code-block:: python\n\n    import trio_asyncio\n    import triopg\n\n\n    async def main():\n        async with triopg.connect() as conn:\n\n            await conn.execute(\n                \"\"\"\n                DROP TABLE IF EXISTS users;\n                CREATE TABLE IF NOT EXISTS users (\n                    _id SERIAL PRIMARY KEY,\n                    user_id VARCHAR(32) UNIQUE\n                )\"\"\"\n            )\n\n            async with conn.transaction():\n                await conn.execute(\"INSERT INTO users (user_id) VALUES (1)\")\n                await conn.execute(\"INSERT INTO users (user_id) VALUES (2)\")\n                await conn.execute(\"INSERT INTO users (user_id) VALUES (3)\")\n\n            print(await conn.fetch(\"SELECT * FROM users\"))\n\n\n    trio_asyncio.run(main)\n\nAPI basics\n----------\n\n``triopg`` is a thin Trio-compatible wrapper around ``asyncpg``. The API is the same,\nwith one exception - ``triopg`` does not support manual resource management.\nIn ``asyncpg`` you can manage pools, connections and transactions manually:\n\n.. code-block:: python\n\n    conn = await asyncpg.connect()\n    tr = conn.transaction()\n    # ..\n    tr.commit()\n    conn.close()\n\nWhile in ``triopg`` you can *only* use ``async with`` blocks:\n\n.. code-block:: python\n\n    async with triopg.connect() as conn:\n        async with conn.transaction():\n            # ...\n\nOtherwise you can follow ``asyncpg``\n`tutorial \u003chttps://magicstack.github.io/asyncpg/current/usage.html\u003e`__ and\n`reference \u003chttps://magicstack.github.io/asyncpg/current/api/\u003e`__.\nEverything should work the same way. Please\n`file an issue \u003chttps://github.com/python-trio/triopg/issues/new\u003e`__ if it doesn't.\n\nHelpers\n-------\n\nIn addition to ``asyncpg``-compatible API, ``triopg`` provides Trio-style\n``.listen()`` helper for the eponymous\n`Postgres statement \u003chttps://www.postgresql.org/docs/current/sql-listen.html\u003e`__:\n\n.. code-block:: python\n\n    async with conn.listen('some.channel', max_buffer_size=1) as notifications:\n        async for notification in notifications:\n            if notification != triopg.NOTIFY_OVERFLOW:\n                print('Notification received:', notification)\n\n``max_buffer_size`` is the amount of notifications you are willing to queue in memory.\n\nIf you **don't** want to think about buffering, set the buffer size to ``math.inf``\nand everything will just work in regular non-pathological situations.\n\nOtherwise, you can set a finite buffer. In this case you should handle\n``triopg.NOTIFY_OVERFLOW`` marker and react according to your use case.\nFor example, you could re-scan the tables, like you would do at startup.\nOr could you simply ignore the marker if you are only interested in the\nnewest notifications.\n\nFor detailed discussion on buffering, see Trio manual,\n`\"Buffering in channels\" \u003chttps://trio.readthedocs.io/en/stable/reference-core.html#buffering-in-channels\u003e`__\nsection.\n\n**Note:** we can't politely ask Postgres to slow down: ``LISTEN`` backpressure is\n`not supported by asyncpg \u003chttps://github.com/MagicStack/asyncpg/issues/463\u003e`__.\nThere's also an inherent challenge with Postgres. Postgres (like most\nbroadcast systems) doesn't really have a good way to communicate backpressure\nfurther upstream to the clients that are calling ``NOTIFY``.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Ftriopg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-trio%2Ftriopg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Ftriopg/lists"}