Retrieve the Public Holidays for a Country in Python

Cloudmersive
2 min readDec 3, 2020

International commerce requires an understanding of important holidays in different countries. This is because these not only affect times when partners are available for communication but also help organizations with planning sales and advertising campaigns to align with increased purchases surrounding different holidays. The following API will enumerate a list of the public holidays for a given country, with support for over 100 countries.

To use this API, run this command to install the SDK:

pip install cloudmersive-validate-api-client

Then, you can call the function:

from __future__ import print_function
import time
import cloudmersive_validate_api_client
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_validate_api_client.DateTimeApi(cloudmersive_validate_api_client.ApiClient(configuration))
input = cloudmersive_validate_api_client.GetPublicHolidaysRequest() # GetPublicHolidaysRequest | Input request
try:
# Get public holidays in the specified country and year
api_response = api_instance.date_time_get_public_holidays(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling DateTimeApi->date_time_get_public_holidays: %s\n" % e)

The function will return the name of the holiday in both English and the local language, as well as the date on which it occurs, the holiday type, and whether the holiday is nationwide. You can retrieve the API Key from the Cloudmersive website at no cost and with no commitment. This will provide you with 800 monthly calls across our library of APIs.

--

--

Cloudmersive

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