<p>I’ve managed to get it working using the Office-365-REST-Python-Client you linked.</p>
<p>If you’re using SharePoint Online, you’ll need to get an <a href="https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs">App-Only principle</a> set up and connect using the acquire_token_for_app function instead of acquire_token_for_user, then passing a client_id and client_secret instead of username & password.</p>
<pre><code class="lang-auto">from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File
client_id = 'yourclientid'
client_secret = 'yourclientsecret'
url = 'https://yoursharepointsite.com/teams/yourteam'
relative_url = '/teams/yourteam/Shared%20Documents/yourteamschannel/yourdoc.extension'
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_app(client_id, client_secret):
ctx = ClientContext(url, ctx_auth)
with open(filename, 'wb') as output_file:
response = File.open_binary(ctx, relative_url)
output_file.write(response.content)
else:
print(ctx_auth.get_last_error())
</code></pre>
<p>This should download your file to a local drive (specified via the filename variable) and you can then load into pandas etc to process</p>