{"id":15783837,"url":"https://github.com/deepmancer/asyncpg-client","last_synced_at":"2025-04-01T16:30:41.298Z","repository":{"id":249620301,"uuid":"832018459","full_name":"deepmancer/asyncpg-client","owner":"deepmancer","description":"Asyncpg Client is a simple and easy-to-use module to interact with PostgreSQL databases","archived":false,"fork":false,"pushed_at":"2024-08-16T11:35:16.000Z","size":43,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-31T08:33:38.398Z","etag":null,"topics":["async","asynchronous","asyncio","asyncpg","database","postgres","postgresql","postgresql-database","pytho"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepmancer.png","metadata":{"files":{"readme":"README.md","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,"publiccode":null,"codemeta":null}},"created_at":"2024-07-22T07:32:53.000Z","updated_at":"2024-10-26T15:44:46.000Z","dependencies_parsed_at":"2024-07-30T20:47:20.056Z","dependency_job_id":"9ebc8b6b-2871-4e41-b3f5-249d0d898015","html_url":"https://github.com/deepmancer/asyncpg-client","commit_stats":{"total_commits":24,"total_committers":3,"mean_commits":8.0,"dds":"0.29166666666666663","last_synced_commit":"e2359777d103cf0db0565a1fe7e68f390c5414f8"},"previous_names":["alirezaheidari-cs/asyncpg_client","deepmancer/asyncpg-client","alirezaheidari-cs/asyncpg-client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fasyncpg-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fasyncpg-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fasyncpg-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fasyncpg-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepmancer","download_url":"https://codeload.github.com/deepmancer/asyncpg-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246620275,"owners_count":20806735,"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":["async","asynchronous","asyncio","asyncpg","database","postgres","postgresql","postgresql-database","pytho"],"created_at":"2024-10-04T20:01:13.257Z","updated_at":"2025-04-01T16:30:41.292Z","avatar_url":"https://github.com/deepmancer.png","language":"Python","readme":"# 📚 Async Postgres Client\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/PostgreSQL-4169E1.svg?style=for-the-badge\u0026logo=PostgreSQL\u0026logoColor=white\" alt=\"PostgreSQL\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/SQLAlchemy-D71F00.svg?style=for-the-badge\u0026logo=SQLAlchemy\u0026logoColor=white\" alt=\"SQLAlchemy\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Pydantic-E92063.svg?style=for-the-badge\u0026logo=Pydantic\u0026logoColor=white\" alt=\"Pydantic\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/PyPI-3775A9.svg?style=for-the-badge\u0026logo=PyPI\u0026logoColor=white\" alt=\"PyPI\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/python-3670A0?style=for-the-badge\u0026logo=python\u0026logoColor=ffdd54\" alt=\"Python\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=for-the-badge\" alt=\"License\"\u003e\n\u003c/p\u003e\n\n**`asyncpg-client`** is a powerful Python package designed for seamless asynchronous interactions with PostgreSQL, leveraging SQLAlchemy. It ensures efficient, thread-safe operations with its singleton-based connection pooling mechanism, making database management easier and faster.\n\n---\n\n| **Source Code** | **Website** |\n|:-----------------|:------------|\n| \u003ca href=\"https://github.com/deepmancer/asyncpg-client\" target=\"_blank\"\u003egithub.com/deepmancer/asyncpg-client\u003c/a\u003e | \u003ca href=\"https://deepmancer.github.io/asyncpg-client/\" target=\"_blank\"\u003edeepmancer.github.io/asyncpg-client\u003c/a\u003e |\n\n---\n\n## ✨ Features\n\n- ⚡ **Asynchronous Operations**: Asynchronous database connections using SQLAlchemy for high performance.\n- 🛠️ **Singleton Pattern**: Efficiently manage database connections using a singleton design.\n- 🔄 **Context Manager Support**: Simplify database session management with context managers.\n- 🔧 **Easy Configuration**: Configure your database effortlessly with `PostgresConfig`.\n\n## 📦 Installation\n\nGet started quickly by installing `asyncpg-client` with pip:\n\n```sh\npip install git+https://github.com/deepmancer/asyncpg-client.git\n```\n\n## 📝 Usage Guide\n\n### 🔧 Configuration\n\nStart by creating a configuration object with `PostgresConfig`:\n\n```python\nfrom asyncpg_client import PostgresConfig\n\nconfig = PostgresConfig(\n    host='localhost',\n    port=5432,\n    user='your_user',\n    password='your_password',\n    database='your_database',\n    url=None,  # Optional: Direct database URL\n    enable_db_echo_log=False,\n    enable_db_expire_on_commit=False\n)\n```\n\n### 🏗️ Creating an AsyncPostgres Instance\n\nNext, create an instance of `AsyncPostgres` using your configuration:\n\n```python\nfrom asyncpg_client import AsyncPostgres\n\nasync def main():\n    pg_client = await AsyncPostgres.create(config=config)\n    print(pg_client.async_url)\n    print(pg_client.sync_url)\n```\n\n### ⚙️ Managing Database Sessions\n\nInteract with your PostgreSQL database using the context manager from `get_or_create_session`:\n\n```python\nfrom asyncpg_client import AsyncPostgres\n\nasync def main():\n    pg_client = await AsyncPostgres.create(config=config)\n\n    async with pg_client.get_or_create_session() as session:\n        # Interact with your database here\n        pass\n\n    await pg_client.disconnect()\n```\n\n### 🔍 Example Usage\n\nHere's a basic example to demonstrate how `asyncpg-client` works:\n\n```python\nimport asyncio\nfrom asyncpg_client import AsyncPostgres, PostgresConfig\n\nasync def main():\n    config = PostgresConfig(\n        host='localhost',\n        port=5432,\n        user='your_user',\n        password='your_password',\n        database='your_database'\n    )\n    pg_client = await AsyncPostgres.create(config=config)\n\n    async with pg_client.get_or_create_session() as session:\n        # Perform your database operations here\n        pass\n\n    await pg_client.disconnect()\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### 🛡️ Error Handling\n\nHandle various database-related errors gracefully with custom exceptions:\n\n- `PGConnectionError`\n- `PGSessionCreationError`\n- `PGEngineInitializationError`\n\n### 🛑 Disconnecting\n\nEnsure a clean disconnect from your PostgreSQL database:\n\n```python\nawait pg_client.disconnect()\n```\n\n## 📄 License\n\nThis project is licensed under the Apache License 2.0. See the [LICENSE](https://github.com/deepmancer/asyncpg-client/blob/main/LICENSE) file for full details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepmancer%2Fasyncpg-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepmancer%2Fasyncpg-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepmancer%2Fasyncpg-client/lists"}