5

I'm building an app that automatically labels Office files on Windows computers. To apply my sensitivity labels to documents programmatically, Microsoft tells me to use its MIP SDK.

But the SDK is in C++, with some convoluted async Observer patterns, so it's not clear to me how to call its functions from Python.

Has anyone succeeded in using the MIP SDK with Python 3? Can you share a concrete Python example of calling the SetLabel() function on a file?

user124114
  • 8,372
  • 11
  • 41
  • 63

1 Answers1

3

I have spent sometime looking into this problem. Microsoft doesn't make it clear on how to call their MIP C++ code using Python. It's also unclear for me if you're trying to set sensitivity labels on local Office files or ones stored in SharePoint or in Office 365.

I previously mentioned using Python Bindings, but after doing some research there are other ways.

Technique One


Microsoft has a PowerShell framework called Security & Compliance Center PowerShell. One the cmdlet is Set-Label, which can be used to enable sensitivity labels for Office files. There is another module called Set-LabelPolicy that can assist in setting global sensitivity policies.

PowerShell cmdlet can be called from Python. There are lots of examples on Stack Overflow on how to accomplish this.

Technique Two


Again Microsoft really requires you to dig for information to use Python over their prefer coding languages.

Microsoft has a GitHub project called AutoRest Python. This project generates Python code that is needed to interact with Microsoft Information Protection (MIP) and other Microsoft centric products.

The other GitHub project that is needed is msrest for python.

If you dig through some of Microsoft GitHub repositories you will find examples on how to use these modules.

Technique Three


You can also use Python to set registry settings related to sensitivity labels for Office files. If needed I can provide you the registry keys.

Life is complex
  • 15,374
  • 5
  • 29
  • 58
  • This does not answer my question. Nor does it meet the requirements for my bounty award, which were very clear. No idea why it was auto-selected and accepted :( – user124114 Sep 21 '21 at 14:56
  • Thanks for responding to this post-bounty question 30 days after I posted an answer. The question was auto-selected for 50% of the bounty, because of the Stack Overflow rules on awarding bounties. I'm sorry that you disagree with the established rules. – Life is complex Sep 21 '21 at 15:04
  • No problem. I still need the answer though :( Maybe another bounty? – user124114 Sep 21 '21 at 15:34
  • I understand. I will look through my answer again, because I know that the answer is within the examples. My issue is being able to test the code, because I don't have a Windows environment. – Life is complex Sep 21 '21 at 15:48
  • @user124114 are you trying to set the labels on individual files stored in a local file system of a specific computer or are you trying to find a certain file containing specific information stored in multiple systems across the entire enterprise? – Life is complex Sep 22 '21 at 15:31
  • The former – I'm building an app that automatically labels Office files on Windows computers. So I need to call `setLabel()` on a local file, yes. – user124114 Sep 28 '21 at 17:52