import pyspark.sql.functions as f
from pyspark.sql.types import StringType
# method 1 use udf
uuid_udf = f.udf(lambda : str(uuid.uuid4().hex), StringType())
df_with_uuid = df.withColumn('uuid', uuid_udf())
# method 2 use lit
df_with_uuid = df.withColumn('uuid', f.lit(uuid.uuid4().hex))