Streamlit Data Connector component that extends Streamlit to easily integrate the NewsAPI in Streamlit Apps. Works with Streamlit >= 1.28.
- Clone the repository:
git clone git@github.com:dcarpintero/st-newsapi-connector.git
- Create and Activate a Virtual Environment:
Windows:
py -m venv .venv
.venv\scripts\activate
macOS/Linux
python3 -m venv .venv
source .venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Launch Web Application
streamlit run ./app.py
# src/app.py
import streamlit as st
from st_newsapi_connector.connection import NewsAPIConnection
conn_newsapi = st.connection("NewsAPI", type=NewsAPIConnection)
# Retrieves News Articles on a specific topic from the NewsAPI
df = conn_newsapi.everything(topic="AI, LLMs")
st.dataframe(df)
# Retrieves Top-Headlines in a country and category from the NewsAPI
df = conn_newsapi.top_headlines(country='US', category='Science')
st.dataframe(df)
# .streamlit/secrets.toml
NEWSAPI_KEY = 'your-newsapi-key'
NEWSAPI_BASE_URL = 'https://newsapi.org/v2/'
# requirements.txt
pandas==1.5.1
pycountry==22.3.5
requests==2.31.0
streamlit==1.30.1
Demo Web App deployed to Streamlit Cloud and available at https://newsapi-connector.streamlit.app/