{"id":13870,"date":"2025-05-31T05:49:25","date_gmt":"2025-05-31T05:49:25","guid":{"rendered":"https:\/\/wealthrevelation.com\/data-science\/2025\/05\/31\/building-data-driven-applications-with-streamlit-and-external-apis\/"},"modified":"2025-05-31T05:49:25","modified_gmt":"2025-05-31T05:49:25","slug":"building-data-driven-applications-with-streamlit-and-external-apis","status":"publish","type":"post","link":"https:\/\/wealthrevelation.com\/data-science\/2025\/05\/31\/building-data-driven-applications-with-streamlit-and-external-apis\/","title":{"rendered":"Building Data-Driven Applications with Streamlit and External APIs"},"content":{"rendered":"<div id=\"tve_editor\" data-post-id=\"12899\">\n<div class=\"thrv_wrapper tve_image_caption img_style_rounded_corners\" data-css=\"tve-u-19721980562\"><span class=\"tve_image_frame\"><img src=\"https:\/\/dataaspirant.com\/wp-content\/plugins\/lazy-load\/images\/1x1.trans.gif\" data-lazy-src=\"https:\/\/dataaspirant.com\/wp-content\/uploads\/2025\/05\/data-drive-applications.png\" class=\"tve_image wp-image-12912\" alt=\"data drive applications\" data-id=\"12912\" width=\"843\" data-init-width=\"1536\" height=\"562\" data-init-height=\"1024\" title=\"data drive applications\" data-width=\"843\" data-height=\"562\" loading=\"lazy\"><img class=\"tve_image wp-image-12912\" alt=\"data drive applications\" data-id=\"12912\" width=\"843\" data-init-width=\"1536\" height=\"562\" data-init-height=\"1024\" title=\"data drive applications\" src=\"https:\/\/dataaspirant.com\/wp-content\/uploads\/2025\/05\/data-drive-applications.png\" data-width=\"843\" data-height=\"562\" loading=\"lazy\"><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p dir=\"ltr\">Data becomes more compelling when it&#8217;s interactive. Turning raw numbers into something people can <a href=\"https:\/\/dataaspirant.com\/time-series-analysis\/\" target=\"_blank\" rel=\"noopener\" data-wpil-monitor-id=\"233\">explore in real time<\/a> transforms insights into experiences. Streamlit makes that shift refreshingly easy, letting you turn <a href=\"https:\/\/dataaspirant.com\/nlp-text-preprocessing-techniques-implementation-python\/\" target=\"_blank\" rel=\"noopener\" data-wpil-monitor-id=\"239\">Python scripts<\/a> into browser-based apps with just a few lines of code.<\/p>\n<p dir=\"ltr\">What gives these apps their punch is external data\u2014live information pulled from sources that reflect the world as it moves. APIs bring that possibility into reach. Whether you\u2019re working with weather, stock prices, public health stats, or traffic flow, pulling <a href=\"https:\/\/dataaspirant.com\/outsource-dot-net-project\/\" target=\"_blank\" rel=\"noopener\" data-wpil-monitor-id=\"235\">data live pushes a project<\/a> from static to situational.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_tw_qs tve_clearfix\" data-url=\"https:\/\/twitter.com\/intent\/tweet\" data-via=\"\" data-use_custom_url=\"\" data-element-name=\"Click to Tweet\">\n<div class=\"thrv_tw_qs_container\">\n<div class=\"thrv_tw_quote\">\n<p class=\"\">Building Data-Driven Applications with Streamlit and External APIs<\/p>\n<\/p><\/div>\n<p>\n\t\t\t<span><br \/>\n\t\t\t\t<i><\/i><br \/>\n\t\t\t\t<span class=\"thrv_tw_qs_button_text thrv-inline-text tve_editable\">Click to Tweet<\/span><br \/>\n\t\t\t<\/span>\n\t\t<\/p>\n<\/p><\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p dir=\"ltr\">This tutorial walks through a lightweight app built in Streamlit that pulls real-time weather data from an external source and visualizes it interactively. It\u2019s a quick, clean way to embed real-world context into your <a href=\"https:\/\/dataaspirant.com\/anaconda-alternatives\/\" target=\"_blank\" rel=\"noopener\" data-wpil-monitor-id=\"241\">Python workflows<\/a>.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h2 id=\"t-1748614246246\" class=\"\">Why Streamlit + External APIs?<\/h2>\n<p dir=\"ltr\">Most <a href=\"https:\/\/dataaspirant.com\/data-analytics-shapes-modern-business-leadership\/\" target=\"_blank\" rel=\"noopener\" data-wpil-monitor-id=\"227\">data science<\/a> work happens in notebooks. Great for experimentation, not so great when you need to share it or make it interactive. Streamlit shifts that equation. With almost no setup, you can create sliders, dropdowns, buttons, and charts that run in the browser.<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption img_style_rounded_corners\" data-css=\"tve-u-197219acb70\"><span class=\"tve_image_frame\"><img src=\"https:\/\/dataaspirant.com\/wp-content\/plugins\/lazy-load\/images\/1x1.trans.gif\" data-lazy-src=\"https:\/\/dataaspirant.com\/wp-content\/uploads\/2025\/05\/streamlit.png\" class=\"tve_image wp-image-12914\" alt=\"Why Streamlit + External APIs?\" data-id=\"12914\" width=\"843\" data-init-width=\"1536\" height=\"562\" data-init-height=\"1024\" title=\"Why Streamlit + External APIs?\" data-width=\"843\" data-height=\"562\" loading=\"lazy\"><img class=\"tve_image wp-image-12914\" alt=\"Why Streamlit + External APIs?\" data-id=\"12914\" width=\"843\" data-init-width=\"1536\" height=\"562\" data-init-height=\"1024\" title=\"Why Streamlit + External APIs?\" src=\"https:\/\/dataaspirant.com\/wp-content\/uploads\/2025\/05\/streamlit.png\" data-width=\"843\" data-height=\"562\" loading=\"lazy\"><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p dir=\"ltr\">What makes Streamlit even more powerful is the ability to pipe in live data through APIs. With a few lines of code, your app can respond to real-world changes\u2014weather patterns, search trends, financial data\u2014each time someone uses it.<\/p>\n<p dir=\"ltr\">This combination unlocks everything from forecasting tools to live dashboards and decision-making aids. If you\u2019re curious about Streamlit\u2019s broader potential, the <a href=\"https:\/\/docs.streamlit.io\/\" class=\"\">official documentation<\/a> is a solid place to dive deeper.<\/p>\n<p dir=\"ltr\">For this build, we\u2019re using a weather API to demonstrate how easy it is to pull in data on the fly and present it through a simple user interface.<\/p>\n<h2 id=\"t-1748614246247\" class=\"\">Connecting to a Weather API<\/h2>\n<p dir=\"ltr\">To power the app with real-world data, we\u2019re using <a href=\"https:\/\/www.visualcrossing.com\/weather-api\/\" class=\"\">Visual Crossing&#8217;s weather API<\/a>. It provides access to historical and forecasted conditions across global locations in a developer-friendly format.<\/p>\n<p dir=\"ltr\">Start by signing up for a free account and generating an <a href=\"https:\/\/dataaspirant.com\/access-openai-api-keys\/\" target=\"_blank\" rel=\"noopener\" data-wpil-monitor-id=\"231\">API key<\/a>. You\u2019ll use this key to authenticate your requests.<\/p>\n<p dir=\"ltr\">Here\u2019s a basic structure for making a request:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_custom_html_shortcode\">\n<p>\n<code><br \/>\n<span>import<\/span> requests<\/p>\n<p><span>API_KEY<\/span> = <span>'your_api_key_here'<\/span><br \/>\n<span>location<\/span> = <span>'New York,NY'<\/span><br \/>\n<span>url<\/span> = <span>f'https:\/\/weather.visualcrossing.com\/VisualCrossingWebServices\/rest\/services\/timeline\/{location}?unitGroup=metric&amp;key={API_KEY}&amp;contentType=json'<\/span><\/p>\n<p><span>response<\/span> = requests.get(url)<br \/>\n<span>data<\/span> = response.json()<br \/>\n<\/code>\n<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>This call returns daily summaries and hourly breakdowns including temperature, humidity, wind speed, and more. Once you\u2019ve got the JSON response, it\u2019s easy to work with in Pandas:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_custom_html_shortcode\">\n<p>\n<code><br \/>\n<span>import<\/span> pandas <span>as<\/span> pd<\/p>\n<p><span>days<\/span> = data[<span>'days'<\/span>]<br \/>\n<span>df<\/span> = pd.DataFrame(days)<br \/>\n<span>print<\/span>(df.head())<br \/>\n<\/code>\n<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p dir=\"ltr\">The result is a clean DataFrame with columns like datetime, tempmax, tempmin, humidity, and windspeed. It\u2019s a ready-made feed for visualization or downstream processing.<\/p>\n<h2 id=\"t-1748614246248\">Building the Streamlit Interface<\/h2>\n<p dir=\"ltr\">With the data stream in place, it\u2019s time to design the interface. Streamlit makes it easy to set up an app that accepts user input, triggers an API call, and displays key metrics in real time.<\/p>\n<p dir=\"ltr\">Start with the core layout:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_custom_html_shortcode\">\n<p>\n<code><br \/>\n<span>import<\/span> streamlit <span>as<\/span> st<\/p>\n<p>st.title(<span>\"Live Weather Dashboard\"<\/span>)<br \/>\nst.write(<span>\"Enter a city to get the latest weather data.\"<\/span>)<br \/>\n<\/code>\n<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p class=\"style=\">Add a city input box and button:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_custom_html_shortcode\">\n<p>\n<code><br \/>\ncity = st.text_input(<span>\"City\"<\/span>, value=<span>\"New York\"<\/span>)<br \/>\n<span>if<\/span> st.button(<span>\"Get Weather\"<\/span>):<br \/>\n    <span># API call and display logic goes here<\/span><br \/>\n<\/code>\n<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Keep the code clean by wrapping the API call in a function:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_custom_html_shortcode\">\n<p>\n<code><br \/>\n<span>def<\/span> fetch_weather(city, api_key):<br \/>\n    url = <span>f'https:\/\/weather.visualcrossing.com\/VisualCrossingWebServices\/rest\/services\/timeline\/{city}?unitGroup=metric&amp;key={api_key}&amp;contentType=json'<\/span><br \/>\n    response = requests.get(url)<br \/>\n    <span>return<\/span> response.json()<br \/>\n<\/code>\n<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Now, when a user submits a city, fetch the data and display weather metrics:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_custom_html_shortcode\">\n<p>\n<code><br \/>\n<span>if<\/span> st.button(<span>\"Get Weather\"<\/span>):<br \/>\n    weather = fetch_weather(city, API_KEY)<br \/>\n    current = weather[<span>'days'<\/span>][<span>0<\/span>]<\/p>\n<p>    st.subheader(<span>f\"Weather in {city}\"<\/span>)<br \/>\n    st.metric(<span>\"Max Temp\"<\/span>, <span>f\"{current['tempmax']} \u00b0C\"<\/span>)<br \/>\n    st.metric(<span>\"Min Temp\"<\/span>, <span>f\"{current['tempmin']} \u00b0C\"<\/span>)<br \/>\n    st.metric(<span>\"Humidity\"<\/span>, <span>f\"{current['humidity']}%\"<\/span>)<br \/>\n    st.metric(<span>\"Wind Speed\"<\/span>, <span>f\"{current['windspeed']} km\/h\"<\/span>)<br \/>\n<\/code>\n<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p dir=\"ltr\">That\u2019s enough to get a lightweight, responsive app up and running\u2014ready to adapt, scale, and expand.<\/p>\n<h2 id=\"t-1748614246249\">Data Visualization<\/h2>\n<p dir=\"ltr\">Raw metrics are useful, but trends bring them to life. With the weather data stored in a DataFrame, Streamlit makes it easy to turn time-series data into visuals.<\/p>\n<p dir=\"ltr\">Start with your libraries:<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_custom_html_shortcode\">\n<p>\n<code><br \/>\n<span>import<\/span> matplotlib.pyplot <span>as<\/span> plt<br \/>\n<span>import<\/span> altair <span>as<\/span> alt<\/p>\n<p>st.line_chart(df[[<span>'datetime'<\/span>, <span>'tempmax'<\/span>, <span>'tempmin'<\/span>]].set_index(<span>'datetime'<\/span>))<\/p>\n<p>temp_chart = alt.Chart(df).mark_line().encode(<br \/>\n    x=<span>'datetime:T'<\/span>,<br \/>\n    y=<span>'tempmax:Q'<\/span>,<br \/>\n    tooltip=[<span>'datetime'<\/span>, <span>'tempmax'<\/span>]<br \/>\n).properties(<br \/>\n    title=<span>'Daily Maximum Temperature'<\/span><br \/>\n)<\/p>\n<p>st.altair_chart(temp_chart, use_container_width=<span>True<\/span>)<\/p>\n<p>humidity_chart = alt.Chart(df).mark_line(color=<span>'teal'<\/span>).encode(<br \/>\n    x=<span>'datetime:T'<\/span>,<br \/>\n    y=<span>'humidity:Q'<\/span><br \/>\n).properties(<br \/>\n    title=<span>'Daily Humidity Levels'<\/span><br \/>\n)<\/p>\n<p>st.altair_chart(humidity_chart, use_container_width=<span>True<\/span>)<br \/>\n<\/code>\n<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p dir=\"ltr\">Charts give users an intuitive sense of how the weather is shifting\u2014something numbers alone can\u2019t always convey.<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption img_style_rounded_corners\" data-css=\"tve-u-19721997482\"><span class=\"tve_image_frame\"><img src=\"https:\/\/dataaspirant.com\/wp-content\/plugins\/lazy-load\/images\/1x1.trans.gif\" data-lazy-src=\"https:\/\/dataaspirant.com\/wp-content\/uploads\/2025\/05\/streamlit-v2.png\" class=\"tve_image wp-image-12913 tcb-moved-image\" alt=\"Why Streamlit + External APIs?\" data-id=\"12913\" width=\"843\" data-init-width=\"1536\" height=\"562\" data-init-height=\"1024\" title=\"Why Streamlit + External APIs?\" data-width=\"843\" data-height=\"562\" data-css=\"tve-u-1972199df59\" loading=\"lazy\"><img class=\"tve_image wp-image-12913 tcb-moved-image\" alt=\"Why Streamlit + External APIs?\" data-id=\"12913\" width=\"843\" data-init-width=\"1536\" height=\"562\" data-init-height=\"1024\" title=\"Why Streamlit + External APIs?\" src=\"https:\/\/dataaspirant.com\/wp-content\/uploads\/2025\/05\/streamlit-v2.png\" data-width=\"843\" data-height=\"562\" data-css=\"tve-u-1972199df59\" loading=\"lazy\"><\/span><\/div>\n<h2 id=\"t-1748614246250\" class=\"\">Wrapping Up and Next Steps<\/h2>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p dir=\"ltr\">You now have a functioning Streamlit app that pulls live weather data, processes it on demand, and presents it through a responsive, browser-based interface. It\u2019s fast to build and easy to adapt\u2014whether you want to add historical context, more metrics, or even <a href=\"https:\/\/dataaspirant.com\/predictive-models-consumer-behavior\/\" target=\"_blank\" rel=\"noopener\" data-wpil-monitor-id=\"229\">predictive models<\/a>.<\/p>\n<p dir=\"ltr\">This kind of project sits right at the intersection of accessibility and power. Lightweight frameworks are changing how quickly we can turn data into usable tools. If you want to explore this further, take a look at this guide on <a href=\"https:\/\/dataaspirant.com\/low-code\/\" class=\"\">low-code tools for data science and machine learning projects<\/a>.<\/p>\n<p dir=\"ltr\">The ability to build with external data in real time isn\u2019t a novelty\u2014it\u2019s becoming a core part of applied data science. Once you learn how to pull, clean, and display external signals, you\u2019re not just analyzing the world. You\u2019re building ways to interact with it.<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_wp_shortcode\">\n<div class=\"tve_shortcode_rendered\">\n<div>\n<h4>\ud83c\udf1f Follow Us<\/h4>\n<p>\n<strong>\ud83d\udcac I hope you like this post!<\/strong> If you have any questions or want me to write an article on a specific topic, <span>feel free to comment below<\/span>.\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/dataaspirant.com\/data-driven-applications-external-apis\/<\/p>\n","protected":false},"author":0,"featured_media":13871,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/posts\/13870"}],"collection":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/comments?post=13870"}],"version-history":[{"count":0,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/posts\/13870\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/media\/13871"}],"wp:attachment":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/media?parent=13870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/categories?post=13870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/tags?post=13870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}