{"id":44865216,"url":"https://github.com/cern-vc/ms-python-client","last_synced_at":"2026-02-17T10:51:44.650Z","repository":{"id":179405596,"uuid":"663436400","full_name":"cern-vc/ms-python-client","owner":"cern-vc","description":"This package is used to interact with the Microsoft Graph API ","archived":false,"fork":false,"pushed_at":"2024-07-06T00:38:03.000Z","size":619,"stargazers_count":1,"open_issues_count":14,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-27T03:45:49.669Z","etag":null,"topics":["api","cern","microsoft"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/ms-python-client/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cern-vc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-07T09:34:54.000Z","updated_at":"2023-07-18T09:35:59.000Z","dependencies_parsed_at":"2023-09-26T00:53:30.943Z","dependency_job_id":"567dac61-9dbb-48ee-b7fa-ebdfe7fd369a","html_url":"https://github.com/cern-vc/ms-python-client","commit_stats":null,"previous_names":["samuelguillemet/ms-python-client","cern-vc/ms-python-client"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/cern-vc/ms-python-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cern-vc%2Fms-python-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cern-vc%2Fms-python-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cern-vc%2Fms-python-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cern-vc%2Fms-python-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cern-vc","download_url":"https://codeload.github.com/cern-vc/ms-python-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cern-vc%2Fms-python-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29540788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T08:11:05.436Z","status":"ssl_error","status_checked_at":"2026-02-17T08:09:38.860Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","cern","microsoft"],"created_at":"2026-02-17T10:51:43.912Z","updated_at":"2026-02-17T10:51:44.643Z","avatar_url":"https://github.com/cern-vc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Microsoft Python client\n\n[![Python tests](https://github.com/cern-vc/ms-python-client/actions/workflows/python-tests.yml/badge.svg)](https://github.com/cern-vc/ms-python-client/actions/workflows/python-tests.yml)\n[![Pre-commit](https://github.com/cern-vc/ms-python-client/actions/workflows/pre-commit.yaml/badge.svg)](https://github.com/cern-vc/ms-python-client/actions/workflows/pre-commit.yaml)\n[![CodeQL](https://github.com/cern-vc/ms-python-client/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/cern-vc/ms-python-client/actions/workflows/github-code-scanning/codeql)\n[![codecov](https://codecov.io/gh/cern-vc/MS-python-client/branch/main/graph/badge.svg?token=04EY0K0P2S)](https://codecov.io/gh/cern-vc/MS-python-client)\n\n![Build](https://img.shields.io/github/actions/workflow/status/cern-vc/ms-python-client/build.yml?logo=python\u0026label=Publish\u0026color=0E7FC0)\n![PyPI - Version](https://img.shields.io/pypi/v/ms-python-client?logo=python)\n![PyPI - Download](https://img.shields.io/pypi/dm/ms-python-client?logo=python\u0026color=0E7FC0)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ms-python-client?logo=python\u0026color=0E7FC0)\n\nMicrosoft graph API Python client with support for [Device Flow Oauth tokens](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-device-code) with deleguated access.\n\n## Install\n\nThis package is [available on Pypi](https://pypi.org/project/ms-python-client/)\n\n```bash\npip install ms-python-client\n```\n\n## Requirements\n\n- Python \u003e= 3.9\n\n## How to configure the client variables to make API calls\n\n### Defining your env variables\n\nDefine the following variables in your `env` or your `.env` file:\n\n- AZURE_AUTHORITY\n- AZURE_CLIENT_ID\n- AZURE_SCOPE\n\n#### For testing purposes\n\nFor testing purposes, you can use the following value:\n\n- MS_ACCESS_TOKEN\n\nThis token could be obtained from the [Microsoft Graph Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer) by clicking on the `Sign in with Microsoft` button and then clicking on the `Access Token` tab.\n\n## Usage\n\n### Initialize the MSApiClient from environment variables\n\n```python\nfrom ms_python_client import MSApiClient\n\nms_client = MSApiClient.init_from_env()\n```\n\n### Initialize the MSApiClient from .env\n\n```python\nfrom ms_python_client import MSApiClient\n\nms_client = MSApiClient.init_from_dotenv()\n```\n\n### Initialize the MSApiClient manually\n\n```python\nfrom ms_python_client import MSApiClient,  Config\n\nconfig = Config(\n    azure_authority=\"\u003cYOUR AZURE AUTHORITY\u003e\",\n    azure_client_id=\"\u003cYOUR AZURE CLIENT ID\u003e\",\n    azure_scope=\"\u003cYOUR AZURE SCOPE\u003e\" # Ex. [User.Read, Calendars.ReadWrite, etc.]\n)\n\nms_client = MSApiClient(\n    config=config,\n)\n```\n\n#### Store of the cache token\n\nBy default the token is stored in a file called `token_cache.bin` in the current directory. You can change this behavior by passing the `token_cache_file` parameter to the `Config` constructor.\n\n```python\nfrom ms_python_client import MSApiClient, Config\n\nconfig = Config(\n    azure_authority=\"\u003cYOUR AZURE AUTHORITY\u003e\",\n    azure_client_id=\"\u003cYOUR AZURE CLIENT ID\u003e\",\n    azure_scope=\"\u003cYOUR AZURE SCOPE\u003e\", # Ex. [User.Read, Calendars.ReadWrite, etc.]\n    token_cache_file=\"/path/to/token_cache.bin\"\n)\n\nms_client = MSApiClient(\n    config=config,\n)\n```\n\nThis will allow you to reuse the token in the next executions of your script and even in different scripts.\n\n## How to make API calls\n\n```python\nUSER_ID = \"12345\"\nSUBJECT = \"Test meeting\"\n\nquery = {\"$count\": \"true\", \"$filter\": f\"contains(subject,'{SUBJECT}')\"}\nresult = cern_ms_client.events.list_events(USER_ID, query)\n```\n\n## Optional: How to configure the logging\n\n```python\nfrom ms_python_client import setup_logs\n\nsetup_logs(log_level=logging.DEBUG)\n```\n\n## Available endpoints\n\n### **events**:\n\n1. get all events\n2. get a single event\n3. create an event\n4. update an event\n5. delete an event\n\n### **users**:\n\n1. get all users\n\n---\n\n## CERN specific usage\n\nInstead of using the `MSApiClient` class, you can use the `CERNMSApiClient` class, which is a subclass of the `MSApiClient` class.\nThis class will provide you some more utilities but it will only work for CERN users (obviously).\n\nThis will be used in the context of synchronizing the events between the CERN Indico system and the calendars of the Zoom Rooms.\n\n### How to initialize the CERNMSApiClient\n\nFollow the [How to configure the client variables to make API calls](#how-to-configure-the-client-variables-to-make-api-calls) section and then:\n\n```python\nfrom ms_python_client import CERNMSApiClient\n\ncern_ms_client = CERNMSApiClient.init_from_dotenv()\n```\n\n### Available endpoints\n\n#### **events**:\n\n1. get all events\n2. get a single event using zoom id\n3. create an event\n4. update an event using zoom id\n5. delete an event using zoom id\n6. get the zoom id of an event\n7. get current event of a user\n\nYou will find useful the `EventParameters` and `PartialEventParameters` classes, which will help you to create the events.\n\nThe `EventParameters` class is used to create an event, while the `PartialEventParameters` class is used to update an event.\n\n- `ZOOM_ID` is the id of the zoom meeting, which can be found inside the url of a meeting link. This is **mandatory** to create an event.\n- `USER_ID` is the email of the Zoom Room.\n\n```python\nfrom ms_python_client import CERNMSApiClient, EventParameters, PartialEventParameters\n\ncern_ms_client = CERNMSApiClient.init_from_dotenv()\n\nUSER_ID = os.getenv(\"USER_ID\") # Which is the email of the Zoom Room\nZOOM_ID = os.getenv(\"ZOOM_ID\")\n\nevent_parameters = EventParameters(\n        subject=\"Test meeting\",\n        start_time=\"2021-10-01T12:00:00\",\n        end_time=\"2021-10-01T13:00:00\",\n        timezone=\"Europe/Zurich\",\n        zoom_url=\"https://cern.zoom.us/******\",\n)\n\npartial_event_parameters = PartialEventParameters(\n        end_time=\"2021-10-01T14:00:00\",\n) # You can update only the end_time of the event for example\n\ncern_ms_client.events.create_event(USER_ID, ZOOM_ID, event_parameters)\ncern_ms_client.events.update_event_by_zoom_id(USER_ID, ZOOM_ID, partial_event_parameters)\ncern_ms_client.events.delete_event_by_zoom_id(USER_ID, ZOOM_ID)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcern-vc%2Fms-python-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcern-vc%2Fms-python-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcern-vc%2Fms-python-client/lists"}