Link Search Menu Expand Document

Python: HTML/CSS to Image

Generate a png, jpg or webp images with Python. Renders exactly like Google Chrome.

Live demo Get an API Key

Table of contents

Generating images with Python

  1. The API takes your HTML/CSS and runs it inside a real instance of Google Chrome to convert your html into an image.
  2. Use Python to send the API your HTML/CSS.
  3. You’ll get back json with the URL to your generated image.

For more details on how this works, see Creating an image.

Example API response:

  "url": ""

Image generated with Python.

Authentication with Python

The API uses HTTP Basic authentication.

Your username is your User ID and your password is your API Key. Both of these are available from the dashboard. The Python code sample demonstrates how to authenticate your request.

You can signup for a free API key to get started.

Free API Key for Python

Python example code

This Python code example sends an HTTP POST to the API. Converting your HTML/CSS to an image with Python.

# pip3 install requests
import requests

# Retrieve these from
HCTI_API_USER_ID = 'your-user-id'
HCTI_API_KEY = 'your-api-key'

data = { 'html': "<div class='box'>Hello, world!</div>",
         'css': ".box { color: white; background-color: #0f79b9; padding: 10px; font-family: Roboto }",
         'google_fonts': "Roboto" }

image = = HCTI_API_ENDPOINT, data = data, auth=(HCTI_API_USER_ID, HCTI_API_KEY))

print("Your image URL is: %s"%image.json()['url'])

Need help?

Talk to a human. Please email us with any questions and we’ll gladly help you get started.

Back to top

Built with extensive integration tests and serious care for developer happiness.
© 2018-2020 Code Happy, LLC.

Page last modified: Oct 29 2020 at 02:54 PM.

Edit this page on GitHub.