A high-performance real-time news aggregation portal built with FastAPI that delivers live updates via WebSocket with async REST API endpoints.
- 🔴 Live Updates: WebSocket-powered real-time news streaming
- ⚡ High Performance: Async FastAPI with SQLAlchemy
- 🛠️ Admin Tools: Generate mock news with Faker library
- 🔐 JWT Auth: Secure token-based authentication with bcrypt
- Python 3.8+
- pip package manager
# Clone repository
git clone https://github.com/karimovsardorbek/real_time_news_fastapi.git
cd real_time_news_fastapi
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Start FastAPI server
cd fastapi-news-portal
uvicorn main:app --host 0.0.0.0 --port 8010 --reload
# Frontend (in new terminal)
cd frontend
python -m http.server 8020curl -X POST 'http://localhost:8010/register/' \
-H 'Content-Type: application/json' \
-d '{
"username": "admin",
"password": "yourpassword"
}'curl -X POST 'http://localhost:8010/token' \
-H 'Content-Type: application/json' \
-d '{
"username": "admin",
"password": "yourpassword"
}'Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer"
}curl -X GET 'http://localhost:8010/api/articles/'curl -X POST 'http://localhost:8010/api/generate-news/' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'const socket = new WebSocket('ws://localhost:8010/ws/news/');- FastAPI - Modern, fast web framework
- SQLAlchemy - Python SQL toolkit and ORM
- Uvicorn - ASGI server implementation
- SQLite - Lightweight database
- WebSockets - Real-time bidirectional communication
- JWT - JSON Web Token authentication
- Bcrypt - Password hashing
- Faker - Generate fake data for testing
- Vanilla JavaScript - Pure JS with modern ES6+ features
- HTML5 - Semantic markup
- CSS3 - Modern styling with animations & grid
- WebSocket API - Browser native WebSocket support
The application uses SQLAlchemy with SQLite for data persistence:
- Articles are stored with auto-incrementing IDs
- Users have bcrypt-hashed passwords
- Database is created automatically on first run
When new articles are generated:
- Article is saved to database
- WebSocket manager broadcasts to all connected clients
- Frontend receives update and adds article to DOM
# Install production server
pip install gunicorn
# Run with Gunicorn
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8010
# Or with Uvicorn (recommended)
uvicorn main:app --host 0.0.0.0 --port 8010 --workers 4- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request