Pelican is a Python based static website generator written in Python. Using Pelican, one can start creating static websites that can later be deployed to a simple file web server on the cloud. Some of the cloud web service providers include Amazon Web Services, Digital Ocean, Vultr etc. One can also host these static websites on a static host providers such as Netlify, Contentful etc. But first, lets understand more about static websites and how to use Python’s Pelican to create your static website.
What is a static website and why should you use one?
The internet today is made up of both dynamic websites as well as static websites. A dynamic website is one which usually consists of a database and the server creates dynamic html web pages on the fly, usually specific to the user who requested it. On the contrary, a static website is made up of contents that are just that – static and is served as the same to all its requesting users.
So which one should you be using for your usecase? A static website or a dynamic website? To answer this question, you should first look into this article that discusses the advantages and disadvantages of a static vs dynamic website.
So with the above introduction, its time to move into the technical aspects of Pelican. First let us discuss about the installation aspect of Pelican.
How To Install Pelican
Jump to the end of this article if you just want a one click installer to install and try Pelican
In order to install Pelican, you need to have both pip and Python installed on your system. If you dont have them installed, you can do so using the following commands:
sudo apt-get install python3 python3-pip
For Fedora Linux
sudo yum install python3 python3-pip
In this installation process, we are using Python 3 version. However note that Pelican works on both Python 2.7 as well as latest version of Python 3, so which one to use is solely left to your discretion.
Once Python and Pip are installed, we can proceed with installing Pelican onto our computers. To do so, we issue the following command:
pip3 install pelican markdown
We can note here that we are installing two Python packages from pip, one is the Pelican static site generator and the other is a markdown package. If you are unfamiliar with markdown, it is a set of standard markup language used to write contents in a way that can later be processed to format the content it surrounds. You can read more about Markdown on Wikipedia.
Once they are installed, we can create a new directory using command line to store our project files. In this case, we are creating a directory called Pelican_Demo and then moving to it.
mkdir Pelican_Demo cd Pelican_Demo
Once inside the newly created directory, we start creating our Pelican website. To do so, we call a Python executable script called pelican-quickstart that was installed to us in our /usr/local/bin directory. So we can run this script simply by calling it as follows:
This would kick start our Pelican static website generator which then proceeds with a series of questions that you need to answer to finally create your static website.
What these set of questions actually does to your Python based Pelican static website will be a topic for another post. But for now, you should be good to go using your website.
If you want to just get your hands dirty and try to get Pelican up and running without wanting to dig deeper into investigating how it works, then you can use the following script to get going.
This script will install all the required packages and answer all the questions of pelican-quickstart automatically for you so that you can simply run it and jump to view the newly created Pelican static website. Follow the instructions given in that Python3-Pelican-Installer github project to get it up and running in no time to get a taste of what Pelican static website looks and feels like.