PaaS: Python as a Service

reflexión
Entregando python en la nube, más fácil que nunca.
Author

sebastiandres

Published

July 25, 2020

Technology changes and brings us many advantages. But the volume of knowledge to manage has become enormous: python, ipython, jupyter notebooks and their libraries on one side, and on the other side, servers, kubernetes, and an endless list of acronyms. Those who know all of this can make the most of it but… how can we make all these technologies available to a user who doesn’t know and doesn’t need to know about all of this?

Is there any way to deliver PaaS: Python as a Service?

Yes. There is a way that is simple both for the user and for the developer.

What are we looking for on the user side?

The simplest way for an eventual user is to create a library that can be installed with pip:

pip install la_libreria_que_hice_con_mucho_esfuerzo

That way a user could use the library with jupyter notebook, without installing anything locally, using mybinder or google colab. They could even use it from a tablet or phone!

A simple example: calculating who has the next birthday.

I have a good memory for some things, but birthdays are not among those things. It’s a family problem, and a reminder could probably be useful to more than one person. With a very simple python code I could implement a function that shows who the next 3 people to have a birthday are and calculates the age they are going to turn. How could I share that code with my family?

Very simple! With MyBinder or Google Colab.

It is possible to configure MyBinder (but not Google Colab) so that the library comes pre-installed by default.

What does the developer have to do?

There are several things we need in order to provide an easy service to users: * A pip-installable library: requires defining a setup.py file and properly configuring a folder structure. The code can be installed from pypi (official, stable) and github (edge). * Use git: allows keeping versions of the code and making incremental changes. * Simple interface: hide the complexity of the code with object orientation, exposing only what is strictly necessary. * Save parameters: when everything fails, it allows quick debugging (and reproducing the execution conditions). In the previous case, it helped me realize that Google Colab uses python 3.6.9 and that’s why certain recent functions of the standard datetime library were not available. * Documentation: for more advanced users and to document the library.

How does it work?

I packaged all of the above into a library that serves as a working framework, which you just download and customize. The library is on github and here is the documentation.

In short, the framework has best practices, libraries and resources pre-configured that allow you to comply with pip, git, simple interface, documentation and saving parameters, at least in the most minimal way possible.

Addendum December 7, 2023

More than 3 years after writing this post, all of the above can be solved much more easily with streamlit.