Get Public Holidays in a Specified Country & Year in Python
Preemptively navigating around public holidays in any given year is a sneakily important task— after all, you don’t want to go through planning a meeting, event, etc. only to find out that everyone will be on vacation that day. Thankfully, you can get that information easily ahead of time with the Cloudmersive Validate API. Using the /validate/date-time/get/holidays iteration, you can enumerate all public holidays in a given country for a given year (over 100 countries supported). It’s easy to use — let’s walk through how you can connect in Python.
Your first step is to install the Python SDK using the following command:
pip install cloudmersive-validate-api-clientfrom __future__ import print_function
import time
import cloudmersive_validate_api_client
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint
After that, you can copy & paste the API Key authentication snippet below, which will capture your API key (attainable by creating a free account on the Cloudmersive website):
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
Now, you can end the callback function with the following snippet, and you’re all set to go:
# 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 requesttry:
# 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)