microsoft-teams-graph


Namemicrosoft-teams-graph JSON
Version 0.0.1a1 PyPI version JSON
download
home_pageNone
SummaryThe Graph package for a Microsoft Teams agent
upload_time2025-08-21 21:54:58
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT
keywords agents ai bot graph microsoft teams
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Microsoft Teams Graph Integration

This package provides seamless access to Microsoft Graph APIs from Teams bots and agents built with the Microsoft Teams AI SDK for Python.

## Requirements

- Teams AI SDK for Python
- Microsoft Graph SDK for Python (msgraph-sdk)
- Azure Core library (azure-core)
- Microsoft Teams Common library (microsoft-teams-common)

## Features

- **Token Type Support**: Uses the unified Token type from microsoft-teams-common
- **Flexible Token Handling**: Accepts strings, StringLike objects, callables, async callables, or None
- **Automatic Token Resolution**: Leverages the common resolve_token utility for consistent token handling

## Quick Start

```python
from microsoft.teams.graph import get_graph_client
from microsoft.teams.apps import App, ActivityContext
from microsoft.teams.api import MessageActivity
from microsoft.teams.api.clients.user.params import GetUserTokenParams

app = App()

@app.on_message
async def handle_message(ctx: ActivityContext[MessageActivity]):
    if not ctx.is_signed_in:
        await ctx.sign_in()
        return

    # Use the user token that's already available in the context
    graph = get_graph_client(ctx.user_token)

    # Make Graph API calls
    me = await graph.me.get()
    await ctx.send(f"Hello {me.display_name}!")

    # Make Graph API calls
    me = await graph.me.get()
    await ctx.send(f"Hello {me.display_name}!")
```

## Token Type Usage

The package uses the Token type from microsoft-teams-common for flexible token handling. You can provide tokens in several formats:

### String Token (Simplest)

```python
# Direct string token
graph = get_graph_client("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs...")
```

### Callable Token (Dynamic)

```python
def get_token():
    """Callable that returns a string token."""
    # Get your access token from wherever (Teams API, cache, etc.)
    return get_access_token_from_somewhere()

# Use the callable with get_graph_client
graph = get_graph_client(get_token)
```

### Async Callable Token

```python
async def get_token_async():
    """Async callable that returns a string token."""
    # Fetch token asynchronously
    token_response = await some_api_call()
    return token_response.access_token

graph = get_graph_client(get_token_async)
```

### Dynamic Token Retrieval

```python
def get_fresh_token():
    """Callable that fetches a fresh token on each invocation."""
    # This will be called each time the Graph client needs a token
    fresh_token = fetch_latest_token_from_api()
    return fresh_token

graph = get_graph_client(get_fresh_token)
```

## Authentication

The package uses Token-based authentication with automatic resolution through the common library. Teams tokens are pre-authorized through the OAuth connection configured in your Azure Bot registration.

## API Usage Examples

```python
# Get user profile
me = await graph.me.get()

# Get recent emails with specific fields
from msgraph.generated.users.item.messages.messages_request_builder import MessagesRequestBuilder

query_params = MessagesRequestBuilder.MessagesRequestBuilderGetQueryParameters(
    select=["subject", "from", "receivedDateTime"],
    top=5
)
request_config = MessagesRequestBuilder.MessagesRequestBuilderGetRequestConfiguration(
    query_parameters=query_params
)
messages = await graph.me.messages.get(request_configuration=request_config)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "microsoft-teams-graph",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "agents, ai, bot, graph, microsoft, teams",
    "author": null,
    "author_email": "Microsoft <TeamsAISDKFeedback@microsoft.com>",
    "download_url": "https://files.pythonhosted.org/packages/e2/66/3f03d280d421b16527b450e08960c5343278879c6c05cb5d75b8a4c1a007/microsoft_teams_graph-0.0.1a1.tar.gz",
    "platform": null,
    "description": "# Microsoft Teams Graph Integration\n\nThis package provides seamless access to Microsoft Graph APIs from Teams bots and agents built with the Microsoft Teams AI SDK for Python.\n\n## Requirements\n\n- Teams AI SDK for Python\n- Microsoft Graph SDK for Python (msgraph-sdk)\n- Azure Core library (azure-core)\n- Microsoft Teams Common library (microsoft-teams-common)\n\n## Features\n\n- **Token Type Support**: Uses the unified Token type from microsoft-teams-common\n- **Flexible Token Handling**: Accepts strings, StringLike objects, callables, async callables, or None\n- **Automatic Token Resolution**: Leverages the common resolve_token utility for consistent token handling\n\n## Quick Start\n\n```python\nfrom microsoft.teams.graph import get_graph_client\nfrom microsoft.teams.apps import App, ActivityContext\nfrom microsoft.teams.api import MessageActivity\nfrom microsoft.teams.api.clients.user.params import GetUserTokenParams\n\napp = App()\n\n@app.on_message\nasync def handle_message(ctx: ActivityContext[MessageActivity]):\n    if not ctx.is_signed_in:\n        await ctx.sign_in()\n        return\n\n    # Use the user token that's already available in the context\n    graph = get_graph_client(ctx.user_token)\n\n    # Make Graph API calls\n    me = await graph.me.get()\n    await ctx.send(f\"Hello {me.display_name}!\")\n\n    # Make Graph API calls\n    me = await graph.me.get()\n    await ctx.send(f\"Hello {me.display_name}!\")\n```\n\n## Token Type Usage\n\nThe package uses the Token type from microsoft-teams-common for flexible token handling. You can provide tokens in several formats:\n\n### String Token (Simplest)\n\n```python\n# Direct string token\ngraph = get_graph_client(\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs...\")\n```\n\n### Callable Token (Dynamic)\n\n```python\ndef get_token():\n    \"\"\"Callable that returns a string token.\"\"\"\n    # Get your access token from wherever (Teams API, cache, etc.)\n    return get_access_token_from_somewhere()\n\n# Use the callable with get_graph_client\ngraph = get_graph_client(get_token)\n```\n\n### Async Callable Token\n\n```python\nasync def get_token_async():\n    \"\"\"Async callable that returns a string token.\"\"\"\n    # Fetch token asynchronously\n    token_response = await some_api_call()\n    return token_response.access_token\n\ngraph = get_graph_client(get_token_async)\n```\n\n### Dynamic Token Retrieval\n\n```python\ndef get_fresh_token():\n    \"\"\"Callable that fetches a fresh token on each invocation.\"\"\"\n    # This will be called each time the Graph client needs a token\n    fresh_token = fetch_latest_token_from_api()\n    return fresh_token\n\ngraph = get_graph_client(get_fresh_token)\n```\n\n## Authentication\n\nThe package uses Token-based authentication with automatic resolution through the common library. Teams tokens are pre-authorized through the OAuth connection configured in your Azure Bot registration.\n\n## API Usage Examples\n\n```python\n# Get user profile\nme = await graph.me.get()\n\n# Get recent emails with specific fields\nfrom msgraph.generated.users.item.messages.messages_request_builder import MessagesRequestBuilder\n\nquery_params = MessagesRequestBuilder.MessagesRequestBuilderGetQueryParameters(\n    select=[\"subject\", \"from\", \"receivedDateTime\"],\n    top=5\n)\nrequest_config = MessagesRequestBuilder.MessagesRequestBuilderGetRequestConfiguration(\n    query_parameters=query_params\n)\nmessages = await graph.me.messages.get(request_configuration=request_config)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "The Graph package for a Microsoft Teams agent",
    "version": "0.0.1a1",
    "project_urls": null,
    "split_keywords": [
        "agents",
        " ai",
        " bot",
        " graph",
        " microsoft",
        " teams"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "feb61be4d3d13e1ecd454d38331247a6fb8dbca375a783f16f01ae510c8e366a",
                "md5": "6b00a1f5021c092b6836fd33426f587b",
                "sha256": "fc741d352684bd7062aab8f1b901ad304f7a04d94cc3ff0e5a28a1721669093f"
            },
            "downloads": -1,
            "filename": "microsoft_teams_graph-0.0.1a1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6b00a1f5021c092b6836fd33426f587b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 4960,
            "upload_time": "2025-08-21T21:54:56",
            "upload_time_iso_8601": "2025-08-21T21:54:56.699412Z",
            "url": "https://files.pythonhosted.org/packages/fe/b6/1be4d3d13e1ecd454d38331247a6fb8dbca375a783f16f01ae510c8e366a/microsoft_teams_graph-0.0.1a1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e2663f03d280d421b16527b450e08960c5343278879c6c05cb5d75b8a4c1a007",
                "md5": "5975355f4b05fe5f075751777ddb84d4",
                "sha256": "a281c8d79a86a95d865a4af4728e8216977e7d5c711fdb76665789494e46e874"
            },
            "downloads": -1,
            "filename": "microsoft_teams_graph-0.0.1a1.tar.gz",
            "has_sig": false,
            "md5_digest": "5975355f4b05fe5f075751777ddb84d4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 3820,
            "upload_time": "2025-08-21T21:54:58",
            "upload_time_iso_8601": "2025-08-21T21:54:58.055303Z",
            "url": "https://files.pythonhosted.org/packages/e2/66/3f03d280d421b16527b450e08960c5343278879c6c05cb5d75b8a4c1a007/microsoft_teams_graph-0.0.1a1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-21 21:54:58",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "microsoft-teams-graph"
}
        
Elapsed time: 3.09107s