Implement Async Support
Description
Implement comprehensive async/await support for GNews using aiohttp to enable concurrent requests and significantly improve performance for bulk operations. This will make GNews suitable for high-performance applications.
Why?
Async support enables concurrent requests, which can be 10x faster for bulk operations. Many modern Python applications use async/await, and this will make GNews compatible with async frameworks like FastAPI, asyncio, and others.
How?
Create a new async_gnews.py file with:
-
GNewsAsyncclass with async methods - Use
aiohttpfor HTTP requests instead ofurllib - Implement concurrent request handling
- Maintain API compatibility with synchronous version
- Add proper async context management
Files to Create
-
gnews/async_gnews.py
Files to Modify
-
requirements.txt(add aiohttp dependency) -
gnews/__init__.py(export async class)
Acceptance Criteria
- [ ]
GNewsAsyncclass created with async methods - [ ] All synchronous methods have async equivalents
- [ ] Concurrent request handling implemented
- [ ] Proper error handling for async operations
- [ ] Context manager support (
async with) - [ ] Performance improvements demonstrated
- [ ] Tests added for async functionality
- [ ] Documentation updated with async examples
Example Usage
import asyncio
from gnews import GNewsAsync
async def main():
async with GNewsAsync() as gnews:
# Concurrent requests
tasks = [
gnews.get_news('AI'),
gnews.get_news('Machine Learning'),
gnews.get_news('Deep Learning')
]
results = await asyncio.gather(*tasks)
return results
# Run async function
results = asyncio.run(main())
Resources
Difficulty: Medium
Time Estimate: 3-5 hours
can you assign this to me?
i want to work on this issue can you kindly assign it to me i am familiar with async files and have worked on real world projects that must needs these features hence i can take on this issue without facing much difficulty if you assign it to me
i would like to work in this issue. please assign this issue to me @ranahaani
@AnaghDeshpande Hi, I saw this project and the issue is quite necessary for me. Can I take it and I'll try to integrate my first changes into your project? And tell me, have you done anything? So that neither you nor I do the same thing.
i create a pr https://github.com/ranahaani/GNews/pull/156