# Metadata with python plugin

**URL:** <https://forum.opentap.io/t/metadata-with-python-plugin/2007>\
**Category:** General\
**Tags:** python\
**Created:** [June 11, 2024, 7:18am UTC](https://forum.opentap.io/t/metadata-with-python-plugin/2007 "2024-06-11T07:18:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernhard.lettner](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bernhard.lettner](https://forum.opentap.io/u/bernhard.lettner)\
**Post date:** [June 11, 2024, 7:18am UTC](https://forum.opentap.io/t/metadata-with-python-plugin/2007/1 "2024-06-11T07:18:34Z")

</div>

I am programming fully with the python-plugin and I try to add Metadata to my Result.csv - but I do not understand how, and the python-examples do not cover this topic.

My goal is something similar as requested here: [https://forum.opentap.io/t/saving-duts-and-intruments-in-results](https://forum.opentap.io/t/saving-duts-and-intruments-in-results)  
i.e. I would like to store DUT and Instrument information (aswell as other properties) into the result.csv file. As I understood this can be achieved easily via Metadata, however I don’t know how to use this feature within the python-plugin.

I tried to add a MetaDataAttribute to a property, i.e.:  
abc = property(Double, 1) .add\_attribute(OpenTap.MetaDataAttribute(True)) .add\_attribute(OpenTap.Display(“abc\_disp”, “abc”)), however this fails with "Unable to cast object of type ‘OpenTap.MetaDataAttribute’ to type ‘System.Type’.

Could someone point me in a direction on how to achieve this?

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [June 16, 2024, 1:29am UTC](https://forum.opentap.io/t/metadata-with-python-plugin/2007/2 "2024-06-16T01:29:42Z")

</div>

Hi @bernhard.lettner,

I think you just need to remove the “Attribute” part from the attribute. This works for me:

```cs
# I modified the BasicDut example to add metadata attribute.
class BasicDut(Dut):
    # Add a Firmware version setting which can be configured by the user.
    
    Firmware = property(String, "1.0.2")\
        .add_attribute(OpenTap.Display( "Firmware Version", "The firmware version of the DUT.", "Common"))\
        .add_attribute(OpenTap.MetaData(True))

```

---

<div class="post-metadata">

**Author:** ![bernhard.lettner](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bernhard.lettner](https://forum.opentap.io/u/bernhard.lettner)\
**Post date:** [June 17, 2024, 6:39am UTC](https://forum.opentap.io/t/metadata-with-python-plugin/2007/3 "2024-06-17T06:39:09Z")

</div>

Hi @rolf_madsen, thanks for your reply and code example!

I tried this, and now the code runs without obvious errors. However, the Metadata is still not stored to the results.csv file.

As Result Listener I am using Text/CSV and Text/Text Log.  
In my code, I only append this line at the end of my Test-step:

```csharp
# publish results:
self.PublishResult("example_resultListener", ["cMeas", "val1"], [val, val1])

```

Do you have any other steps in your code / am I missing some commands?
