msgraphfs 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.4
2
+ Name: msgraphfs
3
+ Version: 0.1
4
+ Dynamic: Summary
5
+ Project-URL: Source, https://github.com/acsone/msgraphfs
6
+ Author-email: Laurent Mignon <laurent.mignon@acsone.eu>
7
+ License: The MIT License (MIT)
8
+
9
+ Copyright (c) 2024 Laurent Mignon (ACSONE)
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ License-File: LICENSE
29
+ Classifier: Intended Audience :: Developers
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Requires-Python: >=3.9
33
+ Requires-Dist: authlib
34
+ Requires-Dist: fsspec>=0.7.5
35
+ Requires-Dist: httpx[http2]
36
+ Provides-Extra: release
37
+ Requires-Dist: towncrier; extra == 'release'
38
+ Provides-Extra: test
39
+ Requires-Dist: coverage[toml]; extra == 'test'
40
+ Requires-Dist: keyring; extra == 'test'
41
+ Requires-Dist: pytest; extra == 'test'
42
+ Requires-Dist: pytest-asyncio; extra == 'test'
43
+ Requires-Dist: pytest-cov; extra == 'test'
44
+ Requires-Dist: requests; extra == 'test'
45
+ Description-Content-Type: text/markdown
46
+
47
+ # MSGraphFS
48
+
49
+ This python package is a [fsspec](https://filesystem-spec.readthedocs.io/) based filesystem-like interface to drives exposed through the Microsoft graph API (OneDrive, Sharepoint, etc).
50
+
51
+ see:
52
+ https://learn.microsoft.com/en-us/graph/api/resources/onedrive?view=graph-rest-1.0
53
+
54
+ ## Usage
55
+
56
+ To use the Microsoft Drive filesystem (for exemple a sharepoint documents libraty), you need to create a new instance of the
57
+ `msgraphfs.MSGDriveFS` class. You can also use the `msgd` protocol to lookup the
58
+ class using `fsspec.get_filesystem_class`.
59
+
60
+ ```python
61
+ import msgraphfs
62
+
63
+ fs = msgraphfs.MSGDriveFS(
64
+ client_id="YOUR_CLIENT_ID",
65
+ drive_id="YOUR_DRIVE_ID",
66
+ oauth2_client_params = {...})
67
+
68
+ fs.ls("/")
69
+
70
+ with fs.open("/path/to/file.txt") as f:
71
+ print(f.read())
72
+ ```
73
+
74
+ ```python
75
+
76
+ import fsspec
77
+
78
+ fs = fsspec.get_filesystem_class("msgd")(
79
+ client_id="YOUR_CLIENT
80
+ drive_id="YOUR_DRIVE_ID",
81
+ oauth2_client_params = {...})
82
+
83
+ fs.ls("/")
84
+
85
+ ```
86
+
87
+ ### Specific functionalities
88
+
89
+ - `ls`, `info` : Both methods can take an `expand` additional argument. This
90
+ argument is a string that will be passed as the `expand` query parameter to
91
+ the microsoft graph API call used to get the file information. This can be
92
+ used to get additional information about the file, such as the `thumbnails` or
93
+ the `permissions` or ...
94
+
95
+ - `checkin`, `checkout` : These methods are used to checkin/checkout a file.
96
+ They take the path of the file to checkin/checkout as argument. The `checking`
97
+ method also take an additional `comment`.
98
+
99
+ - `get_versions` : This method returns the list of versions of a file. It takes
100
+ the path of the file as argument.
101
+
102
+ - `preview` : This method returns a url to a preview of the file. It takes the
103
+ path of the file as argument.
104
+
105
+ - `get_content` : This method returns the content of a file. It takes the path
106
+ or the item_id of the file as argument. You can also pass the `format` argument
107
+ to specify the expected format of the content. This is useful for example to
108
+ convert a word document to a pdf.
109
+
110
+ In addition to the methods above, some methods can take an `item_id` additional
111
+ arguments. This argument is the id of the drive item provided by the Microsoft
112
+ Graph API. It can be used to avoid the need to make an additional API call to
113
+ get the item id or to store a reference to a drive item independently of the
114
+ path. (If the drive item is moved, the path will change but the item id will
115
+ not).
116
+
117
+ ## Installation
118
+
119
+ ```bash
120
+ pip install msgraphfs
121
+ ```
122
+
123
+ ### Get your drive id
124
+
125
+ To get the drive id of your drive, you can use the microsoft graph explorer:
126
+ https://developer.microsoft.com/en-us/graph/graph-explorer
127
+
128
+ The first step is to get the site id of your site. You can do this by making a
129
+ GET request to the following url:
130
+
131
+ ```bash
132
+ https://graph.microsoft.com/v1.0/sites/{url}
133
+ ```
134
+
135
+ where `{url}` is the url of your site without the protocol. For example, if your
136
+ site is `https://mycompany.sharepoint.com/sites/mysite`, you should use
137
+ `mycompany.sharepoint.com/sites/mysite` as the url.
138
+
139
+ In the response, you will find the `id` of the site.
140
+
141
+
142
+ Now your can get the drive id of the drive you want to access. To do this, you
143
+ can make a GET request to the following url:
144
+
145
+ ```bash
146
+ https://graph.microsoft.com/v1.0/sites/{site_id}/drives/
147
+ ```
148
+
149
+ where `{site_id}` is the id of the site you got in the previous step.
150
+
151
+ ## Development
152
+
153
+ To develop this package, you can clone the repository and install the
154
+ dependencies using pip:
155
+
156
+ ```bash
157
+ git clone your-repo-url (a fork of https://github.com/acsone/msgraphfs)
158
+ pip install -e .
159
+ ```
160
+
161
+ This will install the package in editable mode, so you can make changes to the
162
+ code and test them without having to reinstall the package every time.
163
+
164
+ To run the tests, you will need to install the test dependencies. You can do this by running:
165
+
166
+ ```bash
167
+ pip install -e .[test]
168
+ ```
169
+
170
+ Testing the package requires you to have access to a Microsoft Drive (OneDrive, Sharepoint, etc) and to have the `client_id`, `client_secret`, `tenant_id`, `dirve_id`, `site_name` and the user's
171
+ access token.
172
+
173
+ ### How to get an access token required for testing
174
+
175
+ The first step is to get your user's access token.
176
+
177
+
178
+ ### Prerequisites
179
+
180
+ - A registered Azure AD application with:
181
+ - `client_id` and `client_secret`
182
+ - Delegated permissions granted (e.g., `Files.ReadWrite.All`, `Sites.ReadWrite.All`)
183
+ - A redirect URI configured (e.g., `http://localhost:5000/callback`)
184
+
185
+
186
+ #### 1. Build the OAuth2 authorization URL
187
+
188
+ Open the following URL in your browser (replace values as needed):
189
+
190
+ ```bash
191
+ https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/authorize?
192
+ client_id=<CLIENT_ID>
193
+ &response_type=code
194
+ &redirect_uri=http://localhost:5000/callback
195
+ &response_mode=query
196
+ &scope=offline_access%20User.Read%20Files.ReadWrite.All%20Sites.ReadWrite.All
197
+ ```
198
+
199
+ You will be prompted to log in with your Microsoft account and grant the requested permissions.
200
+
201
+ #### 2. Copy the Authorization Code
202
+
203
+ After login, you'll be redirected to:
204
+
205
+ ```bash
206
+ http://localhost:5000/callback?code=<AUTHORIZATION_CODE>
207
+ ```
208
+
209
+ Copy the value of `code` from the URL.
210
+
211
+
212
+ ### Launch the test suite
213
+
214
+ To run the test suite, you just need to run the pytest command in the root directory with the following arguments:
215
+
216
+ * --auth-code: The authorization code you got in the previous step. (It's only required if you launch the tests for the first time or if your refresh token is expired and you need to get a new access token)
217
+ * --client-id: The client id of your Azure AD application.
218
+ * --client-secret: The client secret of your Azure AD application.
219
+ * --tenant-id: The tenant id of your Azure AD application.
220
+ * --drive-id: The drive id of the drive you want to access.
221
+ * --site-name: The name of the site you want to access. (Only required for tests related to the access to the recycling bin)
222
+
223
+ ```bash
224
+ pytest --auth-code <AUTH_CODE> \
225
+ --client-id <CLIENT_ID> \
226
+ --client-secret <CLIENT_SECRET> \
227
+ --tenant-id <TENANT_ID> \
228
+ --drive-id <DRIVE_ID> \
229
+ --site-name <SITE_NAME> \
230
+ tests
231
+ ```
232
+
233
+ Alternatively, you can set the environment variables `MSGRAPHFS_AUTH_CODE`, `MSGRAPHFS_CLIENT_ID`, `MSGRAPHFS_CLIENT_SECRET`, `MSGRAPHFS_TENANT_ID`, `MSGRAPHFS_DRIVE_ID` and `MSGRAPHFS_SITE_NAME` to avoid passing the arguments to pytest.
234
+
235
+ When the auth-code is provided and we need to get the access token (IOW when it's the first time you run the tests or when your refresh token is expired), the package will automatically get the access token and store it
236
+ in a encrypted file into the keyring of your system. The call to the token endpoint requires a `redirect_uri` parameter. This one should match one of the redirect URIs you configured in your Azure AD application.
237
+ By default, it is set to `http://localhost:8069/microsoft_account/authentication`, but you can change it by setting the environment variable `MSGRAPHFS_AUTH_REDIRECT_URI` or by passing the `--auth-redirect-uri` argument to pytest.
238
+
239
+ ### Pre-commit hooks
240
+
241
+ To ensure code quality, this package uses pre-commit hooks. You can install them by running:
242
+
243
+ ```bash
244
+ pre-commit install
245
+ ```
246
+ This will set up the pre-commit hooks to run automatically before each commit. You can also run them manually by executing:
247
+
248
+ ```bash
249
+ pre-commit run --all-files
250
+ ```
@@ -0,0 +1,7 @@
1
+ msgraphfs/__init__.py,sha256=_XpM_VY9EookAhjICTvnL2lbwhlPdXQcyZ6opy9KKnA,70
2
+ msgraphfs/core.py,sha256=fma23Zziqi-dyDxLd3RMx-9ng2E6Gixa1WkKE4tHyt0,50582
3
+ msgraphfs-0.1.dist-info/METADATA,sha256=Mv6lnKl-dussT0O_2h-BlSGChH5iQ53MtlZe7xvo13g,9339
4
+ msgraphfs-0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ msgraphfs-0.1.dist-info/entry_points.txt,sha256=QfPNuPkEgjtFMfKii0Ly71DN84YjoeLUZvhjz7jxQa8,43
6
+ msgraphfs-0.1.dist-info/licenses/LICENSE,sha256=hM-SxjosGhG2YdOER2QqQ6-mbYzSSxelOsOrzlPxFvI,1090
7
+ msgraphfs-0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [fsspec.specs]
2
+ msgd = msgraphfs.MSGDriveFS
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Laurent Mignon (ACSONE)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.