Skip to content

Commit 55dddb8

Browse files
committed
add without_files parameter to client, allow saving memory by not importing libraries for all storage backends
1 parent 22080b5 commit 55dddb8

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

kbcstorage/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Client:
1818
Storage API Client.
1919
"""
2020

21-
def __init__(self, api_domain, token, branch_id='default'):
21+
def __init__(self, api_domain, token, branch_id='default', without_files=False):
2222
"""
2323
Initialise a client.
2424
@@ -27,13 +27,15 @@ def __init__(self, api_domain, token, branch_id='default'):
2727
"https://connection.keboola.com".
2828
token (str): A storage API key.
2929
branch_id (str): The ID of branch to use, use 'default' to work without branch (in main).
30+
without_files (bool): If True, do not init the Files endpoint and saves memory by not importing libraries for all backends.
3031
"""
3132
self.root_url = api_domain.rstrip("/")
3233
self._token = token
3334
self._branch_id = branch_id
3435

3536
self.buckets = Buckets(self.root_url, self.token)
36-
self.files = Files(self.root_url, self.token)
37+
if not without_files:
38+
self.files = Files(self.root_url, self.token)
3739
self.jobs = Jobs(self.root_url, self.token)
3840
self.tables = Tables(self.root_url, self.token)
3941
self.workspaces = Workspaces(self.root_url, self.token)

kbcstorage/files.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
"""
99
import json
1010
import os
11-
import boto3
1211
import requests
1312

14-
from azure.storage.blob import BlobServiceClient, ContentSettings
1513
from kbcstorage.base import Endpoint
16-
from google.oauth2 import credentials
17-
from google.cloud import storage as GCPStorage
1814

1915

2016
class Files(Endpoint):
@@ -29,6 +25,12 @@ def __init__(self, root_url, token):
2925
root_url (:obj:`str`): The base url for the API.
3026
token (:obj:`str`): A storage API key.
3127
"""
28+
29+
from azure.storage.blob import BlobServiceClient, ContentSettings
30+
import boto3
31+
from google.oauth2 import credentials
32+
from google.cloud import storage as GCPStorage
33+
3234
super().__init__(root_url, 'files', token)
3335

3436
def detail(self, file_id, federation_token=False):

0 commit comments

Comments
 (0)