How to detect if a Text String is Base 64 Encoded in Python

Today is going to be a crash course in adding base 64 string detection to your project. I think you will be pleasantly surprised when you realize just how simple this is going to be.

To achieve speed as well as quality, we will make use of a Cloudmersive API, which can be installed with this command.

pip install cloudmersive-convert-api-client

Next we shall call edit_text_base64_detect, which will be doing our work for us. Here is how that function call should be set up:

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.EditTextApi(cloudmersive_convert_api_client.ApiClient(configuration))request = cloudmersive_convert_api_client.Base64DetectRequest() # Base64DetectRequest | Input requesttry:# Detect, check if text string is base 64 encodedapi_response = api_instance.edit_text_base64_detect(request)pprint(api_response)except ApiException as e:print("Exception when calling EditTextApi->edit_text_base64_detect: %s\n" % e)

All that’s left is to enter our test string into the request object and give it a go. That’s it! Easier than writing all the code yourself? You bet!

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