Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to asynchronously query SQL Server from Python (3.4)?

Is it possible to perform asynchronous queries against Microsoft SQL Server from Python (3.4), i.e. in the context of an asyncio event loop?

The following is a skeleton asyncio program, where the (async) SQL query should be fitted into the do_it function:

import asyncio
import contextlib


@asyncio.coroutine
def do_it():
    # TODO: Make an asynchronous MS SQL query, but how??
    fut = asyncio.Future()
    fut.set_result(None)
    return fut


with contextlib.closing(asyncio.SelectorEventLoop()) as loop:
    asyncio.set_event_loop(loop)
    loop.run_until_complete(do_it())

print('Finished')
like image 458
aknuds1 Avatar asked Oct 21 '25 04:10

aknuds1


1 Answers

For now there is only PostgreSQL native asyncio support via aiopg library.

But you can run synchronous calls to MSSQL by loop.run_in_executor().

like image 76
Andrew Svetlov Avatar answered Oct 23 '25 20:10

Andrew Svetlov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!