Web Application Development with Streamlit: Develop and Deploy Secure and Scalable Web Applications to the Cloud Using a Pure Python Framework 1st Edition Mohammad Khorasani - The ebook in PDF and DOCX formats is ready for download now
Web Application Development with Streamlit: Develop and Deploy Secure and Scalable Web Applications to the Cloud Using a Pure Python Framework 1st Edition Mohammad Khorasani - The ebook in PDF and DOCX formats is ready for download now
com
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/secure-web-application-development-a-
hands-on-guide-with-python-and-django-1st-edition-matthew-baker/
ebookmeta.com
https://ebookmeta.com/product/the-american-war-in-afghanistan-a-
history-1st-edition-malkasian/
ebookmeta.com
Directed Evolution Methods and Protocols Methods in
Molecular Biology 2461 Andrew Currin (Editor)
https://ebookmeta.com/product/directed-evolution-methods-and-
protocols-methods-in-molecular-biology-2461-andrew-currin-editor/
ebookmeta.com
https://ebookmeta.com/product/managing-innovation-integrating-
technological-market-and-organizational-change-6th-edition-joe-tidd/
ebookmeta.com
https://ebookmeta.com/product/reassured-love-club-curve-club-curves-
series-1st-edition-jade-royal-2/
ebookmeta.com
https://ebookmeta.com/product/practical-leadership-in-community-
colleges-navigating-todays-challenges-1st-edition-george-r-boggs/
ebookmeta.com
https://ebookmeta.com/product/an-unexpected-love-a-variation-of-jane-
austen-s-pride-and-prejudice-lily-bernard/
ebookmeta.com
Web Application
Development with
Streamlit
Develop and Deploy Secure
and Scalable Web Applications
to the Cloud Using a Pure
Python Framework
Mohammad Khorasani
Mohamed Abdou
Javier Hernández Fernández
Web Application Development with Streamlit: Develop and Deploy Secure
and Scalable Web Applications to the Cloud Using a Pure Python Framework
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
x
Table of Contents
xi
Table of Contents
Bibliography�������������������������������������������������������������������������������������469
Index�������������������������������������������������������������������������������������������������473
xii
About the Authors
Mohammad Khorasani is a hybrid of
an engineer and a computer scientist
with a Bachelor of Science in Mechanical
Engineering from Texas A&M University and a
master’s degree in Computer Science from the
University of Illinois at Urbana-Champaign.
Mohammad specializes in developing and
implementing software solutions for the
advancement of renewable energy systems and services at Iberdrola. In
addition, he develops robotic devices using embedded systems and rapid
prototyping technologies. He is also an avid blogger of STEM-related topics
on Towards Data Science – a Medium publication.
linkedin.com/in/mkhorasani/
xiii
About the Authors
xiv
About the Technical Reviewers
Rosario Moscato has a master’s degree in Electronic Engineering
(Federico II University, Naples) as well as a master’s degree in Internet
Software Design (CEFRIEL, Milan). He also has a Diploma in Apologetics
(Pontifical Athenaeum Regina Apostolorum, Rome) and a master’s
degree in Science and Faith (Pontifical Athenaeum Regina Apostolorum,
Rome). Rosario has gained over 20 years of experience, always
focusing his attention on the development and fine-tuning of the most
innovative technologies in various international companies in Europe
and Asia, covering various highly technical, commercial, and business
development roles.
In recent years, his interest has focused exclusively on artificial
intelligence and data science, pursuing, on one hand, the goal of
enhancing and making every business extremely competitive by
introducing and supporting machine and deep learning technologies
and on the other hand, analyzing the ethical-philosophical implications
deriving from the new scenarios that these disciplines open up.
Rosario has authored two books, and he is a speaker at international
research centers and conferences as well as a trainer and technical/
scientific consultant on the huge and changing world of AI.
Currently, he is working as Senior Data Scientist with one of the biggest
multinational IT companies in the world.
xv
Acknowledgments
This undertaking would not have been possible without the support and
efforts of a selfless few. Individuals and entities who in one way or another
have made a contribution to the contents of this book are named as follows
in no particular order:
• Streamlit: The folks who created the framework itself,
empowering countless developers
• Iberdrola: Which provided the inspiration and time for
us to put Streamlit to a very noble use
• Iberdrola Innovation Middle East: The folks who served
as a test bed for our very first Streamlit ventures and
had to put up with our constant pitching of Streamlit’s
formidability
• Qatar Science & Technology Park: Which has fostered
an environment conducive to innovation and research
• Daniel Paredes, Jerome Dumont, Ana Martos, and
Gustavo López-Luzzatti: For being our very first
Streamlit users
• Dr. Nikhil Navkar: For being another trailblazing
Streamlit user
xix
Preface
Mind you, this anecdote of mine occurred in the summer of 2020, and
Streamlit had only been released to the public in the fall of 2019. But less
than a year of development by their team had rendered exactly the sort of
framework and API that I had hoped for. And ever since then, this product has
only been moving in one direction – upward, with a steep incline. For myself
personally, I could not have discovered it at a more auspicious time. I had just
been hired by Iberdrola and tasked with the audacious goal of creating and
deploying a Python-based application to the Web. In a pre-Streamlit world, I
would have fervently resisted the notion of deploying applications to the Web,
but armed with my new friend, I found myself routinely advocating for the
development of web applications while passionately brandishing Streamlit’s
untethering capabilities. Overnight, I had been transformed into a trailblazing
member of sorts within our development team.
With all good things in the world, it just does not feel right to proceed
without sharing the goodness with the world at large. Consequently, I
have made it a subtle goal in life to inform the online and offline software
development community of the empowerment that Streamlit ushers in. This
book is the culmination of that effort, and more specifically it is intended
for those who have faced the same hurdles as I have, and it will provide a
holistic overview of Streamlit. This book will guide the reader through the life
cycle of creating scalable web applications of their own, from the most basic
use cases to crafting complex and distributed applications on the cloud.
In addition to learning all the ins and outs of Streamlit itself, after
perusing this book, readers should be able to interface their web
applications with robust server-side infrastructure like MongoDB,
PostgreSQL, Linux, Windows Server, and Streamlit’s own deployment
platform. In a nutshell, you should be able to walk away from this book
feeling empowered enough to unleash your ideas and to embody them on
the Internet. Perhaps this could be the beginning of your next startup for
the curious inner entrepreneur in you.
Mohammad Khorasani
September 2021
xx
Acronyms
aaS As a service
API Application programming interface
BLOB Binary large object
CLI Command-line interface
CPU Central processing unit
CRUD Create, read, update, and delete
CSP Cloud service provider
CSRF Cross-site request forgery
CSS Cascading Style Sheet
DI Dependency injection, a coding pattern
DG Delta Generator, a core module in Streamlit
DOM Document Object Model
DTW Dynamic time warping
GPU Graphics processing unit
HTML Hypertext Markup Language
IDE Integrated development environment
ISP Internet service provider
JSON JavaScript Object Notation
JWT JSON Web Token
MLaaS Machine learning as a service
NAT Network address translation
ORM Object-relational model
OS Operating system
PID Process identifier
RCE Remote Code Execution
RDP Remote Desktop Protocol
xxi
Acronyms
xxii
Intended Audience
This book assumes that you have no less than a basic level of exposure and
understanding in the following areas:
• Object-oriented programming
–– Pandas
–– Numpy
–– Plotly
• Cloud computing
xxiii
Intended Audience
a robust web application in hours what would have previously taken you
weeks to produce in Flask or Django. In simpler terms, it offers a lot more
bang for the buck.
Notwithstanding, it is important to clarify that for those who are
looking for a means to deliver highly bespoke and tailored frontend user
interfaces, perhaps Streamlit is not what you should be scouting for. Not
that it will not address your needs someday, it is just that “someday” is
not today. Streamlit is a work in progress, and while their team perseveres
relentlessly, we should remain patient and expect a greater degree of
customizability alongside a multitude of additional features to be released
in the near future. Should you need something more amenable, then you
may find that Django is a more suitable option. Mind you, Django lands
you back in the realm of the predicament mentioned earlier, as you will
need to be a more advanced programmer to create web applications
with it.
Hopefully upon completion of this book, you should be equipped
with the tools that you will need to produce a scalable web application
deployed to the cloud from inception to deployment and operation. You
will become confident in addressing the functional and performance
requirements of developing both server-side and client-side software.
You will be able to create both backend functionality and frontend user
interfaces. In addition, you will learn to interface your software with
relational and nonrelational database systems such as PostgreSQL and
MongoDB in order to scale your application on demand. And finally, you
will acquire the technical know-how to orchestrate and provision your
scalable application on the cloud using Microsoft Server, Linux containers,
and Streamlit’s own cloud service.
While this book will go into great depth and breadth of the required
concepts, a degree of self-learning and research is still expected of any
reader. There will be gaps in tutorials, and perhaps some of the tools
used will be deprecated or obsolete by the time you are reading this
xxiv
Intended Audience
xxv
Additional Material
This book is accompanied with an abundance of online material
including repositories, datasets, libraries, APIs, and their corresponding
documentation. Wherever necessary and possible, the URL to the material
will be provided. All tutorials and source code included in this book will be
available at the following repository: https://github.com/. Finally, any
reference made to the Streamlit API can be additionally found on
https://docs.streamlit.io/library/api-reference.
xxvii
CHAPTER 1
Getting Started
with Streamlit
With 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.
Given that Python is currently the scripting language of choice for most
of the software development community, it is absolutely vital to provide
a web framework for developers that would bridge their skills gap. While
legacy frameworks such as Flask and Django solicit a firm understanding
of HTML and CSS, Streamlit is the first major framework that is all pure
Python, thereby reducing development time from weeks to hours.
2
Chapter 1 Getting Started with Streamlit
when you need multiple instances of the same computing resources and
vertical for when you need bespoke resources, the likes of GPUs, TPUs,
database systems, and more. Perhaps, the single most salient factor about
the cloud is that it expands your horizons and allows you to offer your
product as a service on the World Wide Web. The latest paradigm shift in
tech is to offer quite literally anything as a service. The as-a-service model
(aaS) can be applied to software (SaaS), machine learning (MLaaS), and
any other product that can be offered as a web application on the Internet.
And this is precisely where a web framework such as Streamlit fits the bill.
Streamlit is a cloud enabler for those of us in the software development
community that have been unable to deploy our value to the Internet due
to a hefty skills gap that has thus far impeded us from doing so. Concisely
put, Streamlit is a means of empowerment for developers at all levels.
3
Chapter 1 Getting Started with Streamlit
more enticing. Equipped with the cloud, CSPs are able to pool resources
together, increase resource elasticity, and reduce maintenance and
overheads. And perhaps most importantly, from a consumer’s point of
view, the cloud is the best thing that ever happened since the Internet
itself. As a consumer, the SaaS model offers unparalleled flexibility, price
granularity, and plenty more bang for the buck. In other words, the cloud is
win-win-win; everyone stands to gain.
While the trend toward cloud computing was already on a healthy
trajectory, a once-in-a-century pandemic doubled as a booster toward
everything cloud. The pandemic all but destroyed the stigma associated
with remote learning, online examinations, working from home, and
other dogma that decades of noble efforts by the tech community had
failed to make a dent into. It is fair to assume that from here onward, the
progression toward everything cloud will exceed the prediction of pundits.
And if numbers alone can serve to indicate where we are heading, then
one should feast themselves on the omen of Figure 1-1.
Figure 1-1. Growth of the public cloud computing market from 2008
to 2020. Source: statista.com [13]
4
Chapter 1 Getting Started with Streamlit
5
Chapter 1 Getting Started with Streamlit
1.1.4 Flask
Flask was developed in 2010 by Armin Ronacher from what was
allegedly an April fool’s joke to begin with. Flask is a nonfull-stack or
microframework that provisions an application server without offering
much else in terms of components. Flask is composed of two main
elements: Werkzeug, a tool that lends support for HTTP routing, and Jinja,
a template engine used to render basic HTML pages. In addition, Flask
uses MarkupSafe as a string handling library and ItsDangerous as a secure
data serialization library to store session data as cookies.
Flask is a minimalistic framework that is equipped with the bare
minimum of the components required to render a web application.
Consequently, the developer is afforded a great deal of autonomy and
also responsibility to create their own application. As a result, Flask is best
suited for static websites and for experienced developers who are able to
provision most of their own infrastructure and render their own interfaces.
1.1.5 Django
Django was developed by a group of web programmers in 2003 who
used Python to build web applications. It allows developers to create
complex applications with relatively less overhead in comparison to Flask.
Specifically, Django enables programmers to render dynamic content
with enhanced scalability and with in-house capabilities to interface with
database systems using object-relational mapping.
In addition, there are a host of other modules including but not limited
to ecommerce, authentication, and caching packages that allow the
developer to readily provision extended services. Bundled with a multitude
of other third-party packages, Django allows the developer to focus mainly
on the idea while not having to worry much about the implementation.
6
Chapter 1 Getting Started with Streamlit
1.1.6 Dash
Dash is a web framework developed by Plotly to render enterprise-
grade web applications in Python, R, and even Julia. Given that Plotly
predominantly develops data analytics and visualization tools, similarly
Dash is more often used to create dashboards. Even still, it is indeed
possible to create a host of general-purpose applications with due to its
extended customizability.
Dash has the ability to natively support D3.js charts and provides
default HTML and CSS templates to use. However, for more tailored
interfaces, developers must be well versed with frontend programming
themselves. Furthermore, Dash tenders an enterprise package that
enables experienced developers to deploy their applications on the cloud
with production-grade capabilities such as authentication and database
systems.
1.1.7 Web2Py
Web2Py is a full-stack web framework for Python which like Django
makes use of the model view controller architectural paradigm. It allows
developers to create primitive yet dynamic content with relative ease and
interfaces natively with database systems. The novelty of this framework
as opposed to others is that it comes with its own web-based integrated
development environment equipped with a ticketing system for error
tracking and management.
The main disadvantage however is that Web2Py executes objects
and controllers via a single global environment that is initiated at each
HTTP request. While this has its benefits, it does also carry the pitfalls of
experiencing compromised performance and incompatibility issues with
certain modules.
7
Chapter 1 Getting Started with Streamlit
1.1.9 Academic Significance
Being able to create web apps directly from Python easily has made
Streamlit a valuable tool for academia [1]. Despite its recent creation,
the first beta release is dated April 2019; research teams worldwide
have started adopting the framework to showcase the outcomes of their
projects. Today, many publications already mention Streamlit as their
visualization framework covering a wide range of fields. Some of these
areas include health [2, 3, 4, 5], computer science [6, 7, 8, 9], economics
[11, 10], and civil engineering [12], to mention a few.
8
Chapter 1 Getting Started with Streamlit
1.2 Firing It Up
Being the highly versatile and accommodating framework that it is,
Streamlit allows the developer to utilize it with a variety of computing
resources and technical stack. Even still, there are some recommended
best practices to follow for greater ease and usability.
1.2.1 Technical Requirements
While there is no one-size-fits-all solution when it comes to running
Streamlit, the following computing and system requirements or greater are
recommended for developing and running applications smoothly.
9
Chapter 1 Getting Started with Streamlit
Programmatic Installation
To create an Anaconda environment through the console, please follow
these steps:
proceed ([y]/n)?
10
Chapter 1 Getting Started with Streamlit
cd C:/ProgramData/Anaconda3/envs/<environment name>/
11
Chapter 1 Getting Started with Streamlit
conda list
conda deactivate
Graphical Installation
Alternatively, you may use Anaconda Navigator to create and maintain
your environments as follows:
12
Chapter 1 Getting Started with Streamlit
13
Chapter 1 Getting Started with Streamlit
14
Chapter 1 Getting Started with Streamlit
15
Chapter 1 Getting Started with Streamlit
https://pypi.org/project/streamlit/
cd C:/Users/.../
If the installation has been successful, you may proceed with creating
your script. For good measure, restart Anaconda before you do so.
Importing Streamlit
To import Streamlit into your Python script, ensure that the following line
precedes the rest of your code:
import streamlit as st
st.write('Hello world')
16
Discovering Diverse Content Through
Random Scribd Documents
The Project Gutenberg eBook of An English girl
in Japan
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
SECOND EDITION
Illustrated
LONDON
WELLS GARDNER, DARTON & CO., LTD.
3, PATERNOSTER BUILDINGS, E.C.
First Edition, May, 1904
Second Edition, June, 1906
TO
MY FRIEND MARY
A SOUVENIR
The following sketches of life in Japan and the voyage there and
back are taken from a diary which I kept during my travels.
Since writing my little book of personal reminiscences, which,
thanks to indulgent readers and kind friends, is now republished in a
second edition, many and great changes have taken place in the Far
East.
Japan has now become a great Power--not only in the East, but
also in the West. It is little Japan no longer; or, rather, its greatness
is now understood and acknowledged by all the world. Western
civilization has taken a firm hold on the Japanese people. They have
been rapidly adopting, and, in fact, improving on, Western methods,
customs, and manners. The fear of the globe-trotter of to-day is
whether he will be in time to see the Japan of his dreams and of
romance, before this great Western wave of progress and reform has
divested the Land of the Rising Sun of its quaint originality and
fascinating charm.
E. H. B.
1906.
PREFACE TO FIRST EDITION
The following sketches of life in Japan and the voyage there and
back are taken from a diary which I kept during my travels.
As Japan and its wonderful little people have come so much
before the world during the last few years, and especially at this
time are one of the chief factors in the crisis in the Far East, I
thought that these reminiscences and anecdotes taken from real life
might be of interest.
I am indebted to the editors of the Cornhill, Sketch, Sunday, and
the Buenos Aires Standard for the reproduction of some of the
following sketches.
ELLA HART BENNETT.
1904.
CONTENTS
CHAPTER I
ON THE WAY
PAGE
I start on my travels--A fair Theosophist--Life on an 1–12
American liner--Arrival at New York--Delmonico’s---
The Hotel Waldorf--Niagara Falls--Across the Lakes--
The prairies--A quiet Sunday
CHAPTER II
IN THE ROCKIES
CHAPTER III
EARLY DAYS IN JAPAN
CHAPTER IV
A JAPANESE HARROGATE
CHAPTER V
AN IMPERIAL GARDEN-PARTY
CHAPTER VI
JAPANESE LADIES
CHAPTER VII
JAPANESE CHILDREN
CHAPTER VIII
SERVANTS IN JAPAN
Their politeness--Frequency of their baths--Always 98–108
ready for a nap--Mrs. Peter Potts
CHAPTER IX
SOME FESTIVALS AND A FUNERAL
CHAPTER X
CHANG, MY CHOW
CHAPTER XI
FURTHER ADVENTURES OF CHANG
CHAPTER XII
PAUL AND VIRGINIA
PAGE
A little Nasan appeared Frontispiece
In the Heart of the Rockies 15
‘Tum adain soone! sayonara!’ 26
One of the Shinto Temples 27
The Great Bronze Buddha 28
We start for Kodzu 35
Idaka, the Guide 39
Prepared for the Night 47
Our Invitation-cards were very large and thick 53
The Gardens are very beautiful 57
Quaint Signboards in some of the Streets, Tokio: 63
Butcher’s, Umbrella Shop
Quaint Signboards in some of the Streets, Tokio: Poultry 64
and Egg Shop, Japanese Tailor
‘Many are distinctly pretty when young’ 68
A Japanese Lady of the Upper Class 69
A Tea-house Veranda 72
‘How picturesque they looked!’ 84
Japanese Children 87
Japanese Servants 99
That Delightful Hotel in the Hills 102
Three Friends 125
The Garden of the Little Tea-house 129
The Kind Old ‘Isha-san’ 133
The Little House in the Forest 137
Chang’s First Appearance 140
Yum-Yum and Dodo 141
The Monastery in the Rock 143
Mystical ‘Fuji-Yama’ 151
The Lotus Flower of Japan 154
Arara 173
Initials, Tailpieces, etc.
An English Girl in Japan
CHAPTER I
ON THE WAY