https://github.com/litestar-org/litestar-asyncpg
Database connection management plugin for Litestar and asyncpg
https://github.com/litestar-org/litestar-asyncpg
asyncpg litestar litestar-api litestar-framework
Last synced: 5 days ago
JSON representation
Database connection management plugin for Litestar and asyncpg
- Host: GitHub
- URL: https://github.com/litestar-org/litestar-asyncpg
- Owner: litestar-org
- License: mit
- Created: 2023-10-01T22:32:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-27T13:19:52.000Z (about 2 months ago)
- Last Synced: 2025-03-24T23:51:24.259Z (22 days ago)
- Topics: asyncpg, litestar, litestar-api, litestar-framework
- Language: Python
- Homepage:
- Size: 317 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-litestar - `litestar-asyncpg` - A plugin for the AsyncPG database driver.<sup>*</sup> (Resources / Official Resources)
README
![]()
![]()
| Project | | Status |
|-----------|:----|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| CI/CD | | [](https://github.com/litestar-org/litestar-asyncpg/actions/workflows/publish.yml) [](https://github.com/litestar-org/litestar-asyncpg/actions/workflows/ci.yml) [](https://github.com/litestar-org/litestar-asyncpg/actions/workflows/docs.yml) |
| Quality | | [](https://codecov.io/github/litestar-org/litestar-asyncpg) [](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar-asyncpg) [](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar-asyncpg) [](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar-asyncpg) [](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar-asyncpg) |
| Package | | [](https://badge.fury.io/py/litestar)   |
| Community | | [](https://reddit.com/r/litestarapi) [](https://discord.gg/litestar) [](https://matrix.to/#/#litestar:matrix.org) [](https://blog.litestar.dev) [](https://twitter.com/LitestarAPI) [](https://blog.litestar.dev) |
| Meta | | [](https://github.com/litestar-org/litestar-asyncpg) [](https://github.com/python/mypy) [](https://spdx.org/licenses/) [](https://github.com/sponsors/litestar-org) [](https://github.com/astral-sh/ruff) [](https://github.com/psf/black) |
# Litestar AsyncpgA barebones AsyncPG plugin for Litestar. This plugin is useful for when you plan to use no ORM or need to manage the postgres connection separately.
## Usage
### Installation
```shell
pip install litestar-asyncpg
```### Example
Here is a basic application that demonstrates how to use the plugin.
```python
from __future__ import annotationsfrom typing import TYPE_CHECKING
from litestar import Controller, Litestar, get
from litestar_asyncpg import AsyncpgConfig, AsyncpgPlugin, PoolConfigif TYPE_CHECKING:
from asyncpg import Connectionclass SampleController(Controller):
@get(path="/sample")
async def sample_route(self, db_connection: Connection) -> dict[str, str]:
"""Check database available and returns app config info."""
result = await db_connection.fetch("select 1")
return {"select_1": str(result)}asyncpg = AsyncpgPlugin(config=AsyncpgConfig(pool_config=PoolConfig(dsn="postgresql://app:app@localhost:5432/app")))
app = Litestar(plugins=[asyncpg], route_handlers=[SampleController])```