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.0.tar.gz (595.8 kB view details)

Uploaded Source

Built Distribution

fs_onedrivefs-1.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fs_onedrivefs-1.2.0.tar.gz
  • Upload date:
  • Size: 595.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for fs_onedrivefs-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7229681ae3b9fc9816c6aeb022165ce53f9dde9bcffc09c9a45537c6d3089a8f
MD5 12598b9a643ab1fd1480a816240acf0a
BLAKE2b-256 588bdd59bef50df6bb99c5674b0decc164f1f7b4b8cd4570978bbde7c4b6161a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fs_onedrivefs-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae2fc84e2a05d4f9acae0835d65eda7fb222809c4cdfaa937c428101f3693213
MD5 7069ab46a82bd206fd8841b168114046
BLAKE2b-256 ccbc4c87146729d9fddaa9654178e82f616ef3497732ff17b3f982e74adc3131

See more details on using hashes here.

Supported by

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