Practical Business Python

Taking care of business, one python script at a time

Sat 27 September 2014

Configuring Pelican Static Blog

Posted by Chris Moffitt in articles   


The first part of this series explains why I chose Pelican for this blog. This article goes into more detail around the steps I took to install and configure it for pbpython.

Install the base components

Similar to other tutorials, use virtualenv to install pelican into an isolated environment on the system:
$ mkvirtualenv pbpython-site
$ pip install pelican
$ pip install Pillow beautifulsoup4 cssmin cssprefixer cssutils pretty six smartypants typogrify webassets
Now do the pelican configuation:
$ pelican-quickstart

Please answer the following questions so this script can generate the files
needed by Pelican.

> Where do you want to create your new web site? [.]
> What will be the title of this web site? Practical Business Python
> Who will be the author of this web site? Chris Moffitt
> What will be the default language of this web site? [en]
> Do you want to specify a URL prefix? e.g.,   (Y/n) Y
> What is your URL prefix? (see above example; no trailing slash)
> Do you want to enable article pagination? (Y/n) Y
> How many articles per page do you want? [10]
> Do you want to generate a Fabfile/Makefile to automate generation and publishing? (Y/n) Y
> Do you want an auto-reload & simpleHTTP script to assist with theme and site development? (Y/n)
> Do you want to upload your website using FTP? (y/N) N
> Do you want to upload your website using SSH? (y/N) N
> Do you want to upload your website using Dropbox? (y/N) N
> Do you want to upload your website using S3? (y/N) Y
> What is the name of your S3 bucket? [my_s3_bucket]
> Do you want to upload your website using Rackspace Cloud Files? (y/N) N
> Do you want to upload your website using GitHub Pages? (y/N) N
Done. Your new project is available at /home/chris/src/pbpython-site

$ ls
content  Makefile  output

One additional thing I wanted to do is to make sure I have access to the pelican plugins on github.

Add the plugins:
$ git clone
$ ls
content  Makefile  output  pelican-plugins

I also wanted to make sure to install all the various themes so I could experiment and see what I liked best.


Ensure you use the

directive to clone the github repo

Add the themes:
$ git clone --recursive ./pelican-themes
$ ls
cache  content  Makefile  output  pelicanconf.pyc  pelican-plugins  pelican-themes

Now that these themes are available locally, you can view them by making the changes to your
file described below. In the example below, I set up the theme to use voidy-bootstrap but you can easily change this and see what other themes look like.

Add paths to the plugins and themes:
THEME = "pelican-themes/voidy-bootstrap"
PLUGIN_PATHS = ['pelican-plugins']
PLUGINS = ['assets']

I also wanted to set up some archives and use typogrify so I set those variables as well.

Additional config:
YEAR_ARCHIVE_SAVE_AS = 'posts/{date:%Y}/index.html'
MONTH_ARCHIVE_SAVE_AS = 'posts/{date:%Y}/{date:%b}/index.html'


Now you should have a basic environment set up. When you are ready to see how your site looks on your local machine, you can use the handy devserver to view it “live.”

Run the devserver:
$ make devserver

One of the benefits of using a static blog engine is that you can store all the relevant files in a version control system. I am partial to mercurial and use bitbucket for my code hosting.

I decided that there is no need to store the output file, so , here is what my
file looks like:
$ cat .hgignore
syntax: glob
Here is what the basic bitbucket screen looks like:
bitbucket files
There are two really cool features about saving the content on bitbucket:
  1. Bitbucket can interpret Restructured text files so it gives a nice rendering of the files.
  2. I can use the edit button to edit files directly.
bitbucket editing

Deployment and Hosting

The final piece of the static hosting blog puzzle is determining how to host the site. After doing some research, I decided to try hosting the files using Amazon’s S3 service.

After configuring the service according to the docs, I needed a method to sync the files. Installing and configuring

did the trick.

Configure s3:
$ pip install s3cmd
$ s3cmd --configure
Whenever I need to deploy files to the s3 instance, I execute the following commands:
$ make publish
$ s3cmd sync ./output/ s3:// --acl-public --delete-removed --guess-mime-type

Closing Thoughts

I hope this article helps you understand how to setup pelican for your own site and some of the advantages of using a static blog engine. Feel free to ask questions in the comments if anything is not clear.