Name | fs.onedrivefs JSON |
Version |
1.2.2
JSON |
| download |
home_page | None |
Summary | Pyfilesystem2 implementation for OneDrive using Microsoft Graph API |
upload_time | 2024-12-02 04:02:43 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
pyfilesystem2
filesystem
onedrive
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# fs.onedrivefs
Implementation of pyfilesystem2 file system using OneDrive
 [](https://codecov.io/gh/rkhwaja/fs.onedrivefs) [](https://badge.fury.io/py/fs.onedrivefs)
# Usage
`fs.onedrivefs` can create a [`requests_oauthlib.OAuth2Session`](https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#) for you. This way the `OAuth2Session` is going to refresh the tokens for you.
``` python
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`](https://requests.readthedocs.io/en/latest/user/advanced/#session-objects).
Here is an example of a custom session using [MSAL Python](https://learn.microsoft.com/en-us/entra/msal/python/)
``` 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](https://docs.microsoft.com/en-us/graph/auth-register-app-v2) to get a client ID and secret
Raw data
{
"_id": null,
"home_page": null,
"name": "fs.onedrivefs",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Rehan KHwaja <rehan@khwaja.name>",
"keywords": "Pyfilesystem2, filesystem, onedrive",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/16/52/02d9d49990091d0c196c257407440b218a009c9d2a23d9019b34e6830562/fs_onedrivefs-1.2.2.tar.gz",
"platform": null,
"description": "# fs.onedrivefs\n\nImplementation of pyfilesystem2 file system using OneDrive\n\n [](https://codecov.io/gh/rkhwaja/fs.onedrivefs) [](https://badge.fury.io/py/fs.onedrivefs)\n\n# Usage\n\n`fs.onedrivefs` can create a [`requests_oauthlib.OAuth2Session`](https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#) for you. This way the `OAuth2Session` is going to refresh the tokens for you.\n\n``` python\nonedriveFS = OneDriveFS(\n clientId=<your client id>,\n clientSecret=<your client secret>,\n token=<token JSON saved by oauth2lib>,\n SaveToken=<function which saves a new token string after refresh>)\n\n# onedriveFS is now a standard pyfilesystem2 file system\n```\n\nYou can handle the tokens outside of the library by passing a [`requests.Session`](https://requests.readthedocs.io/en/latest/user/advanced/#session-objects).\nHere is an example of a custom session using [MSAL Python](https://learn.microsoft.com/en-us/entra/msal/python/)\n\n``` python\nclass MSALSession(OAuth2Session):\n def __init__(self, client: msal.ClientApplication):\n super().__init__()\n self.client = client\n\n def request(self, *args, **kwargs):\n account = self.client.get_accounts()[0]\n self.token = self.client.acquire_token_silent_with_error(\n scopes=[\"Files.ReadWrite\"], account=account\n )\n\n return super().request(*args, **kwargs)\n\nclient = msal.ConfidentialClientApplication(\n client_id=<your client id>,\n client_credential=<your client secret>,\n authority=f\"https://login.microsoftonline.com/<your tenant>\",\n token_cache=<your token cache>,\n)\n\n# Authentication flow to populate the token cache\n# YOUR AUTHENTICATION FLOW\n\nsession = MSALSession(client=client)\nonedriveFS = OneDriveFS(session=session)\n\n# onedriveFS is now a standard pyfilesystem2 file system\n```\n\nRegister your app [here](https://docs.microsoft.com/en-us/graph/auth-register-app-v2) to get a client ID and secret\n",
"bugtrack_url": null,
"license": null,
"summary": "Pyfilesystem2 implementation for OneDrive using Microsoft Graph API",
"version": "1.2.2",
"project_urls": {
"Homepage": "https://github.com/rkhwaja/fs.onedrivefs"
},
"split_keywords": [
"pyfilesystem2",
" filesystem",
" onedrive"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "b583432202ca89ece4ad4d3a13b6652d09fb59d1e32e5820c0be503d7fe67d7e",
"md5": "bc430a79f2d196ab1b8de1032ce540d5",
"sha256": "c8d93c6b7848734a8d5192c523934eda89608fade8ff50d215f514b0d8aeeba0"
},
"downloads": -1,
"filename": "fs_onedrivefs-1.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bc430a79f2d196ab1b8de1032ce540d5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 11259,
"upload_time": "2024-12-02T04:02:41",
"upload_time_iso_8601": "2024-12-02T04:02:41.934892Z",
"url": "https://files.pythonhosted.org/packages/b5/83/432202ca89ece4ad4d3a13b6652d09fb59d1e32e5820c0be503d7fe67d7e/fs_onedrivefs-1.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "165202d9d49990091d0c196c257407440b218a009c9d2a23d9019b34e6830562",
"md5": "080f8b6fcb6b59526254737e1adc4575",
"sha256": "721f9784149c09eba0b8bb82e0138e3e0903cd5d3fba54ba63a505f1ae83cad7"
},
"downloads": -1,
"filename": "fs_onedrivefs-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "080f8b6fcb6b59526254737e1adc4575",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 596642,
"upload_time": "2024-12-02T04:02:43",
"upload_time_iso_8601": "2024-12-02T04:02:43.371369Z",
"url": "https://files.pythonhosted.org/packages/16/52/02d9d49990091d0c196c257407440b218a009c9d2a23d9019b34e6830562/fs_onedrivefs-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 04:02:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rkhwaja",
"github_project": "fs.onedrivefs",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fs.onedrivefs"
}