The Well-Grounded Python Developer
If you want to learn how to make your own website in Python using Flask, this is a good book.
A confluence of a couple things recently led me to read this book. If you've been following my blog for some time, you'll know I have been trying to teach myself Python. I think it's useful for data analysis, CI scripting, and a way to generally expand on LabVIEW's capabilities. I'm also using it as a hedge against becoming overly reliant on NI and LabVIEW. In addition to learning Python, I've also been interested in learning more about web development lately.
Why Learn Web Development?
I've also been doing a lot of CI/CD work lately and it occurred to me that there might be a market for some sort of CI/CD as a service business in the LabVIEW world. Setting up and maintaining LabVIEW runners can be painful. I had imagined developers might be interested in some sort of web portal solution.
You log onto a web portal. You tell it you need a LabVIEW runner and fill out a form that selects what version of LabVIEW and additional drivers you need. Maybe you can supply a vipc file. Somehow on the backend, it connects to GitLab (or perhaps GitHub) and suddenly you have access to a new runner that's already configured. No setting up your own separate machine or VM and manually installing everything making sure everything can talk to each other. It's all done for you, all you have to do is specify a tag in your yaml file. That is the vision.
I realized that doing something like that would require some web development skills and I didn't have any. If that idea ever took off, I would probably hire some web developers. Yet in the beginning, having some web skills of my own would be useful so I could do some prototyping and get a simple proof of concept going before I chose to invest too much into the idea.
Web development skills could also be useful for cRIOs and other embedded targets. They often run headless and some sort of web server may be a better fit for certain uses as opposed to developing your own HMI that runs on a separate Windows machine. A little web interface doesn't require installing anything - no app, no run-time engine - and doesn't impose any OS or hardware requirements. You can easily access it from any phone, tablet, or laptop. All you need is a web browser.
Back to the Book
This particular book combines learning good habits in Python with Flask Web Development. It seemed to combine the 2 things I wanted to learn: Python and Web Development. After reading the book I haven't become an expert in either and I did gain some useful skills and insights.
I thought the book was well done. The first couple of chapters were a pretty easy review of some general Python and software engineering best practices. I wasn't terribly impressed with them and I am not the target audience. Once it got into Flask itself I found it much more interesting and well laid out.
The Flask lessons are all built on top of each other. The end product was a functioning blog site. The first lesson started with a very basic Hello World application. Subsequent lessons added some code organization and modularity and then templates and a little JavaScript formatting to make it look nicer. One section about configuration and debugging. The lessons then progressed to login and authentication, which required some persistence. There was a lesson on ORMs to map a database to Python Objects. Each lesson built on the previous introducing small bits at a time.
At first, I had some difficulty getting each example to work. That was mostly pilot error. I somehow missed the reference to the appendix, which describes how to use pyenv
to set up the dependencies for each chapter. I had not heard of pyenv
and it was one of the more useful things I learned about. It's a utility for installing specific versions of Python. It is a compliment topython -m venv
, not a replacement. You use pyenv
to install and specify a specific Python version and then use venv
to create a virtual environment to isolate the Python Packages.
I liked the examples while at the same time, I found them complicated. There were a lot of moving parts going on. The examples used BootStrap as a JavaScript framework and I was not very familiar with it. They also used Jinja templates, which I was somewhat familiar with. For persistence the example blog used SQLLite, which I am familiar with. I was able to fire up the SQLite browser and see what was going into the database on the backend. That was useful. The blog used SQLAlchemy as the ORM layer. I was not familiar with that. I need to play around with it more. I was very familiar with SQL from some previous reading, and the whole ORM idea kind of went over my head a bit. That may be because I was actually trying to understand how it worked behind the scenes, instead of just accepting that it transforms a SQLite db into a series of Python objects.
Part of my lack of fully understanding the examples was because full solutions were provided so I didn't feel the need to type everything out myself. If I had, perhaps I would have learned a little more. I learn much better by doing than by reading. I did get the general idea though. I'm also confident that if I had to develop a website using Flask, I could pull enough out of the book to make it work and do a pretty good job at it. It might not be the most professional site and it would be a good prosumer-level effort. I would feel pretty comfortable writing a web-app interface for a cRIO that was running behind a firewall and maybe making a prototype of a CI/CD runner manager, again running behind a firewall.
Why Read This Book?
If you want to learn to build a simple website using Flask this is a good book. If you are looking just to simply be a better Python programmer in general, there are probably better books out there. If you are looking to augment your LabVIEW programming skills with Python, unless you are planning on doing some web stuff, I would recommend some other books like:
They are more approachable. The examples are simpler and have less moving parts.
CI/CD Runners as a Service
If CI/CD runners as a service sounds interesting or you just want help setting up CI/CD for LabVIEW in general let's talk. Use the connect button below to reach out.