Skip to main content

All Questions

1 vote
1 answer
73 views

How to create a single table at run time with SQLAlchemy asyncio

In my program I have several classes defined which may or may not be instantiated in a given run time. Therefore I don't want to define the tables in the class and have them all populated together ...
iamthebull's user avatar
1 vote
1 answer
392 views

How do you establish a self-referencing foreign key in SQLAlchemy 2.0?

Here is my model: class MyModel(Base): __tablename__ = 'model' id : Mapped[int] = mapped_column(primary_key=True) given_id : Mapped[str] = mapped_column(String(50),...
Taras  Mykhalchuk's user avatar
0 votes
1 answer
959 views

Tortoise-orm with FastApi Fetching data from db is blocking/Sync instead of asynchronous/non-blocking

Using fastapi with tortoise-orm==0.19.3. There're like 25,000 records of the table Server. I'm fetching all of them with the endpoint /servers/ like this. @server_router.get("/servers") ...
Randix Lai Randy's user avatar
2 votes
1 answer
10k views

How to use FastApi and SqlAlchemy for asynchronous operations

I'm using translation software, there may be some mistakes in expression, please understand I have checked the tutorials on the internet and followed the corresponding ideas, but I have encountered a ...
Exploit's user avatar
  • 105
5 votes
2 answers
8k views

How to get a session from async_session() generator FastApi Sqlalchemy

I see in many places an approach for getting SqlAlchemy session just like this one below: async def get_session() -> AsyncSession: async with async_session() as session: yield session ...
thedmdim's user avatar
3 votes
1 answer
2k views

How to return data on WebSocket when new database entry is made FastAPI

I am trying to write a simple API that collects measurements, and then streams them live to clients over a websocket with FastAPI. There are plenty of tutorials on how to send messages when triggered ...
Sean Palmer's user avatar
61 votes
3 answers
108k views

ObjectNotExecutableError when executing any SQL query using AsyncEngine

I'm using async_engine. When I try to execute anything: async with self.async_engine.connect() as con: query = "SELECT id, name FROM item LIMIT 50;" result = await con.execute(f"...
Karol Zlot's user avatar
  • 4,103
38 votes
2 answers
77k views

SqlAlchemy asyncio orm: How to query the database

In SqlAlchemy async orm engine how do I query a table and get a value or all? I know from the non async methods that I can just do SESSION.query(TableClass).get(x) but trying this with the async ...
Marcel Alexandru's user avatar
2 votes
0 answers
4k views

Async SQLAlchemy Session: Commit using AsyncSession() or AsyncSession?

I am starting to use AsyncSession from sqlalchemy in a asyncio app. However, when assigning an AsyncSession object to a class like Foo (based on official docs) and Bar below, is there any difference ...
Nyxynyx's user avatar
  • 63.9k
14 votes
1 answer
27k views

SQLAlchemy AttributeError: 'AsyncEngine' object has no attribute '_run_ddl_visitor'

I am trying to use the async version of SQLAlchemy in an asyncio app. However, when trying to create the tables using Metadata().create_all(), the following error occurs AttributeError: 'AsyncEngine' ...
Nyxynyx's user avatar
  • 63.9k
1 vote
1 answer
1k views

"meta" in Async SQLAlchemy Example

In the official SQLALchemy docs on using an async version of the traditional Engine API, we are provided with the example code import asyncio from sqlalchemy.ext.asyncio import create_async_engine ...
Athena Wisdom's user avatar
0 votes
1 answer
939 views

aiomysql and sqlalchemy basic example produces syntax error on python 3.6

I am trying to integrate sqlalchemy with aiomysql on python 3.6, using their official example on github here is my full code import sqlalchemy as sa import asyncio from aiomysql.sa import ...
m.awad's user avatar
  • 187
3 votes
2 answers
8k views

Correct usage of sqlalchemy scoped_session with python asyncio

I'm building an app using asyncio. I will be using sqlalchemy as the orm. From what i understand scoped_session associates a session with a thread so they don't with each other's operations. Now since ...
Shaumux's user avatar
  • 745