Microsoft Agents M365 Copilot Python SDK (Beta)
Project description
Microsoft 365 Copilot APIs Python Beta Client Library
Integrate the Microsoft 365 Copilot APIs into your Python application!
Note:
Because the Copilot APIs in the beta endpoint are subject to breaking changes, don't use a preview release of the client libraries in production apps.
Installation
To install the client libraries via PyPi:
pip install microsoft-agents-m365copilot-beta
Create a Copilot APIs client and make an API call
The following code example shows how to create an instance of a Microsoft 365 Copilot APIs client with an authentication provider in the supported languages. The authentication provider handles acquiring access tokens for the application. Many different authentication providers are available for each language and platform. The different authentication providers support different client scenarios. For details about which provider and options are appropriate for your scenario, see Choose an Authentication Provider.
The example also shows how to make a call to the Microsoft 365 Copilot Retrieval API. To call this API, you first need to create a request object and then run the POST method on the request.
The client ID is the app registration ID that is generated when you register your app in the Azure portal.
Note:
Your tenant must have a Microsoft 365 Copilot license.
import { createBaseAgentsM365CopilotBetaServiceClient, RetrievalDataSourceObject } from '@microsoft/agents-m365copilot-beta';
import { DeviceCodeCredential } from '@azure/identity';
import { FetchRequestAdapter } from '@microsoft/kiota-http-fetchlibrary';
async function main() {
// Initialize authentication with Device Code flow
const credential = new DeviceCodeCredential({
tenantId: process.env.TENANT_ID,
clientId: process.env.CLIENT_ID,
userPromptCallback: (info) => {
console.log(`\nTo sign in, use a web browser to open the page ${info.verificationUri}`);
console.log(`Enter the code ${info.userCode} to authenticate.`);
console.log(`The code will expire at ${info.expiresOn}`);
}
});
// Create request adapter with auth
const adapter = new FetchRequestAdapter(credential, {
scopes: ['https://graph.microsoft.com/.default']
});
adapter.baseUrl = "https://graph.microsoft.com/beta";
// Create client instance
const client = createBaseAgentsM365CopilotBetaServiceClient(adapter);
try {
console.log(`Using API base URL: ${adapter.baseUrl}\n`);
// Create the retrieval request body
const retrievalBody = {
dataSource: RetrievalDataSourceObject.SharePoint,
queryString: "What is the latest in my organization"
};
// Make the API call
console.log("Making retrieval API request...");
const retrieval = await client.copilot.retrieval.post(retrievalBody);
// Process the results
if (retrieval?.retrievalHits) {
console.log(`\nReceived ${retrieval.retrievalHits.length} hits`);
for (const hit of retrieval.retrievalHits) {
console.log(`\nWeb URL: ${hit.webUrl}`);
for (const extract of hit.extracts || []) {
console.log(`Text:\n${extract.text}\n`);
}
}
}
} catch (error) {
console.error('Error:', error);
throw error;
}
}
Issues
View or log issues on the Issues tab in the repo and tag them as python or python-core.
Copyright and license
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file microsoft_agents_m365copilot_beta-1.0.0rc3.tar.gz.
File metadata
- Download URL: microsoft_agents_m365copilot_beta-1.0.0rc3.tar.gz
- Upload date:
- Size: 32.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1a46d9d9d3666827870f5ff1aee9b87ff4514ec9b7b23320019b0738b8a0395
|
|
| MD5 |
492524f28b13d0c0bc07d8724669bd8d
|
|
| BLAKE2b-256 |
cf9fa2e43e7635d5ae4e7089e820c1052a58f388f5163d0c9eaeb1577bf938ad
|
File details
Details for the file microsoft_agents_m365copilot_beta-1.0.0rc3-py3-none-any.whl.
File metadata
- Download URL: microsoft_agents_m365copilot_beta-1.0.0rc3-py3-none-any.whl
- Upload date:
- Size: 133.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87d553177131089ebd6a1a9d7bee5d89a87744aaadab38cefd38c710d4be7ea1
|
|
| MD5 |
af186a927d9913cf590f0aca9c3e5ac1
|
|
| BLAKE2b-256 |
e00e290e6b4521c10fbfc50ffe922d911ee617462be5772eb0cbcef833a47fe7
|