Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

microsoft_agents_m365copilot_beta-1.0.0rc3.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file microsoft_agents_m365copilot_beta-1.0.0rc3.tar.gz.

File metadata

File hashes

Hashes for microsoft_agents_m365copilot_beta-1.0.0rc3.tar.gz
Algorithm Hash digest
SHA256 d1a46d9d9d3666827870f5ff1aee9b87ff4514ec9b7b23320019b0738b8a0395
MD5 492524f28b13d0c0bc07d8724669bd8d
BLAKE2b-256 cf9fa2e43e7635d5ae4e7089e820c1052a58f388f5163d0c9eaeb1577bf938ad

See more details on using hashes here.

File details

Details for the file microsoft_agents_m365copilot_beta-1.0.0rc3-py3-none-any.whl.

File metadata

File hashes

Hashes for microsoft_agents_m365copilot_beta-1.0.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 87d553177131089ebd6a1a9d7bee5d89a87744aaadab38cefd38c710d4be7ea1
MD5 af186a927d9913cf590f0aca9c3e5ac1
BLAKE2b-256 e00e290e6b4521c10fbfc50ffe922d911ee617462be5772eb0cbcef833a47fe7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page