1111from kili .adapters .authentification import is_api_key_valid
1212from kili .adapters .http_client import HttpClient
1313from kili .adapters .kili_api_gateway .kili_api_gateway import KiliAPIGateway
14+ from kili .core .config_loader import load_config_from_file
1415from kili .core .graphql .graphql_client import GraphQLClient , GraphQLClientName
1516from kili .entrypoints .mutations .asset import MutationsAsset
1617from kili .entrypoints .mutations .issue import MutationsIssue
@@ -91,6 +92,7 @@ def __init__(
9192 verify : Optional [Union [bool , str ]] = None ,
9293 client_name : GraphQLClientName = GraphQLClientName .SDK ,
9394 graphql_client_params : Optional [GraphQLClientParams ] = None ,
95+ disable_tqdm : bool | None = None ,
9496 ) -> None :
9597 """Initialize Kili client.
9698
@@ -118,6 +120,10 @@ def __init__(
118120 client_name: For internal use only.
119121 Define the name of the graphQL client whith which graphQL calls will be sent.
120122 graphql_client_params: Parameters to pass to the graphQL client.
123+ disable_tqdm: Global setting to disable progress bars (tqdm) for all operations.
124+ Can be overridden by individual function calls.
125+ Default to `KILI_DISABLE_TQDM` environment variable.
126+ If not passed, default to `disable_tqdm` in config file or False.
121127
122128 Returns:
123129 Instance of the Kili client.
@@ -130,33 +136,57 @@ def __init__(
130136 kili.assets()
131137 kili.projects()
132138 ```
139+
140+ Disable progress bars globally:
141+ ```python
142+ kili = Kili(disable_tqdm=True)
143+ ```
133144 """
134- api_key = api_key or os .getenv ("KILI_API_KEY" )
145+ config_file = load_config_from_file ()
146+
147+ api_key = api_key or os .getenv ("KILI_API_KEY" ) or config_file .get ("api_key" )
135148
136149 if not api_key and sys .stdin .isatty ():
137150 api_key = getpass .getpass (
138151 "No `KILI_API_KEY` environment variable found.\n Please enter your API key: "
139152 )
140153
141154 if api_endpoint is None :
142- api_endpoint = os .getenv (
143- "KILI_API_ENDPOINT" ,
144- "https://cloud.kili-technology.com/api/label/v2/graphql" ,
155+ api_endpoint = (
156+ os .getenv ("KILI_API_ENDPOINT" )
157+ or config_file .get ("api_endpoint" )
158+ or "https://cloud.kili-technology.com/api/label/v2/graphql"
145159 )
146160
161+ if verify is None :
162+ verify_env = os .getenv ("KILI_VERIFY" )
163+ if verify_env is not None :
164+ verify = verify_env .lower () in ("true" , "1" , "yes" )
165+ elif "verify_ssl" in config_file :
166+ verify = config_file ["verify_ssl" ]
167+ else :
168+ verify = True
169+
170+ # Load disable_tqdm from env or config if not explicitly provided
171+ if disable_tqdm is None :
172+ disable_tqdm_env = os .getenv ("KILI_DISABLE_TQDM" )
173+ if disable_tqdm_env is not None :
174+ disable_tqdm = disable_tqdm_env .lower () in ("true" , "1" , "yes" )
175+ elif "disable_tqdm" in config_file :
176+ disable_tqdm = config_file ["disable_tqdm" ]
177+ # Otherwise keep as None to let individual functions use their own defaults
178+
179+ assert api_endpoint is not None
180+ assert verify is not None
181+
147182 if not api_key :
148183 raise AuthenticationFailed (api_key , api_endpoint )
149184
150- if verify is None :
151- verify = os .getenv (
152- "KILI_VERIFY" ,
153- "True" ,
154- ).lower () in ("true" , "1" , "yes" )
155-
156185 self .api_key = api_key
157186 self .api_endpoint = api_endpoint
158187 self .verify = verify
159188 self .client_name = client_name
189+ self .disable_tqdm = disable_tqdm
160190 self .http_client = HttpClient (kili_endpoint = api_endpoint , verify = verify , api_key = api_key )
161191 skip_checks = os .getenv ("KILI_SDK_SKIP_CHECKS" ) is not None
162192 if not skip_checks and not is_api_key_valid (
0 commit comments