1616// under the License.
1717
1818use std:: sync:: Arc ;
19+ use std:: time:: Duration ;
1920
2021use pyo3:: prelude:: * ;
2122
@@ -24,6 +25,7 @@ use object_store::azure::{MicrosoftAzure, MicrosoftAzureBuilder};
2425use object_store:: gcp:: { GoogleCloudStorage , GoogleCloudStorageBuilder } ;
2526use object_store:: http:: { HttpBuilder , HttpStore } ;
2627use object_store:: local:: LocalFileSystem ;
28+ use object_store:: ClientOptions ;
2729use pyo3:: exceptions:: PyValueError ;
2830use url:: Url ;
2931
@@ -164,6 +166,41 @@ impl PyGoogleCloudContext {
164166 }
165167}
166168
169+ #[ pyclass( name = "ClientOptions" , module = "datafusion.store" , subclass) ]
170+ #[ derive( Debug , Clone ) ]
171+ pub struct PyClientOptions {
172+ pub inner : ClientOptions ,
173+ }
174+
175+ impl Default for PyClientOptions {
176+ fn default ( ) -> Self {
177+ Self :: new ( )
178+ }
179+ }
180+
181+ #[ pymethods]
182+ impl PyClientOptions {
183+ #[ pyo3( signature=( ) ) ]
184+ #[ new]
185+ pub fn new ( ) -> Self {
186+ Self {
187+ inner : ClientOptions :: new ( ) ,
188+ }
189+ }
190+
191+ #[ pyo3( signature = ( timeout) ) ]
192+ pub fn with_timeout ( & mut self , timeout : Duration ) -> Self {
193+ self . inner = self . inner . clone ( ) . with_timeout ( timeout) ;
194+ self . clone ( )
195+ }
196+
197+ #[ pyo3( signature = ( timeout) ) ]
198+ pub fn with_connect_timeout ( & mut self , timeout : Duration ) -> Self {
199+ self . inner = self . inner . clone ( ) . with_connect_timeout ( timeout) ;
200+ self . clone ( )
201+ }
202+ }
203+
167204#[ pyclass( name = "AmazonS3" , module = "datafusion.store" , subclass) ]
168205#[ derive( Debug , Clone ) ]
169206pub struct PyAmazonS3Context {
@@ -174,14 +211,15 @@ pub struct PyAmazonS3Context {
174211#[ pymethods]
175212impl PyAmazonS3Context {
176213 #[ allow( clippy:: too_many_arguments) ]
177- #[ pyo3( signature = ( bucket_name, region=None , access_key_id=None , secret_access_key=None , endpoint=None , allow_http=false , imdsv1_fallback=false ) ) ]
214+ #[ pyo3( signature = ( bucket_name, region=None , access_key_id=None , secret_access_key=None , endpoint=None , client_options= None , allow_http=false , imdsv1_fallback=false ) ) ]
178215 #[ new]
179216 fn new (
180217 bucket_name : String ,
181218 region : Option < String > ,
182219 access_key_id : Option < String > ,
183220 secret_access_key : Option < String > ,
184221 endpoint : Option < String > ,
222+ client_options : Option < PyClientOptions > ,
185223 //retry_config: RetryConfig,
186224 allow_http : bool ,
187225 imdsv1_fallback : bool ,
@@ -209,6 +247,10 @@ impl PyAmazonS3Context {
209247 builder = builder. with_imdsv1_fallback ( ) ;
210248 } ;
211249
250+ if let Some ( client_options) = client_options {
251+ builder = builder. with_client_options ( client_options. inner ) ;
252+ } ;
253+
212254 let store = builder
213255 . with_bucket_name ( bucket_name. clone ( ) )
214256 //.with_retry_config(retry_config) #TODO: add later
@@ -250,6 +292,7 @@ impl PyHttpContext {
250292}
251293
252294pub ( crate ) fn init_module ( m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
295+ m. add_class :: < PyClientOptions > ( ) ?;
253296 m. add_class :: < PyAmazonS3Context > ( ) ?;
254297 m. add_class :: < PyMicrosoftAzureContext > ( ) ?;
255298 m. add_class :: < PyGoogleCloudContext > ( ) ?;
0 commit comments