Getting started with Python
Python is usually not installed on the database server. Instead, it runs within the Python runtime on your workstation or on an application server. When you use Python for data analytics in PostgreSQL, you need to install a specific library called psycopg2 on your workstation or application server. This library, when called from the Python runtime environment, will connect to the PostgreSQL server and handle traffic between your Python script and the database server. In its simplest form, once you connect to the PostgreSQL server using psycopg2, you can submit SQL to the database using Python scripts, in the same way that you would with psql.
While there are many ways to get access to Python, the Anaconda distribution of Python makes it particularly easy to obtain and install it along with other analytical tools, as it comes with many commonly used analytics packages preinstalled alongside a great package manager. For that reason, we will be using the...