Generate Color Palettes Automatically Using Python & Pixabay
Get instant access to the best color palettes for your next project
Hello World!

Today we are going to have a look at how to use Python to generate a color palette from a series of pictures. For this tutorial we are going to:
- Download a bunch of pictures using the Pixabay API
- Extract the colors from the images using colorgram
- Build an HTML page showing the results

As usual, I’ll divide the post into paragraphs so feel free to skip ahead.
0. Requirements and Target
For this tutorial you’ll need:
- Python 3.x
- The following packages: colorgram.py and requests_html
We are going to install the requirements (except for Python) in the next step.
The tutorial is targeted at:
- Python intermediate programmers
- People who work a lot with reporting and want a quick way to generate a color palette starting from a picture
1. Installing the requirements
colorgram
The first thing we need to install is colorgram:
Colorgram is an awesome package capable of extracting colors from an image. This is the package we are going to use to generate the colors for our palette.
To install the package just paste this line into your terminal:
pip install colorgram.pyrequests_html
The second package we need for this example is requests-html. Requests-html is, it is a library intended to make web scraping as easy and intuitive as possible. This is what we are going to use to download the pictures we need from the Pixabay API.
To install this package just paste this into your terminal:
pip install requests-html2. Getting an API key
Before we can start coding, we need to get an API key from Pixabay.
Getting an API key is incredibly easy, just go to the following page and login (or join) Pixabay:
Once you’ve logged in, scroll down the page and you should see your API key:

3. Writing the code
Downloading the required resources
For this tutorial, you’ll need a few files that I’ve already built. To download them just go to Github and clone my project:









