How to Set the Language of an HTML Document in Python

2 min readJul 7, 2021


The language code of an HTML document is an essential component that should always be included inside the HTML tag to indicate the language of the web page. By setting this attribute, you will be able to assist search engines and browsers in locating language-compatible web pages. In this brief tutorial, we will demonstrate an easy way to automatically set the language code of an HTML document by using the following API in Python.

Let’s begin by running this command to install the API client:

pip install cloudmersive-convert-api-client

Once the installation is complete, we can call the function with the below example code:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.EditHtmlApi(cloudmersive_convert_api_client.ApiClient(configuration))
language_code = 'language_code_example' # str | The HTML langauge code to set.
input_file = '/path/to/inputfile' # file | Optional: Input file to perform the operation on. (optional)
input_file_url = 'input_file_url_example' # str | Optional: URL of a file to operate on as input. (optional)
# Sets the language for the HTML document
api_response = api_instance.edit_html_html_set_language(language_code, input_file=input_file, input_file_url=input_file_url)
except ApiException as e:
print("Exception when calling EditHtmlApi->edit_html_html_set_language: %s\n" % e)

Your language code will be set and ready to go upon completion of the process! To retrieve your API key, head to the Cloudmersive website to register for a free account that will provide access to 800 monthly calls across our wide selection of APIs.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.