You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Checkout and check-in are supported through the SharePoint REST v1 client:
fromoffice365.sharepoint.files.checkin_typeimportCheckinTypefile=ctx.web.get_file_by_server_relative_path("Shared Documents/draft.docx")
file.checkout().execute_query()
file.checkin("Updated via API", CheckinType.MajorCheckIn).execute_query()
# or, to discard the check-out:# file.undocheckout().execute_query()
On impersonation: SharePoint REST has no "run as user" switch — a request executes as whoever the access token represents, so a check-out is always attributed to the authenticated identity. To check out as a given site user you must authenticate as that user with a delegated flow, then call file.checkout():
Delegated:with_username_and_password(...), with_interactive(...), with_device_flow(...), or with_access_token(...) if you obtain an on-behalf-of token in a middle-tier service.
App-only:with_client_certificate(...) runs as the application, so it cannot be used to attribute a check-out to another user. (with_client_secret(...) is also not accepted by SharePoint /_api.)
If the goal is to clear a file that someone else left checked out, list the library's checked-out files and take over the check-out — this requires sufficient permissions (e.g. site collection admin):
Activity
office365-maintainer commentedon Oct 3, 2026
Checkout and check-in are supported through the SharePoint REST v1 client:
A runnable end-to-end example is in
examples/sharepoint/files/checkout_checkin.py.On impersonation: SharePoint REST has no "run as user" switch — a request executes as whoever the access token represents, so a check-out is always attributed to the authenticated identity. To check out as a given site user you must authenticate as that user with a delegated flow, then call
file.checkout():with_username_and_password(...),with_interactive(...),with_device_flow(...), orwith_access_token(...)if you obtain an on-behalf-of token in a middle-tier service.with_client_certificate(...)runs as the application, so it cannot be used to attribute a check-out to another user. (with_client_secret(...)is also not accepted by SharePoint/_api.)If the goal is to clear a file that someone else left checked out, list the library's checked-out files and take over the check-out — this requires sufficient permissions (e.g. site collection admin):
Closing this as answered — please reopen if you had a different scenario in mind.