@@ -333,18 +333,21 @@ Then from Windmill, just [fill the S3 resource type](../../integrations/s3.md).
333
333
<TabItem value = " deno" label = " TypeScript (Deno)" attributes = { {className: " text-xs p-4 !mt-0 !ml-0" }} >
334
334
335
335
``` ts
336
- import * as wmill from ' npm:windmill-client@1' ;
336
+ import type { S3Object } from ' npm:windmill-client@^1.229.0' ;
337
+ import * as wmill from ' npm:windmill-client@^1.229.0' ;
337
338
import { S3Client } from ' https://deno.land/x/s3_lite_client@0.2.0/mod.ts' ;
338
339
339
- type s3object = object ;
340
+ export async function main(inputFile : S3Object ) {
341
+ // this will default to the workspace s3 resource
342
+ let args = await wmill .denoS3LightClientSettings ();
343
+ // this will use the designated resource
344
+ // let args = await wmill.denoS3LightClientSettings("<PATH_TO_S3_RESOURCE>");
345
+ const s3Client = new S3Client (args );
340
346
341
- export async function main(inputFile : s3object ) {
342
- const s3Resource = await wmill .getResource (' <PATH_TO_S3_RESOURCE>' );
343
- const s3Client = new S3Client (s3Resource );
344
347
const outputFile = ' output/hello.txt' ;
345
348
346
349
// read object from S3
347
- const getObjectResponse = await s3Client .getObject (inputFile [ ' s3 ' ] );
350
+ const getObjectResponse = await s3Client .getObject (inputFile . s3 );
348
351
const inputObjContent = await getObjectResponse .text ();
349
352
console .log (inputObjContent );
350
353
@@ -356,31 +359,35 @@ export async function main(inputFile: s3object) {
356
359
console .log (obj .key );
357
360
}
358
361
359
- return {
362
+ const result : S3Object = {
360
363
s3: outputFile
361
364
};
365
+ return result ;
362
366
}
363
367
```
364
368
365
369
</TabItem >
366
370
<TabItem value = " python" label = " Python" attributes = { {className: " text-xs p-4 !mt-0 !ml-0" }} >
367
371
368
372
``` python
373
+ # requirements:
374
+ # boto3==1.34.4
375
+ # wmill>=1.229.0
376
+
369
377
import wmill
378
+ from wmill import S3Object
370
379
import boto3
371
380
372
- s3object = dict
373
381
382
+ def main (input_file : S3Object):
383
+ bucket = wmill.get_resource(" <PATH_TO_S3_RESOURCE>" )[" bucket" ]
384
+
385
+ # this will default to the workspace s3 resource
386
+ args = wmill.boto3_connection_settings()
387
+ # this will use the designated resource
388
+ # args = wmill.boto3_connection_settings("<PATH_TO_S3_RESOURCE>")
389
+ s3client = boto3.client(" s3" , ** args)
374
390
375
- def main (input_file : s3object):
376
- s3_resource = wmill.get_resource(" <PATH_TO_S3_RESOURCE>" )
377
- bucket = s3_resource[" bucket" ]
378
- s3client = boto3.client(
379
- " s3" ,
380
- region_name = s3_resource[" region" ],
381
- aws_access_key_id = s3_resource[" accessKey" ],
382
- aws_secret_access_key = s3_resource[" secretKey" ],
383
- )
384
391
output_file = " output/hello.txt"
385
392
386
393
# read object from S3 and print its content
@@ -406,10 +413,9 @@ def main(input_file: s3object):
406
413
# see https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-examples.html
407
414
# and https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html
408
415
# for more code examples (listing object, deleting files, etc)
409
-
410
416
return [
411
- s3object({ " s3 " : output_file} ),
412
- s3object({ " s3 " : uploaded_file} ),
417
+ S3Object( s3 = output_file),
418
+ S3Object( s3 = uploaded_file),
413
419
]
414
420
```
415
421
@@ -426,22 +432,26 @@ You can link a Windmill workspace to an S3 bucket and use it as source and/or ta
426
432
<TabItem value = " polars" label = " Polars" attributes = { {className: " text-xs p-4 !mt-0 !ml-0" }} >
427
433
428
434
``` python
435
+ # requirements:
436
+ # polars==0.19.19
437
+ # s3fs==2023.12.0
438
+ # wmill>=1.229.0
439
+
429
440
import wmill
441
+ from wmill import S3Object
430
442
import polars as pl
431
443
import s3fs
432
444
433
- s3object = dict
434
445
446
+ def main (input_file : S3Object):
447
+ bucket = wmill.get_resource(" u/admin/windmill-cloud-demo" )[" bucket" ]
435
448
436
- def main (input_file : s3object):
437
- s3 = s3fs.S3FileSystem(
438
- # this will default to the workspace s3 resource
439
- ** wmill.polars_connection_settings()[" s3fs_args" ]
440
- # this will use the designated resource
441
- # **wmill.polars_connection_settings("<PATH_TO_S3_RESOURCE>")["s3fs_args"]
442
- )
449
+ # this will default to the workspace s3 resource
450
+ args = wmill.polars_connection_settings().s3fs_args
451
+ # this will use the designated resource
452
+ # args = wmill.polars_connection_settings("<PATH_TO_S3_RESOURCE>").s3fs_args
453
+ s3 = s3fs.S3FileSystem(** args)
443
454
444
- bucket = " <S3_BUCKET_NAME>"
445
455
input_uri = " s3://{} /{} " .format(bucket, input_file[" s3" ])
446
456
output_file = " output/result.parquet"
447
457
output_uri = " s3://{} /{} " .format(bucket, output_file)
@@ -463,29 +473,38 @@ def main(input_file: s3object):
463
473
464
474
# persist the output dataframe back to S3 and return it
465
475
output_df.write_parquet(output_s3)
466
- return s3object({" s3" : output_file})
476
+
477
+ return S3Object(s3 = output_file)
467
478
```
468
479
469
480
</TabItem >
470
481
<TabItem value = " duckdb" label = " DuckDB" attributes = { {className: " text-xs p-4 !mt-0 !ml-0" }} >
471
482
472
483
``` python
484
+ # requirements:
485
+ # wmill>=1.229.0
486
+ # duckdb==0.9.1
487
+
473
488
import wmill
489
+ from wmill import S3Object
474
490
import duckdb
475
491
476
- s3object = dict
477
492
493
+ def main (input_file : S3Object):
494
+ bucket = wmill.get_resource(" u/admin/windmill-cloud-demo" )[" bucket" ]
478
495
479
- def main (input_file : s3object):
480
496
# create a DuckDB database in memory
481
497
# see https://duckdb.org/docs/api/python/dbapi
482
498
conn = duckdb.connect()
483
- # connect duck db to the S3 bucket - this will default to the workspace s3 resource
484
- conn.execute(wmill.duckdb_connection_settings()[" connection_settings_str" ])
499
+
500
+ # this will default to the workspace s3 resource
501
+ args = wmill.duckdb_connection_settings().connection_settings_str
485
502
# this will use the designated resource
486
- # conn.execute(wmill.duckdb_connection_settings("<PATH_TO_S3_RESOURCE>")["connection_settings_str"])
503
+ # args = wmill.duckdb_connection_settings("<PATH_TO_S3_RESOURCE>").connection_settings_str
504
+
505
+ # connect duck db to the S3 bucket - this will default to the workspace s3 resource
506
+ conn.execute(args)
487
507
488
- bucket = " <S3_BUCKET_NAME>"
489
508
input_uri = " s3://{} /{} " .format(bucket, input_file[" s3" ])
490
509
output_file = " output/result.parquet"
491
510
output_uri = " s3://{} /{} " .format(bucket, output_file)
@@ -512,7 +531,7 @@ def main(input_file: s3object):
512
531
)
513
532
514
533
conn.close()
515
- return s3object({ " s3 " : output_file} )
534
+ return S3Object( s3 = output_file)
516
535
```
517
536
518
537
</TabItem >
0 commit comments