Implementing a stateful architecture with Streamlit

Implementing a stateful architecture with Streamlit

Implementing a stateful architecture with Streamlit. Using PostgreSQL to create stateful, multi-page applications with Streamlit


Streamlit has come a long way since its inception back in October of 2019. It has empowered the software development community and has effectively democratized the way we develop and deploy apps to the cloud. However as with all new tools, there is still some way to go, and while the Streamlit team works tirelessly on addressing requests for new features, we developers ourselves can create ad hoc work arounds in the meantime.

A feature that Streamlit currently lacks, is the ability to implement programmable state for its apps. In its current form, there is no internal state that can store volatile data such as user inputs, dataframes and values entered into widgets. Given that Streamlit innately re-runs the entire script when the user triggers an action in the event of pressing a button or switching between pages, the app will reset all inputs and data. While for many applications, this is a non-issue, for others it can be a deal breaker. Just imagine if you are trying to build an app with sequential logic using incremental steps, the absence of a stateful architecture would render Streamlit as an unsuitable framework. The founders have committed to releasing a stateful version in the near future, but until then, one can use an open source database such as PostgreSQL to develop a hack as I will explain below.


PostgreSQL or Postgres for short is a free and open source relational database system that is often the database of choice for most developers due to its ease of use and extended capabilities. While it is ostensibly a structured database management system, it can also store non-structured data such as arrays and binary objects, which makes it rather useful for open-ended projects. In addition, its graphical user interface is highly intuitive and straightforward ensuring that the learning curve is very shallow.

In our implementation of a stateful architecture, we will be using a local Postgres server to store our state variables such as the user inputs and dataframes generated in our Streamlit app. Before we proceed, please download and install Postgres using this link. During the installation you will be prompted to configure a username, password and local TCP port to forward your database server to. The default port is 5432 which you may keep as is. Once the installation is completed, you will be able to login to your server by running the ‘pgAdmin 4' application which will then open your server’s portal on your browser as shown below.

web-development cloud-computing data data-science database

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Applications Of Data Science On 3D Imagery Data

The agenda of the talk included an introduction to 3D data, its applications and case studies, 3D data alignment and more.

Best Cloud Computing (AWS) Development Company

Develop highly scalable apps on Amazon Cloud Services in India. Mobile App Development India Offers Amazon cloud web services (AWS) for app development, database storage solution, hosting solution etc.

Multi-cloud Spending: 8 Tips To Lower Cost

Mismanagement of multi-cloud expense costs an arm and leg to business and its management has become a major pain point. Here we break down some crucial tips to take some of the management challenges off your plate and help you optimize your cloud spend.

50 Data Science Jobs That Opened Just Last Week

Data Science and Analytics market evolves to adapt to the constantly changing economic and business environments. Our latest survey report suggests that as the overall Data Science and Analytics market evolves to adapt to the constantly changing economic and business environments, data scientists and AI practitioners should be aware of the skills and tools that the broader community is working on. A good grip in these skills will further help data science enthusiasts to get the best jobs that various industries in their data science functions are offering.

Learn Web Development (For Data Science)

Web development requires HTML for the structure and CSS for the visual design. Javascript adds functionality and is what most web frameworks like Angular and React are written in. TensorFlow also released their popular machine learning library in Javascript so you can integrate it straight into your site.