This blogpost covers the details of my project, Async Await support in Scrapy. With this post, I would explain my project which I would be working on during this summers.
Details of my project : Async Await support in Scrapy
How did I get to know about the organization ?
Scrapy is a web scraper, which I have used to scrape websites, and get a lot of data to use them, in Data Analytics, and Machine Learning. Data is an integral part of these fields, and we need to have data, in order to progress in them. So using scrapymade me realise the philosophy of the software, while open sourced nature would mean that the users can customize them accordingly.
How did I choose the project ?
For Asynchronous paradigm, the goal is simple : serve the order which finishes first, in spite of the sequence of the request. In programming terms, it is like serving the requests in order of their completion.
How does Scrapy uses the asynchronous paradigm of programming ?
As Scrapy is a web scraper, it makes sense to use async programming, because web pages may not be available at time of requests, and it makes sense to use async paradigm to approach the task. Currently, before Python 3.3, people used asynchronous paradigm, using generators. Scrapy uses a framework, named Twisted for the above. Generators are iterators, which can be used to stop the iterator as and when wished, and to resume them, whenever we want. Using generators, we can stop the code flow, as we can ask Python to wait till we get the response of the request, and proceed accordingly. A relevant blog post for using generators is : Generators.
How async await syntactic sugar relevant ?
For people who have programmed using asynchronous paradigm, they know the drawbacks of it, especially the sphagetti code and callback hell. While new paradigms for asycnhronous programming has been used in Python( i.e generators), the main problem starts, when we want to use generators for both as tool for asynchronous programming, and as an iterator. It becomes difficult to differentiate between the two, and people contributing to these projects, might not be able to make out between them. In order to differentiate between the two, Python has introduced two primitives, for them, async and await. These are generators under the hood, but with difference that they have their own primitive, called ‘coroutines’. Using the above, it becomes easy to write the asynchronous code in a synchronous manner, while mantaining the async nature of code.
What would be my goal in this project ?
My objective in the project would be to support async / await idioms, so that users can write the project with the new syntactic sugar, while maintaining the backwards compatibilty of the project. At the end, we can write scraping code using the new paradigm, and frame our logic of scraping, without needing the overhead of callbacks.
Links to resources