office365-rest-python-client

repository·master·Indexed 23 days ago

https://github.com/vgrem/office365-rest-python-client

A Python client library for interacting with Microsoft 365 services, specifically covering the SharePoint REST API v1 and the Microsoft Graph API. Version 3.0.0 provides support for various authentication flows (Client Secret, Certificate, Interactive, Device Code, and ROPC) and includes implementation patterns for managing Microsoft Bookings, Teams communications (presence), Microsoft 365 Defender (Graph Security API), and Microsoft Entra ID application registrations, permissions, and credential rotation.

Tokens
49.1K
Snippets
98
Records
266
Agent score
83%

What's inside office365-rest-python-client

  1. Manage SharePoint Framework (SPFx) solutions via App Catalog

    master

    The App Catalog functionality allows you to manage the lifecycle of SharePoint Framework (SPFx) solutions and SharePoint Add-ins.

    Key Concepts:

    • Targeting: All management operations (uploading, listing, deploying, removing) target the tenant app catalog using the admin.web.tenant_app_catalog endpoint.
    • Installation: While management happens in the catalog, the install and uninstall operations specifically affect a target site collection.

    Prerequisites:

    • A SharePoint site collection app catalog must exist in your tenant.
    • Permissions: You need the SharePoint Administrator role for tenant-wide operations, or Site Owner permissions on the specific target site for installation/uninstallation.
    • Files: You must have a .sppkg (SPFx solution) or .app (SharePoint Add-in) file ready.
  2. Explore SharePoint REST API example directories

    master

    The examples/sharepoint/ directory contains specialized examples for various SharePoint functionalities. Use these directories to find implementation patterns for specific tasks:

    DirectoryCovers
    app-catalog/SPFx app lifecycle
    alerts/Email notifications on list/item changes
    audit/Audit settings, sign-in logs
    auth/Modern MSAL auth, legacy ACS/SAML, on-prem NTLM, cookie capture
    contenttypes/Content types, field links, hierarchy
    customactions/Custom action bindings (legacy)
    eventreceivers/Remote event receivers (legacy)
    features/Site features activation
    fields/Site/list column CRUD (all types)
    files/Upload, download, copy, move, check out, versions, permissions
    folders/Create, copy, move, rename, delete folders
    groups/SharePoint groups management
    hubsites/Hub site registration, association
    listitems/Item CRUD, bulk operations, filters, attachments
    lists/List CRUD, import/export, paging
    migration/Migration assessment scanner
    navigation/Top nav, Quick Launch
    operations/Long-running async operations (create/update/delete sites), SpoOperation polling
    pages/Modern site pages CRUD, news
    propertybag/Custom key-value pairs on webs
    permissions/Grant, revoke, break inheritance
    recyclebin/Restore deleted items
    compliance/Retention labels, compliance tags on sites/lists/files
    search/KQL queries, filters, refinement, crawl diagnostics, admin
    sharing/Sharing links, anonymous access
    sitedesigns/Site designs and site scripts
    sites/Create (modern/classic/communication), manage admins
    sitescripts/Site script JSON actions
    taxonomy/Term store, term sets, managed metadata
    teams/Teams via SharePoint API (limited)
    tenant/Tenant admin, site collections, licensing, quotas, version policy
    userprofile/Profile properties, followers, OneDrive URL
    users/Current user, site users, search
    views/List views, default and custom
    webhooks/List/webhook subscriptions
    advanced/Proxy config, SSL, performance diagnostics, raw requests
    webs/Web properties, subsites, changes, regional settings
  3. Use Microsoft 365 Security, Compliance, and Threat Protection APIs

    master

    The office365-rest-python-client provides examples for interacting with Microsoft 365 Security APIs, specifically covering attack simulation, security events, and threat protection.

    To use these features, you must ensure your application has the appropriate Microsoft Graph permissions configured in Azure. Common permissions include:

    • AttackSimulation.Read.All: Required to read attack simulation data.
    • SecurityEvents.Read.All: Required to read security events.

    For specific implementations, refer to the following scenarios:

    • Attack simulation training: See the attack_simulation.py example which requires AttackSimulation.Read.All permission.
  4. Manage modern SharePoint pages

    master

    The office365-rest-python-client allows you to create, read, update, publish, and manage modern SharePoint Site Pages. Modern pages use a canvas layout with web parts and can be promoted to news posts.

    Note: This library targets modern Site Pages. Classic page types (Wiki pages, web part pages, etc.) are considered legacy and are not the focus of these modern APIs.

    Prerequisites

    • Site Owner or Member role: Required to create, update, and delete pages.
    • Read access: Sufficient for browsing and listing pages.
  5. Manage Custom Actions in SharePoint (Legacy)

    master

    Custom actions allow you to add functionality to classic SharePoint pages and lists, such as injecting JavaScript via ScriptLink, adding toolbar buttons, or extending the ribbon.

    ⚠️ Warning: This is a legacy approach. Microsoft recommends using SharePoint Framework (SPFx) Extensions for modern sites. These methods target classic pages and lists only.

    Scopes

    • Site scope: Uses ScriptLink to inject JavaScript into every page on the site.
    • List scope: Adds toolbar buttons or ECB (Enterprise Client Browser) menu items to a specific list.

    Prerequisites

    • You must have the Site Owner role to manage custom actions on a site or list.
  6. List Microsoft Teams and channels via SharePoint REST API

    master

    You can use the SharePoint REST API through this client to list Microsoft Teams and channels that the current user has access to.

    Important Limitations: The SharePoint REST API provides limited team operations. For full Microsoft Teams management (such as creating channels, sending messages, installing apps, or managing members), you should use the Microsoft Graph Teams API instead.

  7. Available service modules and examples

    master

    The library provides specialized examples and coverage for various Microsoft 365 and Entra ID services. Use the following directory mapping to find specific implementation patterns:

    • auth: Graph authentication flows (Client secret, certificate, interactive, device code, ROPC, GCC High)
    • defender: Microsoft 365 Defender (Advanced hunting, incidents, alerts, secure score)
    • entraid: Microsoft Entra ID (Users, groups, applications, roles, policies, identity providers)
    • insights: Graph Insights API (Shared documents, trending content)
    • intune: Microsoft Intune (Managed devices, compliance, config profiles, remote actions, organization)
    • onedrive: Microsoft OneDrive (Files, folders, drives, sharing, search, versions, thumbnails)
    • onenote: Microsoft OneNote (Notebooks, sections, section groups, pages, content)
    • outlook: Outlook / Exchange Online (Mail, events, calendars)
    • planner: Microsoft Planner (Plans, buckets, tasks, assignments, details)
    • purview: Microsoft Purview (eDiscovery cases, retention labels, subject rights requests)
    • reports: M365 usage reports (Email, mailbox, OneDrive, SharePoint, Teams, etc.)
    • sharepoint: Microsoft SharePoint (Files, lists, permissions, search, taxonomy, sites, webhooks)
    • teams: Microsoft Teams (Lifecycle, channels, messages, members, apps, tabs, settings)
  8. Entra ID Governance usage scenarios

    master

    The library provides examples for several Microsoft Entra ID governance scenarios. You can find specific implementation patterns in the following files:

    • Terms of use: List agreements, check acceptances, and find pending users (requires Agreement.Read.All). See terms_of_use.py.
    • Access reviews: Manage history definitions, instances, and schedule definitions (requires AccessReview.Read.All). See access_reviews.py.
    • Access review pending decisions: Check for decisions awaiting action (requires AccessReview.Read.All). See pending_decisions.py.
    • PIM role assignments: Identify users with privileged roles (requires RoleManagement.Read.Directory). See privileged_roles.py.
    • Entitlement management: Manage access packages (requires EntitlementManagement.Read.All). See entitlement_packages.py.
    • Change notifications: Create, renew, or delete subscriptions (requires permissions varying by resource). See change_notifications.py.
  9. Manage SharePoint Hub Sites and Home Sites

    master

    The office365-rest-python-client provides capabilities to manage SharePoint Hub Sites and Home Sites.

    Key Operations:

    • Register/Unregister: Convert a site into a hub site or remove its hub status (Requires SharePoint Administrator role).
    • Associate: Connect a site to an existing hub (Requires Site Owner role on the target site).
    • Enumerate: List all hub sites, list hubs associated with a specific hub, or list all home sites.
    • Set Home Site: Designate a site as the intranet landing page (Requires SharePoint Administrator role).

    Conceptual Model:

    • A Hub Site acts as a central node that groups related sites under common navigation and branding.
    • An Associated Site inherits the theme and navigation from its parent hub.
    • A Home Site is a specific hub site designated as the intranet landing page.
  10. How SharePoint permissions and inheritance work

    master

    Permissions in SharePoint flow down the hierarchy by default: Site/Web $\rightarrow$ List/Library $\rightarrow$ Folder $\rightarrow$ File. A user with a specific permission level at the Site level automatically inherits that permission for all child objects.

    To assign unique permissions to a specific object (like a single folder or list) that differ from its parent, you must use the break_role_inheritance() method. This stops the flow of permissions from the parent level to that specific object.