Skip to main content

Pyfilesystem2 implementation for OneDrive using Microsoft Graph API

Project description

fs.onedrivefs

Implementation of pyfilesystem2 file system using OneDrive

image codecov PyPI version

Usage

fs.onedrivefs can create a requests_oauthlib.OAuth2Session for you. This way the OAuth2Session is going to refresh the tokens for you.

onedriveFS = OneDriveFS(
  clientId=<your client id>,
  clientSecret=<your client secret>,
  token=<token JSON saved by oauth2lib>,
  SaveToken=<function which saves a new token string after refresh>)

# onedriveFS is now a standard pyfilesystem2 file system

You can handle the tokens outside of the library by passing a requests.Session. Here is an example of a custom session using MSAL Python

class MSALSession(OAuth2Session):
  def __init__(self, client: msal.ClientApplication):
    super().__init__()
    self.client = client

  def request(self, *args, **kwargs):
    account = self.client.get_accounts()[0]
    self.token = self.client.acquire_token_silent_with_error(
      scopes=["Files.ReadWrite"], account=account
    )

    return super().request(*args, **kwargs)

client = msal.ConfidentialClientApplication(
  client_id=<your client id>,
  client_credential=<your client secret>,
  authority=f"https://login.microsoftonline.com/<your tenant>",
  token_cache=<your token cache>,
)

# Authentication flow to populate the token cache
# YOUR AUTHENTICATION FLOW

session = MSALSession(client=client)
onedriveFS = OneDriveFS(session=session)

# onedriveFS is now a standard pyfilesystem2 file system

Register your app here to get a client ID and secret

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fs_onedrivefs-1.2.2.tar.gz (596.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fs_onedrivefs-1.2.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file fs_onedrivefs-1.2.2.tar.gz.

File metadata

  • Download URL: fs_onedrivefs-1.2.2.tar.gz
  • Upload date:
  • Size: 596.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.4

File hashes

Hashes for fs_onedrivefs-1.2.2.tar.gz
Algorithm Hash digest
SHA256 721f9784149c09eba0b8bb82e0138e3e0903cd5d3fba54ba63a505f1ae83cad7
MD5 080f8b6fcb6b59526254737e1adc4575
BLAKE2b-256 165202d9d49990091d0c196c257407440b218a009c9d2a23d9019b34e6830562

See more details on using hashes here.

File details

Details for the file fs_onedrivefs-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fs_onedrivefs-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8d93c6b7848734a8d5192c523934eda89608fade8ff50d215f514b0d8aeeba0
MD5 bc430a79f2d196ab1b8de1032ce540d5
BLAKE2b-256 b583432202ca89ece4ad4d3a13b6652d09fb59d1e32e5820c0be503d7fe67d7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page