Live News App with Python is the most efficient way to aggregate real-time news and visualize external data streams in today’s fast-paced digital ecosystem. Whether it’s tracking global events, monitoring industry trends, or keeping up with competitor news, having a custom dashboard is essential for businesses and enthusiasts alike.
Instead of building complex web applications using React, Node.js, or Redux, you can rapidly prototype a Live News App with Python and Streamlit. This approach saves development time and resources while delivering a fully functional, filterable, and scalable dashboard within hours.
Live Demo
Before we dive into the code, you can see the application running live in production here:
Why Build a Live News App with Python and Streamlit?
Python and Streamlit are perfect for developers looking to rapidly prototype live news apps without the overhead of traditional frontend and backend setups. Streamlit allows you to render a responsive live news dashboard using only Python, eliminating the need for HTML, CSS, or JavaScript.
Overcoming State Management Challenges
However, a common challenge when building a live news app with Python using Streamlit is state management. Streamlit re-executes scripts with every interaction, which can reset variables like the current page of news articles. Using st.session_state ensures that your live news feed retains state across reruns, making the app user-friendly and seamless.
Technology Stack for a Live News App with Python and Streamlit
To build a robust news aggregator and live app, the following technology stack was used:
-
Programming Language: Python 3.9+
-
Front-End Framework: Streamlit
-
HTTP Client Library: Requests
-
News Data Source: Newsdata.io JSON REST API
This combination allows for rapid development, easy integration with live APIs, and a clean dashboard for news visualization.
Phase 1: Environment Setup and Layout Strategy for Live News App with Python and Streamlit
Before creating a live news app, setting up the environment and defining a layout strategy is critical. We chose a centered layout, similar to Medium or Substack, to enhance readability. A single-column design ensures the user can focus on live news articles without distraction.
import streamlit as st
import requests
# page config setup
st.set_page_config(page_title='LIVE NEWS',layout='centered')
st.markdown("<h1 style='text-align:center'> LIVE NEWS </h1>",unsafe_allow_html=True)
Using unsafe_allow_html=True provides additional control for styling headers, images, and content alignment, making the Python-powered live news dashboard visually appealing.
Phase 2: Solving the Amnesia Problem in Live News App with Python and Streamlit
The most technical limitation of Streamlit for live news apps is that the app “forgets” the current state during user interactions. For example, if a user is on page 3 of sports news and clicks “Next Page,” Streamlit reruns the script, resetting all local variables.
We solve this by leveraging st.session_state, a persistent storage for live news app state. This allows the app to store pagination tokens, filter selections, and other variables across user interactions, ensuring a smooth and reliable live news experience.
if "next_page_id" not in st.session_state:
st.session_state.next_page_id = None
Phase 3: Sidebar and User Controls for a News Dashboard
A clean sidebar is essential for user input in live news apps. All filtering and selection controls are placed in the sidebar, while the main area displays the real-time news feed.
Users can select news categories like Business, Tech, or Sports, and choose countries to filter news. Mapping country names to API codes ensures users interact with human-readable values, enhancing the usability of the live news app.
with st.sidebar:
st.header("Settings")
# Category Selection
category = st.selectbox(
"Choose Category",
options=['education','entertainment','health','food','crime','technology','sports','business'],
index=5 # Defaults to 'technology'
)
# Country Mapping: UI Label -> API Code
country_map={
"India":'in',
"United States":'us',
"Japan":"jp",
"United Kingdom":"gb"
}
country_name = st.selectbox("Choose a Country",list(country_map.keys()))
country_code = country_map[country_name]
The “Apply Filters” button prevents unnecessary API calls and ensures that the app only fetches relevant news data when the user intends, optimizing speed and efficiency.
if st.button("Apply Filters"):
# RESET the pagination token
st.session_state.next_page_id=None
st.rerun()
Phase 4: Building the API Layer for News Aggregation
Integrating external APIs like the Newsdata.io API is a cornerstone of building a live news app with Python. Our fetch_news function includes robust error handling for API timeouts, invalid data, or key restrictions.
def fetch_news(page_id=None):
base_url='https://newsdata.io/api/1/latest?'
api_key="pub_a2a77ae0275040b89a657a4695df8b0c"
params={
"apikey":api_key,
"country":country_code,
"category":category,
"language":'en',
"removeduplicate":"1"
}
if page_id :
params['page']=page_id
try:
response = requests.get(base_url,params=params)
#print(response.json())
return response.json()
except requests.exceptions.RequestException as e:
st.error(f"Error fetching data : {e}")
return None
Passing "removeduplicate": "1" ensures only unique headlines are displayed, improving the signal-to-noise ratio of the live news dashboard. This is critical for analysts who rely on accurate, up-to-date news feeds.
Phase 5: Dynamic UI Rendering for Live Articles
News articles vary in structure—some have images, descriptions, or valid sources, while others may not. Using conditional rendering in Streamlit, we create a dynamic live news layout that adapts to available data.
st.title(f'{category.capitalize()} News in {country_name}')
news_data = fetch_news(st.session_state.next_page_id)
if news_data and "results" in news_data:
articles = news_data['results']
for article in articles:
# Safe extraction with defaults using .get()
title = article.get("title") or "No Title"
description = article.get("description")
link = article.get('link','#')
image_url= article.get('image_url')
source_id= article.get('source_id',"Unknown")
with st.container():
st.subheader(title)
st.caption(f"Source : {source_id}")
if image_url:
col1,col2=st.columns([3,1])
with col1:
if description:
st.write(description[:300]+"...")
else:
st.write("No description available")
st.link_button("Read Full Article ",link)
with col2:
st.image(image_url,use_container_width=True)
else:
# Fallback for text-only articles
if description:
st.write(description)
st.link_button("Read Full Article ",link)
st.divider()
For example, a 3:1 column ratio displays 75% width for text and 25% for images. If no image exists, a single column layout ensures the Python live news app UI remains visually consistent and user-friendly.
Phase 6: Implementing Pagination in Live News App with Python and Streamlit
Pagination is key to maintaining a smooth live news feed experience. Our app uses a “Load Next Batch” button, updating st.session_state with the API’s next page token and calling st.rerun() to fetch the next batch of articles.
This allows users to continuously scroll through news without losing context, providing a real-time, paginated live news experience with minimal latency.
#pagination logic
next_page_token = news_data.get("nextPage")
if next_page_token:
if st.button("Load Next Batch"):
# Update the session state
st.session_state.next_page_id = next_page_token
# Force a re-run of the script
st.rerun()
else:
st.info("No more news available for this category")
elif news_data:
st.warning("No news found for these filters")
Related posts:
- Cryptocurrency Price Tracker Python – Real – Time Project
- Web Scraping with Python: Extract Data from Websites in Minutes
Deployment and Final Thoughts
We deployed the Python live news app using Streamlit Cloud, connected to GitHub via a CI/CD pipeline. This allows developers to push updates seamlessly to the live news dashboard.
With under 100 lines of Python code, including comments, this project demonstrates how to rapidly prototype functional, scalable, and state-managed dashboards using Python, Streamlit, and the Newsdata.io API.
For additional advice and updates, follow us on Facebook, Instagram, and LinkedIn.

