Dev Space

Customize and extend the power of Alteryx with SDKs, APIs, custom tools, and more.

Python Tool to Translate Hexidecimal to Unicode

SydneyF
Alteryx Alumni (Retired)

Hi Developers!

 

I saw this post in the Alteryx Designer Discussions, and although Alteryx does support Unicode encoding by default, it does not have a native way of translating other encodings into Unicode. This got me wondering if there might be a way to leverage the Python SDK for this task. I was able to modify the Python Single Input Output Example Tool to accomplish this task. The core of the code is a function that translates hexadecimal to Unicode.

 

def unicodeTrans(msg):
	new_msg = []
	for char in msg:
		try:
			char = chr(ord(char))
		except ValueError:
			char = '?'
		new_msg.append(char)
	return ''.join(new_msg)
			

 

This function was working really well when ran in an IDE, but was failing to execute the translation in the Python SDK Tool. It turned out this was because of the way values are passed through the Alteryx Engine to Python. The Python SDK uses UTF-8, and the input values are passed in from the engine as strings. This required that I convert the strings to bytes before passing them into the translation function, in order for the function to work properly. 

 

bts = bytes(text, 'utf-8').decode("unicode_escape")
result = unicodeTrans(bts)

 

This is a pretty simple tool, but I had a lot of fun with this exercise learning more about the Python SDK!

 

 

 

2 REPLIES 2
TashaA
Alteryx Alumni (Retired)

Really cool use case @SydneyF! Thanks so much for sharing 

SeanAdams
17 - Castor
17 - Castor

Thank you for posting this @SydneyF  - the documentation for the SDK is still a little rough, so having examples like this to work through really helps.

The other SDK examples are out there - but I couldn't find one that added a simple calculated field (which is what I'm trying to achieve, and which yours does).