-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminio_storage.py
More file actions
42 lines (32 loc) · 1.29 KB
/
minio_storage.py
File metadata and controls
42 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Built-in Minio storage example for the current 2.x line."""
from minio import Minio
from pydantic import BaseModel
from excelalchemy import ExcelAlchemy, FieldMeta, ImporterConfig, Number, String
from excelalchemy.core.storage import build_storage_gateway
from excelalchemy.core.storage_minio import MinioStorageGateway
class EmployeeImporter(BaseModel):
full_name: String = FieldMeta(label='Full name', order=1)
age: Number = FieldMeta(label='Age', order=2)
def main() -> None:
minio_client = Minio(
'localhost:9000',
access_key='minioadmin',
secret_key='minioadmin',
secure=False,
)
config = ImporterConfig.for_create(
EmployeeImporter,
creator=lambda row, context: row,
minio=minio_client,
bucket_name='excel-files',
locale='en',
)
gateway = build_storage_gateway(config)
alchemy = ExcelAlchemy(config)
template = alchemy.download_template_artifact(filename='employee-template.xlsx')
print(f'Built gateway: {type(gateway).__name__}')
print(f'Uses built-in Minio path: {config.storage_options.uses_legacy_minio_path}')
print(f'Template bytes: {len(template.as_bytes())}')
print(f'Gateway type check: {isinstance(gateway, MinioStorageGateway)}')
if __name__ == '__main__':
main()