spio 0.0.0__tar.gz
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.
Potentially problematic release.
This version of spio might be problematic. Click here for more details.
- spio-0.0.0/LICENSE.md +19 -0
- spio-0.0.0/PKG-INFO +286 -0
- spio-0.0.0/README.md +266 -0
- spio-0.0.0/pyproject.toml +26 -0
- spio-0.0.0/src/marvin/__init__.py +0 -0
- spio-0.0.0/src/marvin/tools/default_config.ini +11 -0
- spio-0.0.0/src/marvin/tools/spio.py +1316 -0
spio-0.0.0/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
spio-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: spio
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Magical Marvin SharePoint Library
|
|
5
|
+
Author: Roeland Maes
|
|
6
|
+
Author-email: roeland.maes@vito.be
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Provides-Extra: full
|
|
13
|
+
Provides-Extra: pandas
|
|
14
|
+
Provides-Extra: pandas-parquet
|
|
15
|
+
Provides-Extra: pandas-xlsx
|
|
16
|
+
Requires-Dist: Office365-REST-Python-Client (>=2.3,<3.0)
|
|
17
|
+
Requires-Dist: msal_extensions (>=0.3,<0.4)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Spio
|
|
22
|
+
|
|
23
|
+
## Description
|
|
24
|
+
|
|
25
|
+
Spio is a Python package that provides functionalities for reading and writing data to a SharePoint.
|
|
26
|
+
It can also handle various types of spatial and non-spatial data formats such as GeoTIFF, GeoPackage, NetCDF, CSV, Excel, and more.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
To install the package, you can use the following command:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install spio
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
If you want to install the package with all the dependencies, you can use the following command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install spio[full]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Building from Source
|
|
43
|
+
|
|
44
|
+
To build the package from source you can use the following commands:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://git.vito.be/projects/MARVIN/repos/sharepoint_tools
|
|
48
|
+
cd sharepoint_tools
|
|
49
|
+
conda create -f conda_env.yml
|
|
50
|
+
conda activate spio
|
|
51
|
+
poetry install
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Configuration
|
|
55
|
+
|
|
56
|
+
Before using the package, you need to configure the settings to match your environment.
|
|
57
|
+
The configuration is managed through a `settings` module which should include all the necessary configurations.
|
|
58
|
+
|
|
59
|
+
### **Settings Configuration**:
|
|
60
|
+
Ensure you have a `settings` file (e.g., `.secrets.yaml` or `settings.yaml`) that provides the necessary configuration options. Example:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from dynaconf import Dynaconf
|
|
64
|
+
|
|
65
|
+
settings = Dynaconf(
|
|
66
|
+
settings_files=['settings.yaml', '.secrets.yaml']
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The settings file should include the following configurations:
|
|
71
|
+
|
|
72
|
+
```yaml
|
|
73
|
+
user_account: your.name@vito.be
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### **Initialize Spio with Settings**:
|
|
77
|
+
You need to initialize Spio with your settings before using any functionalities.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from config import settings
|
|
81
|
+
from marvin.tools import spio
|
|
82
|
+
|
|
83
|
+
spio.init_spio(settings)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
|
|
88
|
+
Here are some example usages of the package:
|
|
89
|
+
|
|
90
|
+
### Reading Data
|
|
91
|
+
|
|
92
|
+
- **Read GeoTIFF using Rasterio**:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from marvin.tools.spio import SPIO
|
|
96
|
+
import rasterio
|
|
97
|
+
|
|
98
|
+
geotiff_file = SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geotiff.tiff')
|
|
99
|
+
with rasterio.open(geotiff_file.copy_bytes_io()) as src:
|
|
100
|
+
# Read the dataset's metadata
|
|
101
|
+
print("Metadata:", src.meta)
|
|
102
|
+
print("CRS:", src.crs)
|
|
103
|
+
print("Bounds:", src.bounds)
|
|
104
|
+
data = src.read()
|
|
105
|
+
print("data: ", data.shape)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- **Read GeoTIFF using GDAL**:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from marvin.tools.spio import SPIO
|
|
112
|
+
from osgeo import gdal
|
|
113
|
+
|
|
114
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geotiff.tiff') as spio:
|
|
115
|
+
dataset = gdal.Open(spio.copy_file())
|
|
116
|
+
band = dataset.GetRasterBand(1)
|
|
117
|
+
data = band.ReadAsArray()
|
|
118
|
+
print("data: ", data.shape)
|
|
119
|
+
# Close the dataset
|
|
120
|
+
del dataset
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- **Read GeoPackage**:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from marvin.tools.spio import SPIO
|
|
127
|
+
import geopandas as gpd
|
|
128
|
+
|
|
129
|
+
gdf = gpd.read_file(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geopackage.gpkg'))
|
|
130
|
+
print("gdf: ", gdf)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **Read NetCDF (h5netcdf)**:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from marvin.tools.spio import SPIO
|
|
137
|
+
import xarray as xr
|
|
138
|
+
|
|
139
|
+
ds = xr.load_dataset(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/netcdf.nc')) # use engine='h5netcdf' if not detected correctly
|
|
140
|
+
print("ds: ", ds)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- **Read NetCDF (netcdf4)**:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from marvin.tools.spio import SPIO
|
|
147
|
+
import xarray as xr
|
|
148
|
+
|
|
149
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/netcdf.nc') as spio:
|
|
150
|
+
ds = xr.load_dataset(spio.copy_file(), engine='netcdf4')
|
|
151
|
+
print("ds: ", ds)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- **Read GRIB**:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from marvin.tools.spio import SPIO
|
|
158
|
+
import xarray as xr
|
|
159
|
+
|
|
160
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/grib.grb') as spio:
|
|
161
|
+
grb_ds = xr.load_dataset(spio.copy_file()) # engine='cfgrib'
|
|
162
|
+
print("grb_ds: ", grb_ds)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
- **Read Parquet**:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from marvin.tools.spio import SPIO
|
|
169
|
+
import pandas as pd
|
|
170
|
+
|
|
171
|
+
df = pd.read_parquet(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.parquet'))
|
|
172
|
+
print("df: ", df)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
- **Read CSV**:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from marvin.tools.spio import SPIO
|
|
179
|
+
import pandas as pd
|
|
180
|
+
|
|
181
|
+
df = pd.read_csv(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.csv'))
|
|
182
|
+
print(f"df: , df")
|
|
183
|
+
|
|
184
|
+
# read first lines
|
|
185
|
+
df_top = pd.read_csv(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.csv', read_chunks=SPIO.DEFAULT_CHUNK_SIZE), sep=';', nrows=10)
|
|
186
|
+
print(f"df_top: , df_top")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- **Read Excel**:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from marvin.tools.spio import SPIO
|
|
193
|
+
import pandas as pd
|
|
194
|
+
|
|
195
|
+
df = pd.read_excel(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.xlsx'))
|
|
196
|
+
print("df: ", df)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
### Writing Data
|
|
201
|
+
|
|
202
|
+
- **Write CSV**:
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from marvin.tools.spio import SPIO
|
|
206
|
+
import pandas as pd
|
|
207
|
+
|
|
208
|
+
df = pd.read_csv('path/to/your/data.csv')
|
|
209
|
+
df.to_csv(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.csv'))
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- **Write Excel**:
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from marvin.tools.spio import SPIO
|
|
216
|
+
import pandas as pd
|
|
217
|
+
|
|
218
|
+
df = pd.read_csv('path/to/your/data.csv')
|
|
219
|
+
df.to_excel(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.xlsx'), engine='xlsxwriter')
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
- **Write Text**:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from marvin.tools.spio import SPIO
|
|
226
|
+
|
|
227
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.txt') as spio:
|
|
228
|
+
spio.write_lines(['Hello, SPIO!'])
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
- **Write GeoTiff**:
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from marvin.tools.spio import SPIO
|
|
236
|
+
import rasterio
|
|
237
|
+
|
|
238
|
+
with rasterio.open('path/to/your/map.tiff') as src:
|
|
239
|
+
data = src.read()[0]
|
|
240
|
+
profile = src.profile
|
|
241
|
+
|
|
242
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/map.tiff') as spio: # rasterio will not flush or close the SPIO file, so we need to do it ourselves
|
|
243
|
+
with rasterio.open(spio, 'w', **profile) as dst:
|
|
244
|
+
dst.write(data, 1)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
- **Write GeoPackage Fiona**:
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
from marvin.tools.spio import SPIO
|
|
252
|
+
import geopandas as gpd
|
|
253
|
+
|
|
254
|
+
gdf = gpd.read_file('path/to/your/geopackage.gpkg')
|
|
255
|
+
|
|
256
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geopackage.gpkg') as spio: # fiona will not flush or close the IO-object, so we need to do it ourselves
|
|
257
|
+
gdf.to_file(spio, layer='mylayer', driver='GPKG', engine='fiona')
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
- **Write GeoPackage Fiona**:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from marvin.tools.spio import SPIO
|
|
264
|
+
import geopandas as gpd
|
|
265
|
+
|
|
266
|
+
gdf = gpd.read_file('path/to/your/geopackage.gpkg')
|
|
267
|
+
|
|
268
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geopackage.gpkg') as spio: # pyogrio will not flush the IO-object
|
|
269
|
+
gdf.to_file(spio.io_delegate(), layer='mylayer', driver='GPKG', engine='pyogrio') # pyogrio can only write to a real BytesIO object.
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Additional Functionalities
|
|
273
|
+
|
|
274
|
+
Spio also provides additional functions to handle different data formats and processes.
|
|
275
|
+
You can explore these in the https://git.vito.be/projects/MARVIN/repos/sharepoint_tools/browse/test/tst_spio.py.
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
## Contributing
|
|
279
|
+
|
|
280
|
+
If you want to contribute to spio, please follow the standard contributing guidelines and push your changes to a new branch in
|
|
281
|
+
https://git.vito.be/projects/MARVIN/repos/sharepoint_tools
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
This project is licensed under the MIT License - see the LICENSE.md file for details.
|
|
286
|
+
|
spio-0.0.0/README.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
|
|
2
|
+
# Spio
|
|
3
|
+
|
|
4
|
+
## Description
|
|
5
|
+
|
|
6
|
+
Spio is a Python package that provides functionalities for reading and writing data to a SharePoint.
|
|
7
|
+
It can also handle various types of spatial and non-spatial data formats such as GeoTIFF, GeoPackage, NetCDF, CSV, Excel, and more.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
To install the package, you can use the following command:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install spio
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If you want to install the package with all the dependencies, you can use the following command:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install spio[full]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Building from Source
|
|
24
|
+
|
|
25
|
+
To build the package from source you can use the following commands:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://git.vito.be/projects/MARVIN/repos/sharepoint_tools
|
|
29
|
+
cd sharepoint_tools
|
|
30
|
+
conda create -f conda_env.yml
|
|
31
|
+
conda activate spio
|
|
32
|
+
poetry install
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
Before using the package, you need to configure the settings to match your environment.
|
|
38
|
+
The configuration is managed through a `settings` module which should include all the necessary configurations.
|
|
39
|
+
|
|
40
|
+
### **Settings Configuration**:
|
|
41
|
+
Ensure you have a `settings` file (e.g., `.secrets.yaml` or `settings.yaml`) that provides the necessary configuration options. Example:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from dynaconf import Dynaconf
|
|
45
|
+
|
|
46
|
+
settings = Dynaconf(
|
|
47
|
+
settings_files=['settings.yaml', '.secrets.yaml']
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The settings file should include the following configurations:
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
user_account: your.name@vito.be
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### **Initialize Spio with Settings**:
|
|
58
|
+
You need to initialize Spio with your settings before using any functionalities.
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from config import settings
|
|
62
|
+
from marvin.tools import spio
|
|
63
|
+
|
|
64
|
+
spio.init_spio(settings)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
Here are some example usages of the package:
|
|
70
|
+
|
|
71
|
+
### Reading Data
|
|
72
|
+
|
|
73
|
+
- **Read GeoTIFF using Rasterio**:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from marvin.tools.spio import SPIO
|
|
77
|
+
import rasterio
|
|
78
|
+
|
|
79
|
+
geotiff_file = SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geotiff.tiff')
|
|
80
|
+
with rasterio.open(geotiff_file.copy_bytes_io()) as src:
|
|
81
|
+
# Read the dataset's metadata
|
|
82
|
+
print("Metadata:", src.meta)
|
|
83
|
+
print("CRS:", src.crs)
|
|
84
|
+
print("Bounds:", src.bounds)
|
|
85
|
+
data = src.read()
|
|
86
|
+
print("data: ", data.shape)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- **Read GeoTIFF using GDAL**:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from marvin.tools.spio import SPIO
|
|
93
|
+
from osgeo import gdal
|
|
94
|
+
|
|
95
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geotiff.tiff') as spio:
|
|
96
|
+
dataset = gdal.Open(spio.copy_file())
|
|
97
|
+
band = dataset.GetRasterBand(1)
|
|
98
|
+
data = band.ReadAsArray()
|
|
99
|
+
print("data: ", data.shape)
|
|
100
|
+
# Close the dataset
|
|
101
|
+
del dataset
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- **Read GeoPackage**:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from marvin.tools.spio import SPIO
|
|
108
|
+
import geopandas as gpd
|
|
109
|
+
|
|
110
|
+
gdf = gpd.read_file(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geopackage.gpkg'))
|
|
111
|
+
print("gdf: ", gdf)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- **Read NetCDF (h5netcdf)**:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from marvin.tools.spio import SPIO
|
|
118
|
+
import xarray as xr
|
|
119
|
+
|
|
120
|
+
ds = xr.load_dataset(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/netcdf.nc')) # use engine='h5netcdf' if not detected correctly
|
|
121
|
+
print("ds: ", ds)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- **Read NetCDF (netcdf4)**:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from marvin.tools.spio import SPIO
|
|
128
|
+
import xarray as xr
|
|
129
|
+
|
|
130
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/netcdf.nc') as spio:
|
|
131
|
+
ds = xr.load_dataset(spio.copy_file(), engine='netcdf4')
|
|
132
|
+
print("ds: ", ds)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- **Read GRIB**:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from marvin.tools.spio import SPIO
|
|
139
|
+
import xarray as xr
|
|
140
|
+
|
|
141
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/grib.grb') as spio:
|
|
142
|
+
grb_ds = xr.load_dataset(spio.copy_file()) # engine='cfgrib'
|
|
143
|
+
print("grb_ds: ", grb_ds)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
- **Read Parquet**:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from marvin.tools.spio import SPIO
|
|
150
|
+
import pandas as pd
|
|
151
|
+
|
|
152
|
+
df = pd.read_parquet(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.parquet'))
|
|
153
|
+
print("df: ", df)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- **Read CSV**:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from marvin.tools.spio import SPIO
|
|
160
|
+
import pandas as pd
|
|
161
|
+
|
|
162
|
+
df = pd.read_csv(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.csv'))
|
|
163
|
+
print(f"df: , df")
|
|
164
|
+
|
|
165
|
+
# read first lines
|
|
166
|
+
df_top = pd.read_csv(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.csv', read_chunks=SPIO.DEFAULT_CHUNK_SIZE), sep=';', nrows=10)
|
|
167
|
+
print(f"df_top: , df_top")
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
- **Read Excel**:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from marvin.tools.spio import SPIO
|
|
174
|
+
import pandas as pd
|
|
175
|
+
|
|
176
|
+
df = pd.read_excel(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.xlsx'))
|
|
177
|
+
print("df: ", df)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
### Writing Data
|
|
182
|
+
|
|
183
|
+
- **Write CSV**:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from marvin.tools.spio import SPIO
|
|
187
|
+
import pandas as pd
|
|
188
|
+
|
|
189
|
+
df = pd.read_csv('path/to/your/data.csv')
|
|
190
|
+
df.to_csv(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.csv'))
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
- **Write Excel**:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from marvin.tools.spio import SPIO
|
|
197
|
+
import pandas as pd
|
|
198
|
+
|
|
199
|
+
df = pd.read_csv('path/to/your/data.csv')
|
|
200
|
+
df.to_excel(SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.xlsx'), engine='xlsxwriter')
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- **Write Text**:
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
from marvin.tools.spio import SPIO
|
|
207
|
+
|
|
208
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/data.txt') as spio:
|
|
209
|
+
spio.write_lines(['Hello, SPIO!'])
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
- **Write GeoTiff**:
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
from marvin.tools.spio import SPIO
|
|
217
|
+
import rasterio
|
|
218
|
+
|
|
219
|
+
with rasterio.open('path/to/your/map.tiff') as src:
|
|
220
|
+
data = src.read()[0]
|
|
221
|
+
profile = src.profile
|
|
222
|
+
|
|
223
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/map.tiff') as spio: # rasterio will not flush or close the SPIO file, so we need to do it ourselves
|
|
224
|
+
with rasterio.open(spio, 'w', **profile) as dst:
|
|
225
|
+
dst.write(data, 1)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
- **Write GeoPackage Fiona**:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from marvin.tools.spio import SPIO
|
|
233
|
+
import geopandas as gpd
|
|
234
|
+
|
|
235
|
+
gdf = gpd.read_file('path/to/your/geopackage.gpkg')
|
|
236
|
+
|
|
237
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geopackage.gpkg') as spio: # fiona will not flush or close the IO-object, so we need to do it ourselves
|
|
238
|
+
gdf.to_file(spio, layer='mylayer', driver='GPKG', engine='fiona')
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
- **Write GeoPackage Fiona**:
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
from marvin.tools.spio import SPIO
|
|
245
|
+
import geopandas as gpd
|
|
246
|
+
|
|
247
|
+
gdf = gpd.read_file('path/to/your/geopackage.gpkg')
|
|
248
|
+
|
|
249
|
+
with SPIO('https://yourdomain.sharepoint.com/:i:/r/sites/your-site/path/to/your/geopackage.gpkg') as spio: # pyogrio will not flush the IO-object
|
|
250
|
+
gdf.to_file(spio.io_delegate(), layer='mylayer', driver='GPKG', engine='pyogrio') # pyogrio can only write to a real BytesIO object.
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Additional Functionalities
|
|
254
|
+
|
|
255
|
+
Spio also provides additional functions to handle different data formats and processes.
|
|
256
|
+
You can explore these in the https://git.vito.be/projects/MARVIN/repos/sharepoint_tools/browse/test/tst_spio.py.
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
## Contributing
|
|
260
|
+
|
|
261
|
+
If you want to contribute to spio, please follow the standard contributing guidelines and push your changes to a new branch in
|
|
262
|
+
https://git.vito.be/projects/MARVIN/repos/sharepoint_tools
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
This project is licensed under the MIT License - see the LICENSE.md file for details.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
[tool.poetry]
|
|
3
|
+
name = "spio"
|
|
4
|
+
version = "0.0.0"
|
|
5
|
+
description = "Magical Marvin SharePoint Library"
|
|
6
|
+
authors = ["Roeland Maes <roeland.maes@vito.be>", "Thomas Danckaert <thomas.danckaert@vito.be>"]
|
|
7
|
+
packages = [
|
|
8
|
+
{ include = "src/marvin" }
|
|
9
|
+
]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
|
|
12
|
+
[tool.poetry.dependencies]
|
|
13
|
+
python = "^3.10"
|
|
14
|
+
msal_extensions = "^0.3"
|
|
15
|
+
Office365-REST-Python-Client = "^2.3"
|
|
16
|
+
|
|
17
|
+
[tool.poetry.extras]
|
|
18
|
+
pandas = ["pandas"]
|
|
19
|
+
pandas_xlsx = ["pandas", "xlsxwriter"]
|
|
20
|
+
pandas_parquet = ["pandas", "pyarrow"]
|
|
21
|
+
full = ["numpy", "pyproj", "gdal", "cfgrib", "dynaconf", "pandas", "netcdf4", "h5netcdf", "pyarrow", "geopandas", "fiona", "rasterio", "matplotlib", "openpyxl", "xlsxwriter", "pyexcelerate"]
|
|
22
|
+
|
|
23
|
+
[tool.poetry-git-version-plugin]
|
|
24
|
+
make_alpha_version = true
|
|
25
|
+
|
|
26
|
+
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
[default]
|
|
3
|
+
graph_url=https://graph.microsoft.com/
|
|
4
|
+
sharepoint_host=yourhost.sharepoint.com
|
|
5
|
+
user_account=some.user@mail.abc
|
|
6
|
+
|
|
7
|
+
[msal]
|
|
8
|
+
client_id=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
9
|
+
authority=https://login.microsoftonline.com/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
10
|
+
auth_method=device
|
|
11
|
+
scopes=["Files.ReadWrite", "User.ReadWrite"]
|