UUID generator in Python

Hey @Thiemo.Kellner,

If I understand correctly, you want to create a single unique identifier that you will use throughout your workflow. Perhaps to record some sort of “Session ID” for you to reference later on.


Recommended approach: GUID Generator component

If you simply use the Empty Table Creator node and set it to generate one row, then use the GUID Generator component, that will effectively create a single GUID/UUID that can be accessed elsewhere in your workflows.

image

You could also tack on a Table Row to Variable node if you wanted to access the GUID as a flow variable.

Example workflow: single-uuid-for-session – KNIME Community Hub


Alternate approach: Python

If you really wanted to do it in Python, you could use a Python Script node with a script like the one below, but I wouldn’t recommend it. The GUID Generator component uses Java which would likely execute a bit faster.

import knime.scripting.io as knio

import pandas as pd
import uuid

knio.output_tables[0] = knio.Table.from_pandas(
    pd.DataFrame({'session_id': [str(uuid.uuid4())]})
)

Example workflow: single-uuid-for-session-python – KNIME Community Hub


Good luck and have fun!

Cheers,

@sjporter

4 Likes