I know I can add a description to a dataset that doesn't have one like this:
dataset.citation.add_ds_description(value="This is a description of the dataset")
But if I've loaded an existing dataset (dataset = dataverse.load_dataset(pid)) how do I update the description? :thinking:
You can edit the object directly, by using the following:
dataset.citation.ds_description.value = "New description"
The adder functions are more or less for convenience to not have to "dig-out" the expected type and then set it to the appropriate attribute. In general, you can apply any Python OOP techniques for metadata blocks .
I thought I tried that! I will, as soon as I get to my desk. Is this documented? I couldn't find it anywhere. :sweat_smile:
It is kind of documented within this Jupyter notebook but only for the primitive and no compound case, but that should work as the Dataverse JSON is constructed from the given Dataset object.
What about the fact that description is multi-valued? The code above would update the first description?
Oh you are right! In this case you'd need to add an index as the attribute is of type List. Here's an update:
dataset.citation.ds_description[i].value = "New description"
On another note, if the Citation block is consistent across versions and instances, we could add convenience functions for commonly used fields such as description and title
Ah ha. Do we need to add docs for this?
Technically, a description can have a date. I don't want to set a date but off the top of your head, do you think this is possible?
Ok, here's the final versions that works:
# Update the metadata fields
dataset.citation.title = title
dataset.citation.subject = ["Other"]
dataset.metadatablocks["citation"].ds_description[0].value = description
dataset.metadatablocks["citation"].author[0].name = author_name
dataset.metadatablocks["citation"].author[0].affiliation = None
dataset.metadatablocks["citation"].dataset_contact[0].name = "Dataverse Support"
dataset.metadatablocks["citation"].dataset_contact[0].email = "support@dataverse.org"
dataset.metadatablocks["citation"].origin_of_sources = '<a href="' + access_link_url + '">' + access_link_name + '</a>'
In short, you should use the dataset.metadatablocks trick for direct access to the part of the dict you need to change.
Also this is super helpful for figuring out which values need to be set:
print(dataverse.list_metadatablocks(detailed=True))
And you can print out the dataset as a dict:
print(dataset.dataverse_dict())
Or in JSON format (with optional indenting):
print(dataset.dataverse_json(4))
Huge thanks to @Jan Range for the live troubleshooting this morning. This is a good reason to attend the pyDataverse meeting! (#python > meetings ) :big_smile:
Last updated: Nov 01 2025 at 14:11 UTC