datablob 0.8.0__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.
datablob/__init__.py
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import boto3
|
|
2
|
+
import csv
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
import geopandas as gpd
|
|
5
|
+
import io
|
|
6
|
+
from json import dumps as json_dumps
|
|
7
|
+
from json import loads as json_loads
|
|
8
|
+
from openpyxl import Workbook
|
|
9
|
+
import os
|
|
10
|
+
import pandas as pd
|
|
11
|
+
import tempfile
|
|
12
|
+
import tzdata
|
|
13
|
+
import zipfile
|
|
14
|
+
from zoneinfo import ZoneInfo
|
|
15
|
+
|
|
16
|
+
POSSIBLE_LATITUDE_KEYS = [
|
|
17
|
+
"LATITUDE",
|
|
18
|
+
"Latitude",
|
|
19
|
+
"latitude",
|
|
20
|
+
"LAT",
|
|
21
|
+
"Lat",
|
|
22
|
+
"lat",
|
|
23
|
+
"@lat",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
POSSIBLE_LONGITUDE_KEYS = [
|
|
27
|
+
"LONGITUDE",
|
|
28
|
+
"Longitude",
|
|
29
|
+
"longitude",
|
|
30
|
+
"LONG",
|
|
31
|
+
"Long",
|
|
32
|
+
"long",
|
|
33
|
+
"LON",
|
|
34
|
+
"Lon",
|
|
35
|
+
"lon",
|
|
36
|
+
"@lon",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class DataBlobClient:
|
|
41
|
+
def __init__(self, bucket_name, bucket_path, timezones=None):
|
|
42
|
+
self.bucket_name = bucket_name
|
|
43
|
+
self.bucket_path = bucket_path.rstrip("/")
|
|
44
|
+
self.timezones = timezones or ["UTC"]
|
|
45
|
+
|
|
46
|
+
def _get_unique_keys(self, rows):
|
|
47
|
+
columns = set()
|
|
48
|
+
for row in rows:
|
|
49
|
+
columns.update(row.keys())
|
|
50
|
+
return list(sorted(list(columns)))
|
|
51
|
+
|
|
52
|
+
def get_filenames_by_dataset_and_version(self):
|
|
53
|
+
results = {}
|
|
54
|
+
response = boto3.client("s3").list_objects_v2(
|
|
55
|
+
Bucket=self.bucket_name, Prefix=self.bucket_path
|
|
56
|
+
)
|
|
57
|
+
if "Contents" in response:
|
|
58
|
+
for obj in response["Contents"]:
|
|
59
|
+
key = obj["Key"][len(self.bucket_path) + 1 :]
|
|
60
|
+
|
|
61
|
+
if len(key.split("/")) == 3:
|
|
62
|
+
[dataset_id, version, filename] = key.split("/")
|
|
63
|
+
if version.startswith("v"):
|
|
64
|
+
version = version[1:]
|
|
65
|
+
if filename:
|
|
66
|
+
if dataset_id not in results:
|
|
67
|
+
results[dataset_id] = {}
|
|
68
|
+
if version not in results[dataset_id]:
|
|
69
|
+
results[dataset_id][version] = []
|
|
70
|
+
results[dataset_id][version].append(filename)
|
|
71
|
+
|
|
72
|
+
for dataset_id, subdict in results.items():
|
|
73
|
+
versions = list(subdict.keys())
|
|
74
|
+
for version in versions:
|
|
75
|
+
files = subdict[version]
|
|
76
|
+
if "meta.json" in files:
|
|
77
|
+
subdict[version] = sorted(subdict[version])
|
|
78
|
+
else:
|
|
79
|
+
del subdict[version]
|
|
80
|
+
return results
|
|
81
|
+
|
|
82
|
+
def upload_csv(self, dataset_name, dataset_version, data):
|
|
83
|
+
key = (
|
|
84
|
+
self.bucket_path + "/" + dataset_name + "/v" + dataset_version + "/data.csv"
|
|
85
|
+
)
|
|
86
|
+
boto3.client("s3").put_object(
|
|
87
|
+
Bucket=self.bucket_name,
|
|
88
|
+
Key=key,
|
|
89
|
+
Body=data,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def upload_tsv(self, dataset_name, dataset_version, data):
|
|
93
|
+
key = (
|
|
94
|
+
self.bucket_path + "/" + dataset_name + "/v" + dataset_version + "/data.tsv"
|
|
95
|
+
)
|
|
96
|
+
boto3.client("s3").put_object(
|
|
97
|
+
Bucket=self.bucket_name,
|
|
98
|
+
Key=key,
|
|
99
|
+
Body=data,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
def get_dataset_as_csv(self, name, version, remove_bom=True):
|
|
103
|
+
key = self.bucket_path + "/" + name + "/v" + version + "/data.csv"
|
|
104
|
+
response = boto3.client("s3").get_object(Bucket=self.bucket_name, Key=key)
|
|
105
|
+
object_content = response["Body"].read().decode("utf-8")
|
|
106
|
+
if remove_bom:
|
|
107
|
+
object_content = object_content.lstrip("\ufeff")
|
|
108
|
+
return object_content
|
|
109
|
+
|
|
110
|
+
def get_dataset_as_tsv(self, name, version, remove_bom=True):
|
|
111
|
+
key = self.bucket_path + "/" + name + "/v" + version + "/data.tsv"
|
|
112
|
+
response = boto3.client("s3").get_object(Bucket=self.bucket_name, Key=key)
|
|
113
|
+
object_content = response["Body"].read().decode("utf-8")
|
|
114
|
+
if remove_bom:
|
|
115
|
+
object_content = object_content.lstrip("\ufeff")
|
|
116
|
+
return object_content
|
|
117
|
+
|
|
118
|
+
def get_dataset_as_json(self, name, version):
|
|
119
|
+
key = self.bucket_path + "/" + name + "/v" + version + "/data.json"
|
|
120
|
+
response = boto3.client("s3").get_object(Bucket=self.bucket_name, Key=key)
|
|
121
|
+
object_content = response["Body"].read().decode("utf-8")
|
|
122
|
+
return json_loads(object_content)
|
|
123
|
+
|
|
124
|
+
def get_dataset_metadata(self, name: str, version: str):
|
|
125
|
+
key = self.bucket_path + "/" + name + "/v" + version + "/meta.json"
|
|
126
|
+
response = boto3.client("s3").get_object(Bucket=self.bucket_name, Key=key)
|
|
127
|
+
object_content = response["Body"].read().decode("utf-8")
|
|
128
|
+
return json_loads(object_content)
|
|
129
|
+
|
|
130
|
+
def upload_geojson_points(self, dataset_name, dataset_version, data):
|
|
131
|
+
key = (
|
|
132
|
+
self.bucket_path
|
|
133
|
+
+ "/"
|
|
134
|
+
+ dataset_name
|
|
135
|
+
+ "/v"
|
|
136
|
+
+ dataset_version
|
|
137
|
+
+ "/data.points.geojson"
|
|
138
|
+
)
|
|
139
|
+
boto3.client("s3").put_object(
|
|
140
|
+
Bucket=self.bucket_name,
|
|
141
|
+
Key=key,
|
|
142
|
+
Body=data if isinstance(data, str) else json_dumps(data),
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
def upload_shapefile_points(self, dataset_name, dataset_version, blob):
|
|
146
|
+
key = (
|
|
147
|
+
self.bucket_path
|
|
148
|
+
+ "/"
|
|
149
|
+
+ dataset_name
|
|
150
|
+
+ "/v"
|
|
151
|
+
+ dataset_version
|
|
152
|
+
+ "/data.points.shp.zip"
|
|
153
|
+
)
|
|
154
|
+
boto3.client("s3").put_object(
|
|
155
|
+
Bucket=self.bucket_name,
|
|
156
|
+
Key=key,
|
|
157
|
+
Body=blob,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def upload_jsonl(self, dataset_name, dataset_version, data):
|
|
161
|
+
key = (
|
|
162
|
+
self.bucket_path
|
|
163
|
+
+ "/"
|
|
164
|
+
+ dataset_name
|
|
165
|
+
+ "/v"
|
|
166
|
+
+ dataset_version
|
|
167
|
+
+ "/data.jsonl"
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
results = ""
|
|
171
|
+
for row in data:
|
|
172
|
+
results += json_dumps(row) + "\n"
|
|
173
|
+
|
|
174
|
+
boto3.client("s3").put_object(
|
|
175
|
+
Bucket=self.bucket_name,
|
|
176
|
+
Key=key,
|
|
177
|
+
Body=results,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
def upload_json(self, dataset_name, dataset_version, data):
|
|
181
|
+
key = (
|
|
182
|
+
self.bucket_path
|
|
183
|
+
+ "/"
|
|
184
|
+
+ dataset_name
|
|
185
|
+
+ "/v"
|
|
186
|
+
+ dataset_version
|
|
187
|
+
+ "/data.json"
|
|
188
|
+
)
|
|
189
|
+
boto3.client("s3").put_object(
|
|
190
|
+
Bucket=self.bucket_name,
|
|
191
|
+
Key=key,
|
|
192
|
+
Body=data if isinstance(data, str) else json_dumps(data),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
def upload_parquet(self, dataset_name, dataset_version, data):
|
|
196
|
+
key = (
|
|
197
|
+
self.bucket_path
|
|
198
|
+
+ "/"
|
|
199
|
+
+ dataset_name
|
|
200
|
+
+ "/v"
|
|
201
|
+
+ dataset_version
|
|
202
|
+
+ "/data.parquet"
|
|
203
|
+
)
|
|
204
|
+
boto3.client("s3").put_object(
|
|
205
|
+
Bucket=self.bucket_name,
|
|
206
|
+
Key=key,
|
|
207
|
+
Body=data,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
def upload_xlsx(self, dataset_name, dataset_version, data):
|
|
211
|
+
key = (
|
|
212
|
+
self.bucket_path
|
|
213
|
+
+ "/"
|
|
214
|
+
+ dataset_name
|
|
215
|
+
+ "/v"
|
|
216
|
+
+ dataset_version
|
|
217
|
+
+ "/data.xlsx"
|
|
218
|
+
)
|
|
219
|
+
boto3.client("s3").put_object(
|
|
220
|
+
Bucket=self.bucket_name,
|
|
221
|
+
Key=key,
|
|
222
|
+
Body=data,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
def upload_metadata(self, dataset_name, dataset_version, data):
|
|
226
|
+
key = (
|
|
227
|
+
self.bucket_path
|
|
228
|
+
+ "/"
|
|
229
|
+
+ dataset_name
|
|
230
|
+
+ "/v"
|
|
231
|
+
+ dataset_version
|
|
232
|
+
+ "/meta.json"
|
|
233
|
+
)
|
|
234
|
+
boto3.client("s3").put_object(
|
|
235
|
+
Bucket=self.bucket_name,
|
|
236
|
+
Key=key,
|
|
237
|
+
Body=data if isinstance(data, str) else json_dumps(data),
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
def convert_gdf_to_shapefile(self, gdf):
|
|
241
|
+
buf = io.BytesIO()
|
|
242
|
+
|
|
243
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
244
|
+
path = os.path.join(tmpdir, f"data.shp")
|
|
245
|
+
gdf.to_file(path, driver="ESRI Shapefile")
|
|
246
|
+
|
|
247
|
+
# copy temp files into in-memory zip file
|
|
248
|
+
with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
249
|
+
for filename in os.listdir(tmpdir):
|
|
250
|
+
zf.write(os.path.join(tmpdir, filename), filename)
|
|
251
|
+
|
|
252
|
+
buf.seek(0)
|
|
253
|
+
return buf.getvalue()
|
|
254
|
+
|
|
255
|
+
def _convert_row_to_xlsx_data_types(self, row, xlsx_data_types):
|
|
256
|
+
result = []
|
|
257
|
+
for icol, value in enumerate(row):
|
|
258
|
+
data_type = xlsx_data_types[icol]
|
|
259
|
+
if value is None:
|
|
260
|
+
value = ""
|
|
261
|
+
elif data_type == "Number":
|
|
262
|
+
if value != "":
|
|
263
|
+
value = float(value)
|
|
264
|
+
elif data_type == "Text":
|
|
265
|
+
value = str(value)
|
|
266
|
+
else:
|
|
267
|
+
print("[datablob] warning: unsupported xlsx data type " + data_type)
|
|
268
|
+
value = str(value)
|
|
269
|
+
result.append(value)
|
|
270
|
+
return result
|
|
271
|
+
|
|
272
|
+
def convert_to_xlsx(self, meta, data, columns, xlsx_data_types=None):
|
|
273
|
+
wb = Workbook()
|
|
274
|
+
ws_overview = wb.active
|
|
275
|
+
ws_overview.title = "Overview"
|
|
276
|
+
ws_overview.append(["name", meta["name"]])
|
|
277
|
+
for tz, value in meta["lastUpdated"].items():
|
|
278
|
+
ws_overview.append(["last updated (in " + tz + ")", value])
|
|
279
|
+
ws_overview.append(["description", meta["description"]])
|
|
280
|
+
ws_overview.append(["number of columns", meta["numColumns"]])
|
|
281
|
+
ws_overview.append(["number of rows", meta["numRows"]])
|
|
282
|
+
ws_overview.append(["column names", ", ".join(meta["columns"])])
|
|
283
|
+
if "xlsx_data_types" in meta:
|
|
284
|
+
ws_overview.append(["xlsx data types", ", ".join(meta["xlsx_data_types"])])
|
|
285
|
+
|
|
286
|
+
# Iterate through all cells in the first column (Column A)
|
|
287
|
+
max_length = 0
|
|
288
|
+
for cell in ws_overview["A"]:
|
|
289
|
+
if cell.value:
|
|
290
|
+
if len(str(cell.value)) > max_length:
|
|
291
|
+
max_length = len(str(cell.value))
|
|
292
|
+
ws_overview.column_dimensions["A"].width = max_length + 2
|
|
293
|
+
|
|
294
|
+
ws_data = wb.create_sheet(title="Data")
|
|
295
|
+
ws_data.append(columns)
|
|
296
|
+
for row in data:
|
|
297
|
+
row = [str(row.get(col, "")) for col in columns]
|
|
298
|
+
if xlsx_data_types:
|
|
299
|
+
row = self._convert_row_to_xlsx_data_types(row, xlsx_data_types)
|
|
300
|
+
ws_data.append(row)
|
|
301
|
+
xlsx_buffer = io.BytesIO()
|
|
302
|
+
wb.save(xlsx_buffer)
|
|
303
|
+
xlsx_buffer.seek(0)
|
|
304
|
+
return xlsx_buffer
|
|
305
|
+
|
|
306
|
+
def convert_rows_to_csv(self, rows, fieldnames=None):
|
|
307
|
+
f = io.StringIO(newline="")
|
|
308
|
+
if fieldnames is None:
|
|
309
|
+
fieldnames = sorted(list(rows[0].keys()))
|
|
310
|
+
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
|
311
|
+
writer.writeheader()
|
|
312
|
+
writer.writerows(rows)
|
|
313
|
+
f.seek(0)
|
|
314
|
+
# read and make sure we don't have a BOM
|
|
315
|
+
return f.read().lstrip("\ufeff")
|
|
316
|
+
|
|
317
|
+
def convert_rows_to_tsv(self, rows, fieldnames=None):
|
|
318
|
+
f = io.StringIO(newline="")
|
|
319
|
+
if fieldnames is None:
|
|
320
|
+
fieldnames = sorted(list(rows[0].keys()))
|
|
321
|
+
writer = csv.DictWriter(f, fieldnames=fieldnames, delimiter="\t")
|
|
322
|
+
writer.writeheader()
|
|
323
|
+
writer.writerows(rows)
|
|
324
|
+
f.seek(0)
|
|
325
|
+
# read and make sure we don't have a BOM
|
|
326
|
+
return f.read().lstrip("\ufeff")
|
|
327
|
+
|
|
328
|
+
def infer_latitude(self, rows):
|
|
329
|
+
keys = POSSIBLE_LATITUDE_KEYS
|
|
330
|
+
for row in rows:
|
|
331
|
+
keys = [key for key in keys if key in row]
|
|
332
|
+
return keys[0] if len(keys) > 1 else None
|
|
333
|
+
|
|
334
|
+
def infer_longitude(self, rows):
|
|
335
|
+
keys = POSSIBLE_LONGITUDE_KEYS
|
|
336
|
+
for row in rows:
|
|
337
|
+
keys = [key for key in keys if key in row]
|
|
338
|
+
return keys[0] if len(keys) > 1 else None
|
|
339
|
+
|
|
340
|
+
def convert_rows_to_geojson_points(self, rows, longitude_key, latitude_key):
|
|
341
|
+
features = []
|
|
342
|
+
for row in rows:
|
|
343
|
+
features.append(
|
|
344
|
+
{
|
|
345
|
+
"type": "Feature",
|
|
346
|
+
"properties": row,
|
|
347
|
+
"geometry": {
|
|
348
|
+
"type": "Point",
|
|
349
|
+
"coordinates": [row[longitude_key], row[latitude_key]],
|
|
350
|
+
},
|
|
351
|
+
}
|
|
352
|
+
)
|
|
353
|
+
return {"type": "FeatureCollection", "features": features}
|
|
354
|
+
|
|
355
|
+
def update_dataset(
|
|
356
|
+
self,
|
|
357
|
+
name,
|
|
358
|
+
version,
|
|
359
|
+
data,
|
|
360
|
+
column_names=None,
|
|
361
|
+
description=None,
|
|
362
|
+
latitude_key=None,
|
|
363
|
+
longitude_key=None,
|
|
364
|
+
json=True,
|
|
365
|
+
jsonl=True,
|
|
366
|
+
geojson=True,
|
|
367
|
+
parquet=True,
|
|
368
|
+
xlsx=False,
|
|
369
|
+
xlsx_data_types=None,
|
|
370
|
+
):
|
|
371
|
+
lastUpdated = dict(
|
|
372
|
+
[(tz, datetime.now(ZoneInfo(tz)).isoformat()) for tz in self.timezones]
|
|
373
|
+
)
|
|
374
|
+
columns = column_names if column_names else self._get_unique_keys(data)
|
|
375
|
+
meta = {
|
|
376
|
+
"name": name,
|
|
377
|
+
"lastUpdated": lastUpdated,
|
|
378
|
+
"description": description or "",
|
|
379
|
+
"numColumns": len(columns),
|
|
380
|
+
"numRows": len(data),
|
|
381
|
+
"columns": columns,
|
|
382
|
+
"files": [],
|
|
383
|
+
}
|
|
384
|
+
data_as_csv = self.convert_rows_to_csv(data, fieldnames=columns)
|
|
385
|
+
data_as_tsv = self.convert_rows_to_tsv(data, fieldnames=columns)
|
|
386
|
+
|
|
387
|
+
df = pd.DataFrame(data)
|
|
388
|
+
|
|
389
|
+
if latitude_key and longitude_key:
|
|
390
|
+
if geojson:
|
|
391
|
+
data_as_geojson_points = self.convert_rows_to_geojson_points(
|
|
392
|
+
data, longitude_key=longitude_key, latitude_key=latitude_key
|
|
393
|
+
)
|
|
394
|
+
else:
|
|
395
|
+
data_as_geojson_points = None
|
|
396
|
+
|
|
397
|
+
if parquet:
|
|
398
|
+
gdf = gpd.GeoDataFrame(
|
|
399
|
+
df,
|
|
400
|
+
geometry=gpd.points_from_xy(df[longitude_key], df[latitude_key]),
|
|
401
|
+
crs="EPSG:4326",
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
buffer = io.BytesIO()
|
|
405
|
+
gdf.to_parquet(buffer, engine="pyarrow")
|
|
406
|
+
data_as_parquet_blob = buffer.getvalue()
|
|
407
|
+
else:
|
|
408
|
+
data_as_parquet_blob = None
|
|
409
|
+
|
|
410
|
+
shapefile_blob = self.convert_gdf_to_shapefile(gdf)
|
|
411
|
+
else:
|
|
412
|
+
if parquet:
|
|
413
|
+
buffer = io.BytesIO()
|
|
414
|
+
df.to_parquet(buffer, engine="pyarrow")
|
|
415
|
+
data_as_parquet_blob = buffer.getvalue()
|
|
416
|
+
else:
|
|
417
|
+
data_as_parquet_blob = None
|
|
418
|
+
|
|
419
|
+
data_as_geojson_points = None
|
|
420
|
+
shapefile_blob = None
|
|
421
|
+
|
|
422
|
+
if xlsx:
|
|
423
|
+
if xlsx_data_types:
|
|
424
|
+
meta["xlsx_data_types"] = xlsx_data_types
|
|
425
|
+
data_as_xlsx = self.convert_to_xlsx(meta, data, columns, xlsx_data_types)
|
|
426
|
+
self.upload_xlsx(name, version, data_as_xlsx)
|
|
427
|
+
meta["files"].append({"filename": "data.xlsx", "format": "Excel"})
|
|
428
|
+
|
|
429
|
+
self.upload_csv(name, version, data_as_csv)
|
|
430
|
+
meta["files"].append({"filename": "data.csv", "format": "CSV"})
|
|
431
|
+
|
|
432
|
+
self.upload_tsv(name, version, data_as_tsv)
|
|
433
|
+
meta["files"].append({"filename": "data.tsv", "format": "TSV"})
|
|
434
|
+
|
|
435
|
+
if json:
|
|
436
|
+
self.upload_json(name, version, data)
|
|
437
|
+
meta["files"].append({"filename": "data.json", "format": "JSON"})
|
|
438
|
+
|
|
439
|
+
if jsonl:
|
|
440
|
+
self.upload_jsonl(name, version, data)
|
|
441
|
+
meta["files"].append({"filename": "data.jsonl", "format": "JSON Lines"})
|
|
442
|
+
|
|
443
|
+
if geojson and data_as_geojson_points:
|
|
444
|
+
self.upload_geojson_points(name, version, data_as_geojson_points)
|
|
445
|
+
meta["files"].append(
|
|
446
|
+
{"filename": "data.points.geojson", "format": "GeoJSON (Points)"}
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
if shapefile_blob:
|
|
450
|
+
self.upload_shapefile_points(name, version, shapefile_blob)
|
|
451
|
+
meta["files"].append(
|
|
452
|
+
{"filename": "data.points.shp.zip", "format": "Shapefile (Points)"}
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
if parquet and data_as_parquet_blob:
|
|
456
|
+
self.upload_parquet(name, version, data_as_parquet_blob)
|
|
457
|
+
meta["files"].append({"filename": "data.parquet", "format": "Parquet"})
|
|
458
|
+
|
|
459
|
+
self.upload_metadata(name, version, meta)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datablob
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: Client for Updating a Simple Data Warehouse on Blob Storage
|
|
5
|
+
Home-page: https://github.com/gocarta/datablob
|
|
6
|
+
Download-URL: https://github.com/gocarta/datablob/tarball/download
|
|
7
|
+
Author: Daniel J. Dufour
|
|
8
|
+
Author-email: daniel.j.dufour@gmail.com
|
|
9
|
+
Keywords: data,python
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: boto3
|
|
17
|
+
Requires-Dist: geopandas
|
|
18
|
+
Requires-Dist: openpyxl
|
|
19
|
+
Requires-Dist: pandas
|
|
20
|
+
Requires-Dist: pyarrow
|
|
21
|
+
Requires-Dist: shapely
|
|
22
|
+
Requires-Dist: tzdata
|
|
23
|
+
Dynamic: author
|
|
24
|
+
Dynamic: author-email
|
|
25
|
+
Dynamic: classifier
|
|
26
|
+
Dynamic: description
|
|
27
|
+
Dynamic: description-content-type
|
|
28
|
+
Dynamic: download-url
|
|
29
|
+
Dynamic: home-page
|
|
30
|
+
Dynamic: keywords
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
Dynamic: requires-dist
|
|
33
|
+
Dynamic: summary
|
|
34
|
+
|
|
35
|
+
# datablob
|
|
36
|
+
Client for Updating a Simple Data Warehouse on Blob Storage
|
|
37
|
+
|
|
38
|
+
## design philosophy
|
|
39
|
+
- optimize for simplicity and user friendliness
|
|
40
|
+
- storage is cheap (compared to compute)
|
|
41
|
+
- pre-compute as much as possible
|
|
42
|
+
- should work out of the box
|
|
43
|
+
- advanced configuration should be opt-in
|
|
44
|
+
- explicit is better than implicit
|
|
45
|
+
- straightforwardness over magic
|
|
46
|
+
|
|
47
|
+
## install
|
|
48
|
+
```sh
|
|
49
|
+
pip install datablob
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## supported formats
|
|
53
|
+
- csv
|
|
54
|
+
- [geojson (points only)](https://geojson.org/)
|
|
55
|
+
- json
|
|
56
|
+
- [json lines](https://jsonlines.org/)
|
|
57
|
+
- [parquet](https://parquet.apache.org/), including [geoparquet](https://geoparquet.org/)
|
|
58
|
+
- [shapefile (points only)](https://en.wikipedia.org/wiki/Shapefile)
|
|
59
|
+
- tsv
|
|
60
|
+
- xlsx (Microsoft Excel)
|
|
61
|
+
|
|
62
|
+
## basic usage
|
|
63
|
+
```py
|
|
64
|
+
from datablob import DataBlobClient
|
|
65
|
+
|
|
66
|
+
client = DataBlobClient(
|
|
67
|
+
bucket_name="example-test-bucket-123", bucket_path="prefix/to/dataportal"
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
client.update_dataset(name="fleet", version="2", data=rows, xlsx=True)
|
|
71
|
+
# automatically creates the following files
|
|
72
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/meta.json
|
|
73
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.csv
|
|
74
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.points.geojson
|
|
75
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.json
|
|
76
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.jsonl
|
|
77
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.parquet
|
|
78
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.points.shp.zip
|
|
79
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.tsv
|
|
80
|
+
# s3://example-test-bucket-123/prefix/to/dataportal/fleet/v2/data.xlsx
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## advanced usage
|
|
84
|
+
```py
|
|
85
|
+
client.update_dataset(
|
|
86
|
+
name="fleet",
|
|
87
|
+
version="1",
|
|
88
|
+
data=rows,
|
|
89
|
+
column_names=["ID", "Make", "Model", "Year"]
|
|
90
|
+
description="List of Vehicles in Fleet",
|
|
91
|
+
xlsx=True,
|
|
92
|
+
xlsx_data_types=["Number", "Text", "Text", "Number"]
|
|
93
|
+
)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## examples
|
|
97
|
+
- [Clever Vehicle Locations](https://github.com/gocarta/dataops-clever-vehicle-locations)
|
|
98
|
+
- [Simple Bus Routes](https://github.com/gocarta/dataops-simple-bus-routes)
|
|
99
|
+
- [Simple Bus Stops](https://github.com/gocarta/dataops-simple-bus-stops)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
datablob/__init__.py,sha256=1tTI4098zU3BGn7Nh5ssgqnr_aIHiuU_-exGIXWeC3c,15853
|
|
2
|
+
datablob-0.8.0.dist-info/licenses/LICENSE,sha256=9Ofzc7m5lpUDN-jUGkopOcLZC3cl6brz1QhKInF60yg,7169
|
|
3
|
+
datablob-0.8.0.dist-info/METADATA,sha256=EMehVuRiyLLpjYohrJFCJKqjsIV0XXsykc-dEyiW8nQ,3270
|
|
4
|
+
datablob-0.8.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
datablob-0.8.0.dist-info/top_level.txt,sha256=trYKBOas9qK0gyjeAqOB4i8C0UNYvELioROXl7NfdWU,9
|
|
6
|
+
datablob-0.8.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Creative Commons Legal Code
|
|
2
|
+
|
|
3
|
+
CC0 1.0 Universal
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
datablob
|