reading-notes

Serverless Functions

Reading

Resources

Reference

Notes

What is Serverless?

Serverless is a type of computing that allows you to run code or applications without having to worry about managing the underlying servers. Instead of provisioning and maintaining servers to run your code, you can simply write and deploy your application to a cloud provider that handles all of the infrastructure for you. The term “serverless” does not mean “no servers”, but rather describes the experience of the developer; the server is invisible to them.

With a serverless model, you only pay for the resources you consume, such as the number of times your code is executed or the amount of computing time it consumes. This can be more cost-effective than running your own servers, since you only pay for what you use and don’t have to worry about the overhead of maintaining the infrastructure. In other words, developers never pay to idle capacity. The cloud provider spins the server up when code executes and “scales to zero” when done executing. This model is known as Functions-as-a-Service (FaaS).

Create a Virtual Environment

venv is a module in Python that allows you to create virtual environments. A virtual environment is a separate environment on your computer that allows you to install packages and Python modules in isolation from the global Python environment. This can be useful for a variety of reasons, such as:

You can also use the venv module to create virtual environments with different versions of Python. For example, you can use the --python flag to specify the path to a specific version of Python, like this: python3 -m venv myenv --python=python3.9. This will create a virtual environment that uses Python 3.9 instead of the default version of Python that is installed on your system.

How does a venv work?

When you create a virtual environment using the venv module, it creates a new directory on your computer that contains a copy of the Python interpreter, as well as a copy of the pip package manager. This allows you to have a separate Python environment that is isolated from the global Python environment on your system.

When you activate a virtual environment, the activate script modifies your shell’s PATH environment variable to include the directories for the virtual environment’s Python interpreter and pip executables. This ensures that when you run python or pip from the command line, the correct executables from the virtual environment are used instead of the ones from the global environment.

When you install a package using pip while a virtual environment is active, the package is installed in the virtual environment’s copy of the Python package directory, rather than the global package directory. This allows you to have multiple versions of the same package installed on your system, with each version installed in a separate virtual environment.

When you deactivate a virtual environment, the deactivate script modifies your shell’s PATH environment variable to remove the directories for the virtual environment’s executables. This ensures that you are using the global Python environment again until you activate another virtual environment.

Python and APIs

http.server — Base Classes for Implementing Web Servers

http.server uses classes from socketserver to create base classes for making HTTP servers.

Request Library for API Calls