Discussions#

You can interact with the discussions on each DSS object through the API.

Obtaining the discussions#

The first step is always to retrieve a DSSObjectDiscussions object corresponding to the DSS object your manipulating. Generally, it’s through a method called get_object_discussions

# Get the discussions of a dataset
discussions = dataset.get_object_discussions()

# Get the discussion of a wiki article
discussions = wiki.get_article("my article").get_object_discussions()

# Get the discussions of a project
discussions = project.get_object_discussions()

# ...

List the discussions of an object#

for discussion in discussions.list_discussions():
        # Discussion is a DSSDiscussion object
        print("Discussion with id: %s" % discussion.discussion_id)

Reading the messages of a discussion#

for message in discussion.get_replies():
        print("Message by author %s" % message.get_author())
        print("Message posted on %s" % message.get_timestamp())
        print("Message content: %s" % message.get_text())

Adding a new message to a discussion#

discussion.add_reply("hello world\n# This is Markdown")

Creating a new discussion#

new_discussion = discussions.create_discussion("Topic", "Hello, this is the message")

Detailed examples#

This section contains more advanced examples on discussions.

Export discussions from a Project#

You can programmatically retrieve all discussion messages from various “commentable” items in a Project.

import dataiku

def get_discussions_from_object(object_handle):
    """Return all discussion messages from a commentable object.
    """
    
    disc_data = []
    discussions = object_handle.get_object_discussions()
    for disc in discussions.list_discussions():
        disc_content = {}
        disc_content["topic"] = disc.get_metadata()["topic"]
        msg_list = []
        for msg in disc.get_replies():
            msg_content = {}
            msg_content["author"] = msg.get_author()
            msg_content["ts"] = msg.get_timestamp()
            msg_content["text"] = msg.get_text()
            msg_list.append(msg_content)
        disc_content["messages"] = msg_list
        disc_data.append(disc_content)
    return disc_data

        
def export_project_discussions(project):
    """Return all discussion data for a given Project.
    """

    proj_disc = {}
    dispatch = {
        "datasets": {
            "f_list": project.list_datasets, 
            "f_get": project.get_dataset
        },
        "recipes": {
            "f_list": project.list_recipes,
            "f_get": project.get_recipe
        },
        "scenarios": {
            "f_list": project.list_scenarios,
            "f_get": project.get_scenario
        },
        "managed_folders": {
            "f_list": project.list_managed_folders,
            "f_get": project.get_managed_folder
        }
    }
    
    for obj_type, funcs in dispatch.items():
        obj_disc = []
        for item in funcs["f_list"]():
            disc = {}
            disc["name"] = item["name"]
            obj_handle = funcs["f_get"](item["name"])
            disc["discussions"] = get_discussions_from_object(obj_handle)
            obj_disc.append(disc)
        proj_disc[obj_type] = obj_disc
        
    # Special case: project discussions
    proj_disc["project"] = get_discussions_from_object(project)
    
    # Special case: wiki
    wiki_disc = []
    articles = project.get_wiki().list_articles()
    for art in articles:
        art_disc = {}
        art_disc["article_id"] = art.article_id
        art_disc["discussions"] = get_discussions_from_object(art)
        wiki_disc.append(art_disc)
    proj_disc["wiki"] = wiki_disc
    
    return proj_disc

client = dataiku.api_client()
project = client.get_default_project()
discussions = export_project_discussions(project)

Reference documentation#

dataikuapi.dss.discussion.DSSObjectDiscussions(...)

A handle to manage discussions on a DSS object.

dataikuapi.dss.discussion.DSSDiscussion(...)

A handle to interact with a discussion.

dataikuapi.dss.discussion.DSSDiscussionReply(...)

A read-only handle to access a discussion reply.