Skip to main content

A Python package to query data from NewsAPI in Streamlit apps

Project description

Open_inStreamlit Python PyPi Build CodeFactor License

📰 Streamlit-NewsAPI Data Connector

Connect to NewsAPI from your Streamlit app. Powered by st.experimental_connection(). Works with Streamlit >= 1.22. Read more about Streamlit Connections in the official docs.

Contributions to this repo are welcome. If you are interested in helping to maintain it, reach out to us.

🚀 Quickstart

  1. Clone the repository:
git clone git@github.com:dcarpintero/st-newsapi-connector.git
  1. Create and Activate a Virtual Environment:
Windows:

py -m venv .venv
.venv\scripts\activate

macOS/Linux

python3 -m venv .venv
source .venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Launch Web Application
streamlit run ./app.py

📄 Minimal Integration

# 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.28.1

👩‍💻 Streamlit Web App

Demo Web App deployed to Streamlit Cloud and available at https://st-newsapi-connector.streamlit.app/

📚 References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

st-newsapi-connector-0.1.18.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

st_newsapi_connector-0.1.18-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page