Questions tagged [aiopg]

A Python library for accessing a PostgreSQL database using asyncio.

aiopg wraps asynchronous features of the Psycopg database driver.

30 questions
13
votes
1 answer

aiopg + sqlalchemy: how to "drop table if exists" without raw sql?

I am looking at examples of aiopg usage with sqlalchemy and these lines scare me: async def create_table(conn): await conn.execute('DROP TABLE IF EXISTS tbl') await conn.execute(CreateTable(tbl)) I do not want to execute raw sql queries…
sanyassh
  • 8,100
  • 13
  • 36
  • 70
7
votes
0 answers

django ORM with asyncio

I'm looking for something that can allow the usage of the Django ORM with asyncio (with PostgreSQL). As of now I found only aiopg in the asyncio ecosystem, which allows to run raw SQL or to use SQLAlchemy only. I then found something in the django…
Luke
  • 1,794
  • 10
  • 43
  • 70
4
votes
1 answer

Failure on unit tests with pytest, tornado and aiopg, any query fail

I've a REST API running on Python 3.7 + Tornado 5, with postgresql as database, using aiopg with SQLAlchemy core (via the aiopg.sa binding). For the unit tests, I use py.test with pytest-tornado. All the tests go ok as soon as no query to the…
Alberto
  • 687
  • 6
  • 21
4
votes
2 answers

Using asyncio nested_future() and gather() with nested loops

While trying to execute some async functions in parallel, I am always getting an error, which I would like to understand. Running asyncio on Python 3.5.1, I'm combining aiohttp through the ClientSession and aiopg (asynchronous psycopg2) calls. The…
Rmatt
  • 1,287
  • 1
  • 16
  • 30
2
votes
0 answers

Aiopg cursor doesn't return fetchone()

I am stuck into a problem with aiopg. There are a one problem when i async with engine and try to return a result to endpoint in FastApi. Look down below for my db class. class DBEngine: def __init__(self, connection_url: str) -> None: …
Lilly
  • 59
  • 1
  • 1
  • 9
2
votes
0 answers

how to work with postgres database using coroutines

We're building a backend service utilizing asyncio framework (in our case aiohttp). We're using aiopg to make queries to the database. Since this is one-threaded server, what is the correct implementation pattern of making a database query: 1) The…
PawelRoman
  • 6,122
  • 5
  • 30
  • 40
2
votes
1 answer

How to improve performance of many appends to a list?

How to improve a performance of the following code? BANNED_DOORBOTS = {...} async def execute_query(self, query): async with self.pool.acquire() as conn: async with conn.cursor() as cur: await cur.execute(query) …
user6611764
2
votes
1 answer

aiopg/psycopg2 autocommit and transactions

My doubt is very SQLish but Since psycopg2 async connections are autocommit, I'm manually setting up transactions defined and then closed in the same cursor/connection. like this: async def transaction(self, queries): async with…
monobot
  • 109
  • 1
  • 7
1
vote
0 answers

Psycopg2 install error on windows (pip or wheel) (UnicodeDecodeError)

I am currently trying to make use of pypy to try and see with a profiler if I will get better results than now, currently using only python 3.8 I have installed pypy 3.9 for windows 10 (64 bits) and been upgrading pip, setuptools, as well as wheels…
Charles L.
  • 13
  • 1
  • 5
1
vote
1 answer

fastapi + aiomysql connection pool stuck after 10 calls

Why aiomysql connection pool stuck after N calls? (N is the maxsize number of connection. Tried the default N=10 and N=3) I thought the acquired connections are automatically closed on exit with async with. Here's the minimal script to…
luthfianto
  • 1,746
  • 3
  • 22
  • 37
1
vote
1 answer

How can I use unique query for every client connected to websocket

I'm trying to have only one database connection in my websocket and return this information to each client connected. Is it possible to do that? There is my current code: import asyncio import aiopg import websockets import logging import sys import…
Michael
  • 1,063
  • 14
  • 32
1
vote
1 answer

AttributeError: 'PGDialect_psycopg2' object has no attribute 'dbapi_type_map'

After updating all the plugins on the python server, it now raises File "D:\Python362\lib\site-packages\aiopg\utils.py", line 72, in __await__ resp = yield from self._coro File "D:\Python362\lib\site-packages\aiopg\sa\connection.py", line 116,…
AJIADb9
  • 41
  • 5
0
votes
0 answers

Error when using pytest-asyncio with aiopg

I'm creating small educational app using fastapi and aiopg for connectioon to db. It remains to write only the tests. I try to use pytest-asyncio and dependency overriding for connection to my test_db. @pytest.fixture(scope="session",…
Ririol
  • 1
  • 1
0
votes
1 answer

Error on application startup after adding pg_context to main.py

I make polls application from docs. Version of PostgreSQL is 15. Using poetry here are my dependencies from pyproject.toml: python = "^3.11" aiohttp = "^3.8.5" aiodns = "^3.0.0" pyyaml = "^6.0.1" aiopg = {extras = ["sa"], version =…
WideWood
  • 549
  • 5
  • 13
0
votes
0 answers

how to fetch request which has multiple queries inside using aiopg?

I use python aiopg package and want to group requests into big one using semicolons. I tried Cursor.nextset(), but it marked as "Not supported" It should be something like Query = ''' select * from product where id = 74; select id,…
VladVons
  • 27
  • 3
1
2