33from __future__ import annotations
44
55import os
6- from typing import Any , Dict , Union , Mapping , cast
7- from typing_extensions import Self , Literal , override
6+ from typing import Any , Union , Mapping
7+ from typing_extensions import Self , override
88
99import httpx
1010
3131)
3232
3333__all__ = [
34- "ENVIRONMENTS" ,
3534 "Timeout" ,
3635 "Transport" ,
3736 "ProxiesTypes" ,
4241 "AsyncClient" ,
4342]
4443
45- ENVIRONMENTS : Dict [str , str ] = {
46- "production" : "https://portfolio-parser.api.casparser.in" ,
47- "local" : "http://localhost:5000" ,
48- }
49-
5044
5145class CasParser (SyncAPIClient ):
5246 cas_parser : cas_parser .CasParserResource
@@ -57,14 +51,11 @@ class CasParser(SyncAPIClient):
5751 # client options
5852 api_key : str
5953
60- _environment : Literal ["production" , "local" ] | NotGiven
61-
6254 def __init__ (
6355 self ,
6456 * ,
6557 api_key : str | None = None ,
66- environment : Literal ["production" , "local" ] | NotGiven = NOT_GIVEN ,
67- base_url : str | httpx .URL | None | NotGiven = NOT_GIVEN ,
58+ base_url : str | httpx .URL | None = None ,
6859 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
6960 max_retries : int = DEFAULT_MAX_RETRIES ,
7061 default_headers : Mapping [str , str ] | None = None ,
@@ -95,31 +86,10 @@ def __init__(
9586 )
9687 self .api_key = api_key
9788
98- self ._environment = environment
99-
100- base_url_env = os .environ .get ("CAS_PARSER_BASE_URL" )
101- if is_given (base_url ) and base_url is not None :
102- # cast required because mypy doesn't understand the type narrowing
103- base_url = cast ("str | httpx.URL" , base_url ) # pyright: ignore[reportUnnecessaryCast]
104- elif is_given (environment ):
105- if base_url_env and base_url is not None :
106- raise ValueError (
107- "Ambiguous URL; The `CAS_PARSER_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None" ,
108- )
109-
110- try :
111- base_url = ENVIRONMENTS [environment ]
112- except KeyError as exc :
113- raise ValueError (f"Unknown environment: { environment } " ) from exc
114- elif base_url_env is not None :
115- base_url = base_url_env
116- else :
117- self ._environment = environment = "production"
118-
119- try :
120- base_url = ENVIRONMENTS [environment ]
121- except KeyError as exc :
122- raise ValueError (f"Unknown environment: { environment } " ) from exc
89+ if base_url is None :
90+ base_url = os .environ .get ("CAS_PARSER_BASE_URL" )
91+ if base_url is None :
92+ base_url = f"https://portfolio-parser.api.casparser.in"
12393
12494 super ().__init__ (
12595 version = __version__ ,
@@ -161,7 +131,6 @@ def copy(
161131 self ,
162132 * ,
163133 api_key : str | None = None ,
164- environment : Literal ["production" , "local" ] | None = None ,
165134 base_url : str | httpx .URL | None = None ,
166135 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
167136 http_client : httpx .Client | None = None ,
@@ -197,7 +166,6 @@ def copy(
197166 return self .__class__ (
198167 api_key = api_key or self .api_key ,
199168 base_url = base_url or self .base_url ,
200- environment = environment or self ._environment ,
201169 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
202170 http_client = http_client ,
203171 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
@@ -253,14 +221,11 @@ class AsyncCasParser(AsyncAPIClient):
253221 # client options
254222 api_key : str
255223
256- _environment : Literal ["production" , "local" ] | NotGiven
257-
258224 def __init__ (
259225 self ,
260226 * ,
261227 api_key : str | None = None ,
262- environment : Literal ["production" , "local" ] | NotGiven = NOT_GIVEN ,
263- base_url : str | httpx .URL | None | NotGiven = NOT_GIVEN ,
228+ base_url : str | httpx .URL | None = None ,
264229 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
265230 max_retries : int = DEFAULT_MAX_RETRIES ,
266231 default_headers : Mapping [str , str ] | None = None ,
@@ -291,31 +256,10 @@ def __init__(
291256 )
292257 self .api_key = api_key
293258
294- self ._environment = environment
295-
296- base_url_env = os .environ .get ("CAS_PARSER_BASE_URL" )
297- if is_given (base_url ) and base_url is not None :
298- # cast required because mypy doesn't understand the type narrowing
299- base_url = cast ("str | httpx.URL" , base_url ) # pyright: ignore[reportUnnecessaryCast]
300- elif is_given (environment ):
301- if base_url_env and base_url is not None :
302- raise ValueError (
303- "Ambiguous URL; The `CAS_PARSER_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None" ,
304- )
305-
306- try :
307- base_url = ENVIRONMENTS [environment ]
308- except KeyError as exc :
309- raise ValueError (f"Unknown environment: { environment } " ) from exc
310- elif base_url_env is not None :
311- base_url = base_url_env
312- else :
313- self ._environment = environment = "production"
314-
315- try :
316- base_url = ENVIRONMENTS [environment ]
317- except KeyError as exc :
318- raise ValueError (f"Unknown environment: { environment } " ) from exc
259+ if base_url is None :
260+ base_url = os .environ .get ("CAS_PARSER_BASE_URL" )
261+ if base_url is None :
262+ base_url = f"https://portfolio-parser.api.casparser.in"
319263
320264 super ().__init__ (
321265 version = __version__ ,
@@ -357,7 +301,6 @@ def copy(
357301 self ,
358302 * ,
359303 api_key : str | None = None ,
360- environment : Literal ["production" , "local" ] | None = None ,
361304 base_url : str | httpx .URL | None = None ,
362305 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
363306 http_client : httpx .AsyncClient | None = None ,
@@ -393,7 +336,6 @@ def copy(
393336 return self .__class__ (
394337 api_key = api_key or self .api_key ,
395338 base_url = base_url or self .base_url ,
396- environment = environment or self ._environment ,
397339 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
398340 http_client = http_client ,
399341 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
0 commit comments