Web Application Development with Streamlit
Develop and Deploy Secure and Scalable Web Applications to the Cloud Using a Pure Python Framework
- 2022
- Book
- Authors
- Mohammad Khorasani
- Mohamed Abdou
- Javier Hernández Fernández
- Publisher
- Apress
About this book
Transition from a back-end developer to a full-stack developer with knowledge of all the dimensions of web application development, namely, front-end, back-end and server-side software. This book provides a comprehensive overview of Streamlit, allowing developers and programmers of all backgrounds to get up to speed in as little time as possible.
Streamlit is a pure Python web framework that will bridge the skills gap and shorten development time from weeks to hours. This book walks you through the complete cycle of web application development, from an introductory to advanced level with accompanying source code and resources. You will be exposed to developing basic, intermediate, and sophisticated user interfaces and subsequently you will be acquainted with data visualization, database systems, application security, and cloud deployment in Streamlit.
In a market with a surplus demand for full stack developers, this skill set could not possibly come at a better time. In one sentence, Streamlit is a means for the empowerment of developers everywhere and all stand to gain from it.
What You’ll Learn
Mutate big data in real-timeVisualize big data interactivelyImplement web application security and privacy protocols Deploy Streamlit web applications to the cloud using Streamlit, Linux and Windows servers
Who is this Book for?
Developers with solid programming experience wanting to learn Streamlit; Back-end developers looking to upskill and transition to become a full-stack developers; Those who wish to learn and become more acquainted with data visualization, database systems, security and cloud deployment with Steamlit
Table of Contents
-
Frontmatter
-
Chapter 1. Getting Started with Streamlit
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezGetting Started with Streamlit delves into the benefits of cloud computing and the role of Streamlit as a pure Python web framework. It compares Streamlit with legacy frameworks like Flask and Django, emphasizing Streamlit's ease of use and rapid development capabilities. The chapter also covers the installation and basic usage of Streamlit, setting the stage for more advanced topics in subsequent chapters.AI Generated
This summary of the content was generated with the help of AI.
AbstractWith the inundation of data, and the pace at which it is created, traditional computing methods possess limited means to deliver results. On the other hand, cloud computing acts as an enabler, allowing one to overcome the limitations of the former. With increased scalability, reduced costs, and enhanced adaptability, cloud service providers, developers, and users alike stand to gain from the fruits of migrating to the cloud. -
Chapter 2. Streamlit Basics
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThis chapter introduces the basics of Streamlit, a powerful tool for creating web applications. It covers essential techniques such as creating input forms, implementing conditional flow, managing errors, and mutating dataframes. Additionally, it demonstrates how to render static and interactive charts, and develop user interfaces. The chapter concludes with a summary of the key concepts and a preview of more advanced topics to come. By the end of this chapter, readers will be equipped with the skills to create and deploy their own web applications using Streamlit.AI Generated
This summary of the content was generated with the help of AI.
AbstractStreamlit has made it thoroughly simple to create interfaces, display text, visualize data, render widgets, and manage a web application from inception to deployment with its convenient and highly intuitive application programming interface showcased in the Appendix. With the techniques covered in this chapter, one will learn how to create input forms, implement conditional flow, manage errors, mutate dataframes, and render basic charts. And upon completion of Streamlit basics, a developer should be able to produce, manage, and control a variety of trivial web applications and to deploy them locally. Such applications include but are not limited to data explorer, machine learning, multimedia, data wrangling, and other general-purpose applications. Once the developer has mastered the basics of Streamlit, they may then begin to develop more advanced and nontrivial applications that will be addressed in subsequent chapters. -
Chapter 3. Architecting the User Interface
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThis chapter delves into the architecture and customization of user interfaces in Streamlit, a powerful framework for developing web applications. It discusses how Streamlit allows developers to focus on backend logic while the framework handles the frontend implementation. The chapter covers the customization of color schemes, fonts, and layouts both programmatically and graphically, enabling the creation of bespoke user interfaces. Additionally, it explores advanced features such as placeholders for dynamic content, progress bars for real-time updates, and the creation of multipage and subpage applications. The chapter also provides best practices for folder structuring and modularizing application development, making it a valuable resource for developers looking to create efficient and scalable Streamlit applications.AI Generated
This summary of the content was generated with the help of AI.
AbstractWith Streamlit, the developer is able to focus on implementing their backend logic while leaving the frontend implementation largely to the framework itself. In addition, using Streamlit you can render responsive interfaces for PC, tablet, and mobile platforms at your fingertips with no added overhead. However, should one need to develop more bespoke and tailored applications, Streamlit affords a considerable degree of customization of its frontend design to the developer without soliciting any knowledge of HTML, CSS, or JavaScript. One may configure their application using a multitude of color schemes, fonts, and appearances both graphically and programmatically. -
Chapter 4. Data Management and Visualization
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThis chapter delves into the essential methods for managing and visualizing big data in web applications. It covers the encoding of large multimedia files and dataframes into bytes data for robust storage, leveraging Streamlit’s caching capabilities to enhance execution efficiency, and demonstrating the utility of the Plotly library for creating interactive and visually appealing charts. By providing hands-on techniques and examples, this chapter equips professionals with the tools necessary to handle and visualize data effectively, ensuring both efficiency and robustness in their applications.AI Generated
This summary of the content was generated with the help of AI.
AbstractAs with any web application, the management of data is an integral part of the undertaking. Coupled with the rise in big data, we are constantly in need of developing techniques that can manage the sheer magnitude of our data in an efficient and robust manner. In this chapter, we will address some of the key methods used to manage big data. Namely, we will cover encoding large multimedia files and dataframes into bytes data that can then be stored more robustly on database systems or in memory. Subsequently, we will demonstrate the utility of Streamlit’s in-house caching capabilities that can be used to cache data, function executions, and objects in order to drastically reduce execution time on reruns of our application. Finally, we will cover techniques to mutate dataframes and tables in our application on demand. -
Chapter 5. Database Integration
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThis chapter delves into the essentials of database integration, focusing on relational and nonrelational systems. It begins with an introduction to SQL and relational databases, using PostgreSQL as the primary tool. The chapter covers the basic CRUD operations and demonstrates how to connect PostgreSQL to Streamlit for data visualization and manipulation. Additionally, it explores advanced features like fuzzy matching and full-text indexing. The second half of the chapter introduces MongoDB, a popular nonrelational database, and shows how to integrate it with Streamlit for handling unstructured data. The chapter concludes with practical examples and code snippets, making it a valuable resource for professionals looking to enhance their data management skills.AI Generated
This summary of the content was generated with the help of AI.
AbstractBefore we begin to utilize application data and user interaction insights, we need to learn how to store and manage data of varying schemas persistently with the use of robust and distributed database systems in an organized manner. Two types of database systems will be discussed in detail, namely, relational and nonrelational databases. Examples of interfacing with PostgreSQL and MongoDB will be shown to demonstrate the use cases for each. In addition, advanced features such as fuzzy matching and full-text indexing will be exhibited, and boilerplates will be provided to the reader to use as building blocks for their own applications. Finally, the reader will also learn how to seamlessly interface such databases with Streamlit to visualize data and to execute create, read, update, and delete operations on their data. PostgreSQL and pgAdmin installation is required for full understanding in this chapter. -
Chapter 6. Leveraging Backend Servers
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThis chapter delves into the importance of backend servers in web application development, emphasizing the need to offload database management from the frontend to enhance security and modularity. It covers the fundamentals of frontend-backend communication, focusing on HTTP protocols and methods. The chapter also introduces JSON as a widely used data format in APIs and demonstrates how to build a Pythonic backend server using Flask. Additionally, it explores techniques for optimizing application performance through multiprocessing and multithreading. The chapter concludes with a practical example of connecting a Streamlit application to a backend server, showcasing the end-to-end process of building a secure and efficient web application architecture.AI Generated
This summary of the content was generated with the help of AI.
AbstractIn this chapter, we will introduce a more sophisticated and scalable way of designing web applications. Specifically, this chapter will present the process to offload the overhead associated with managing databases from the Streamlit server and onto an independent backend server as it should be in a full-stack environment. To that end, this chapter will walk the developer through the entire process of provisioning a backend server in Python that acts as the middleman between the database and the frontend. And finally, the developer will be acquainted with the workings of a highly modular, versatile, and secure architecture with additional security layers between the application and database. -
Chapter 7. Implementing Session State
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThe chapter delves into the crucial aspect of implementing session state in Streamlit applications, which is essential for developing more advanced and user-friendly applications. It covers the native method introduced in Streamlit version 0.84.1 for managing session-specific data, including variables, widgets, and objects. The chapter also explores the use of cookies for storing state across multiple sessions, ensuring a seamless user experience. Additionally, it introduces session IDs to provide personalized experiences and demonstrates how to store session state persistently using a PostgreSQL database, enabling the retrieval of historical states and generating user insights. Practical examples and code listings are provided to illustrate these concepts, making the chapter a valuable resource for developers looking to enhance their Streamlit applications.AI Generated
This summary of the content was generated with the help of AI.
AbstractIn order to develop more advanced Streamlit applications, it is vital to establish session-specific data that can be utilized to deliver a more enhanced experience to the user. Specifically, the application will need to preserve the user’s data and entries using what is referred to as session states. These states can be set and accessed on demand whenever necessary, and they will persist whenever the user triggers a rerun of the Streamlit application or navigates from one page to another. In addition, we will establish the means to store state across multiple sessions with the use of cookies that can store data on the user’s browser to be accessed when they restart the associated Streamlit application. Finally, we will learn how to record and visualize rich insights of how users are interacting with our application, to provide analytics to both the developer and product owner alike. -
Chapter 8. Authentication and Application Security
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThe chapter begins by introducing the necessity of secure user authentication for a production-ready Streamlit web application. It delves into the creation of admin accounts, password hashing using Bcrypt, and the implementation of JWTs for stateless authentication. The middleware is developed to intercept and authenticate requests, ensuring that only authorized users can access sensitive data. Additionally, the chapter highlights best practices for securing application secrets and preventing SQL injection attacks. The final sections discuss the importance of managing secrets securely and configuring Git to exclude sensitive files from version control. This chapter provides a thorough and practical approach to enhancing the security of web applications, making it a valuable resource for developers aiming to build robust and secure software solutions.AI Generated
This summary of the content was generated with the help of AI.
AbstractAfter acquainting ourselves with the necessary building blocks of a well-structured Streamlit web application, we require an additional feature to deploy a production-ready application, namely, a secure user authentication service. Once all users requesting access to the application are authenticated, we can guarantee a secure user experience whereby private data is safe and any unwelcome or malicious requests are formidably denied. In this chapter, we will learn how to establish user accounts, verify user actions, and implement other housekeeping measures that are expected of any well-versed software engineer. -
Chapter 9. Deploying Locally and to the Cloud
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThis chapter delves into the intricacies of deploying Streamlit applications, both locally and to the cloud. It begins by explaining how to expose a local Streamlit application to the Web, including methods like port forwarding and HTTP tunneling using Ngrok. The chapter then transitions to cloud deployment, focusing on Streamlit Cloud, which simplifies the process to a single click. Additionally, it covers secure data storage using Streamlit’s Secrets Management and provides comprehensive guides for deploying applications on Linux containers and Windows Server. Throughout, the chapter offers practical examples and detailed instructions, making it an invaluable resource for anyone looking to expand the reach of their Streamlit applications.AI Generated
This summary of the content was generated with the help of AI.
AbstractAs you approach the end of the development phase with your Streamlit application, it is time for it to see the light for the first time. In other words, you are ready to deploy the application and unleash your goodness to the world at large. To that end, you will need a machine to serve your application continuously, robustly, and resiliently. And while you can transform your local machine into a server of sorts, you are better off deploying the application to the mighty cloud, with the likes of Amazon Web Services, Microsoft Azure, Google Cloud Platform, and last but not least Streamlit itself. -
Chapter 10. Building Streamlit Components
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThe chapter 'Building Streamlit Components' delves into the process of creating tailored components in Streamlit using ReactJS. It begins by explaining the basics of integrating ReactJS components into Streamlit applications, highlighting the flexibility and power of this approach. The chapter then walks through the steps to build, use, and share custom components within a Pythonic context, demonstrating how to enhance the user interface and functionality of Streamlit applications. Additionally, it covers advanced topics such as bidirectional data communication between Streamlit and ReactJS components, publishing components as pip packages, and showcasing a collection of intricate Streamlit components from the Extra-Streamlit-Components library. The chapter is particularly valuable for developers looking to extend the capabilities of their Streamlit applications with custom components, offering practical examples and insights into best practices.AI Generated
This summary of the content was generated with the help of AI.
AbstractStreamlit regularly extends its features to incorporate additional capabilities that can be utilized by developers in a few short lines of code. At some point however, developers will need to take matters into their own hands and build something tailored to address their own specific user requirements. Whether this is to modify the user interface or to offer a bespoke experience to the user, Streamlit allows the developer to create custom components on demand. Furthermore, Streamlit supports using ReactJS as a wingman to build components that can be used as a live web server or built using deployment-ready code. In this chapter, we will walk through the steps required to make new Streamlit components, to use them in a Pythonic context, and to share them with the general public. -
Chapter 11. Streamlit Use Cases
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThe chapter begins by introducing several use cases of Streamlit, such as data visualization and real-time dashboards. It then delves into more advanced applications, including interfacing with external devices like Arduino and sensors for real-time data collection and control. Additionally, the chapter covers the development of a data warehousing application using Streamlit and concludes with a comprehensive guide to creating a machine learning application as a service. Each section is designed to provide practical insights and code examples, making it a valuable resource for professionals looking to expand their skills in web development and data science.AI Generated
This summary of the content was generated with the help of AI.
AbstractIn this chapter, we will cover several real-world use cases of Streamlit, including but not limited to applications related to data visualization, real-time dashboards, and time-series analysis. Additionally, we will introduce methods to interface our Streamlit application with external subsystems such as an Arduino microcontroller, infrared temperature sensor, and a sonar. Interfacing with physical devices and peripherals will enable us to scale Streamlit into an entirely new dimension where we can develop not only digital applications but also applications for embedded systems. For instance, we can create an operations dashboard to monitor the temperature of a building remotely or to control a valve motor in a factory line. The utility is quite literally endless. And finally as the culmination of everything we have learned thus far in this book, in the final section of this chapter the reader will be guided on how to utilize many of the techniques covered previously, to develop an advanced machine learning application. -
Chapter 12. Streamlit at Work
Mohammad Khorasani, Mohamed Abdou, Javier Hernández FernándezThis chapter delves into two compelling real-world applications of Streamlit, showcasing its potential in diverse industries. The first case study focuses on Iberdrola, a leading renewable energy firm, which leverages Streamlit to develop a data manager application for wind farms. This application enables the estimation of electrical losses and provides valuable insights from SCADA data, streamlining operational performance analysis. The second case study involves maxon Group, a manufacturer of high-precision electronic motors, which utilizes Streamlit to create a command and control dashboard for a surgical scope adapter system. This dashboard allows for real-time monitoring and remote control of motors, demonstrating the flexibility and power of Streamlit in industrial applications. Both case studies underscore the practical benefits and broad applicability of Streamlit in enhancing data management, visualization, and control systems, making it an invaluable tool for professionals across various sectors.AI Generated
This summary of the content was generated with the help of AI.
AbstractThis final chapter introduces two real-world cases that have taken advantage of Streamlit to develop web applications in some capacity. The first case covers the technical development of a data manager application for wind farms for Iberdrola – a renewable energy firm. We can observe how this application is being used to estimate electrical losses during production and to obtain valuable insights from Iberdrola’s SCADA data. The second case divulges the utility of Streamlit for industrial applications with maxon Group – a manufacturer of high-precision electronic motors. Specifically, we can see that Streamlit can be used to create a command and control dashboard application to control the maxon motors of a surgical scope adapter system both locally and remotely. -
Backmatter
- Title
- Web Application Development with Streamlit
- Authors
-
Mohammad Khorasani
Mohamed Abdou
Javier Hernández Fernández
- Copyright Year
- 2022
- Publisher
- Apress
- Electronic ISBN
- 978-1-4842-8111-6
- Print ISBN
- 978-1-4842-8110-9
- DOI
- https://doi.org/10.1007/978-1-4842-8111-6
Accessibility information for this book is coming soon. We're working to make it available as quickly as possible. Thank you for your patience.