integrating django with aiohttp/asyncio
Asked Answered
L

1

7

I want to integate django with aiohttp/asyncio for asynchronous programming and for websockets handling. I know django has celery & django-channels to do asynchronous task and websocket server respectively but aiohttp is having both asynchronous and websocket server pre built in it and I found that framework more scalable and easy, compared to celery/django channels while creating a function to webscraping (I don't know if webscraping can be possible in celery I, havent tried it yet).
And it also supports async and await perfectly.

But my question is: How can we implement both django and aiohttp in a project? Instead using django's development server can we use aiohttp server to serve the site.

And are we able to integrate django with aiohttp function (like lets take an example: If I want to scrape a website of user submmited input to my database. Can I use await calls in my function while fetching the website and posting the following website to my django database? Or post the function results to another django function?)

And I want to know the disadvantages of integrating, if any?

And while posting your answer please could you post a sample practical example of integration instead suggesting me those libraries over github.

Lewls answered 19/1, 2019 at 6:43 Comment(0)
R
0

Maybe is time for considering Django >= 4.1 wich already have built-in Asynchronous Support

From the docs:

Django has support for writing asynchronous (“async”) views, along with an entirely async-enabled request stack if you are running under ASGI. Async views will still work under WSGI, but with performance penalties, and without the ability to have efficient long-running requests.

We’re still working on async support for the ORM and other parts of Django. You can expect to see this in future releases. For now, you can use the sync_to_async() adapter to interact with the sync parts of Django. There is also a whole range of async-native Python libraries that you can integrate with.

Reggiereggis answered 13/2, 2023 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.