22import os
33from typing import Any , List , Optional , Tuple , Union
44
5- import boto3
65from botocore .client import BaseClient
6+ from botocore .config import Config
77from botocore .exceptions import ClientError
88
9+ from whylogs .api ._s3_client import build_s3_client
910from whylogs .api .writer import Writer
1011from whylogs .api .writer .writer import _Writable
1112from whylogs .core .utils import deprecated_alias
@@ -20,11 +21,16 @@ class S3Writer(Writer):
2021 >**IMPORTANT**: In order to correctly connect to your Amazon S3 bucket, make sure you have
2122 the following environment variables set: `[AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY]`
2223
24+ The same writer targets any S3-compatible object store by passing an ``endpoint_url``
25+ (and matching credentials). To reuse a fully configured client instead, pass it as
26+ ``s3_client`` and it is used as provided.
27+
2328 Parameters
2429 ----------
2530 s3_client: BaseClient, optional
2631 The s3 client used to authenticate and perform operations on the s3 bucket.
27- Should be a BaseClient from the boto3 library
32+ Should be a BaseClient from the boto3 library. When omitted, a client is built
33+ internally.
2834 base_prefix: str, optional
2935 The base file prefix for s3, in order to organize. A placeholder 'profile' will take place if None is provided.
3036 bucket_name: str, optional
@@ -33,6 +39,11 @@ class S3Writer(Writer):
3339 object_name: str, optional
3440 The s3's object name. It basically states the location where the file goes to.
3541 Also made optional, so it can be defined through the `option` method
42+ endpoint_url: str, optional
43+ Endpoint URL of an S3-compatible object store. Leave unset for AWS S3.
44+ Only applies to the internally built client.
45+ config: botocore.config.Config, optional
46+ Extra botocore configuration merged into the internally built client.
3647 Returns
3748 -------
3849 None
@@ -49,6 +60,15 @@ class S3Writer(Writer):
4960 profile.writer("s3").option(bucket_name="my_bucket").write()
5061 ```
5162
63+ Writing to an S3-compatible endpoint:
64+
65+ ```python
66+ profile.writer("s3").option(
67+ bucket_name="my_bucket",
68+ endpoint_url="https://<s3-compatible-endpoint>",
69+ ).write()
70+ ```
71+
5272 """
5373
5474 def __init__ (
@@ -57,8 +77,10 @@ def __init__(
5777 base_prefix : Optional [str ] = None ,
5878 bucket_name : Optional [str ] = None ,
5979 object_name : Optional [str ] = None ,
80+ endpoint_url : Optional [str ] = None ,
81+ config : Optional [Config ] = None ,
6082 ):
61- self .s3_client = s3_client or boto3 . client ( "s3" )
83+ self .s3_client = s3_client or build_s3_client ( config = config , endpoint_url = endpoint_url )
6284 self .base_prefix = base_prefix or "profile"
6385 self .bucket_name = bucket_name or ""
6486 self .object_name = object_name or None
0 commit comments