Survey banner
Switching to Dataiku - a new area to help users who are transitioning from other tools and diving into Dataiku! CHECK IT OUT

Add file attachments within a custom scenario (Python) script

Level 1
Add file attachments within a custom scenario (Python) script


I am trying to automate a flow using a custom scenario script written in Python. I wish to send one of the outputs produced by the flow as an email attachment once the flow completes. I got this far:

sender = scenario.get_message_sender(channel_id="email_channel_id")

sender.set_params(sender="", recipient="")

Not sure how to include attachments in the set_params() call.

Please note that:

  • The attachment is a file within a managed DataIku folder that is expected to be built at the end of the flow

  • It is a multi-worksheet Excel file


Thank you in advance for your help.

0 Kudos
2 Replies
Level 1

Never mind. Figured out how to do this myself by examining the html fields in the in-built reporter form:

# Instantiate an email sender object
sender = scenario.get_message_sender(channel_id = "email_channel_id")

# Create an array of dicts: one for each attachment with:
# - 'type' specifying the type of attachment
# - 'params' specifying other details
attachments =[ {
'type': 'FOLDER_ITEM',
{'folderId': 'folder_id',
'attachedItemPath': 'name_of_file_in_folder'}

# Set all params in the sender object
attachments = attachments,
message="Test to test the testy test.")
# Send email


Level 1

Hi All,
I wanted to send an attachment using custom python script based on a condition.

Lets say if my dataset is empty then I do not want to include attachment else include it.

Can anyone please help me here how to get that done?

0 Kudos