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
4141)
4242
4343__all__ = [
44- "ENVIRONMENTS" ,
4544 "Timeout" ,
4645 "Transport" ,
4746 "ProxiesTypes" ,
5251 "AsyncClient" ,
5352]
5453
55- ENVIRONMENTS : Dict [str , str ] = {
56- "production" : "https://api.trychannel3.com" ,
57- "development" : "https://localhost:8000" ,
58- }
59-
6054
6155class Channel3 (SyncAPIClient ):
6256 search : search .SearchResource
@@ -69,14 +63,11 @@ class Channel3(SyncAPIClient):
6963 # client options
7064 api_key : str
7165
72- _environment : Literal ["production" , "development" ] | NotGiven
73-
7466 def __init__ (
7567 self ,
7668 * ,
7769 api_key : str | None = None ,
78- environment : Literal ["production" , "development" ] | NotGiven = NOT_GIVEN ,
79- base_url : str | httpx .URL | None | NotGiven = NOT_GIVEN ,
70+ base_url : str | httpx .URL | None = None ,
8071 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
8172 max_retries : int = DEFAULT_MAX_RETRIES ,
8273 default_headers : Mapping [str , str ] | None = None ,
@@ -107,31 +98,10 @@ def __init__(
10798 )
10899 self .api_key = api_key
109100
110- self ._environment = environment
111-
112- base_url_env = os .environ .get ("CHANNEL3_BASE_URL" )
113- if is_given (base_url ) and base_url is not None :
114- # cast required because mypy doesn't understand the type narrowing
115- base_url = cast ("str | httpx.URL" , base_url ) # pyright: ignore[reportUnnecessaryCast]
116- elif is_given (environment ):
117- if base_url_env and base_url is not None :
118- raise ValueError (
119- "Ambiguous URL; The `CHANNEL3_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None" ,
120- )
121-
122- try :
123- base_url = ENVIRONMENTS [environment ]
124- except KeyError as exc :
125- raise ValueError (f"Unknown environment: { environment } " ) from exc
126- elif base_url_env is not None :
127- base_url = base_url_env
128- else :
129- self ._environment = environment = "production"
130-
131- try :
132- base_url = ENVIRONMENTS [environment ]
133- except KeyError as exc :
134- raise ValueError (f"Unknown environment: { environment } " ) from exc
101+ if base_url is None :
102+ base_url = os .environ .get ("CHANNEL3_BASE_URL" )
103+ if base_url is None :
104+ base_url = f"https://api.trychannel3.com"
135105
136106 super ().__init__ (
137107 version = __version__ ,
@@ -175,7 +145,6 @@ def copy(
175145 self ,
176146 * ,
177147 api_key : str | None = None ,
178- environment : Literal ["production" , "development" ] | None = None ,
179148 base_url : str | httpx .URL | None = None ,
180149 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
181150 http_client : httpx .Client | None = None ,
@@ -211,7 +180,6 @@ def copy(
211180 return self .__class__ (
212181 api_key = api_key or self .api_key ,
213182 base_url = base_url or self .base_url ,
214- environment = environment or self ._environment ,
215183 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
216184 http_client = http_client ,
217185 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
@@ -288,14 +256,11 @@ class AsyncChannel3(AsyncAPIClient):
288256 # client options
289257 api_key : str
290258
291- _environment : Literal ["production" , "development" ] | NotGiven
292-
293259 def __init__ (
294260 self ,
295261 * ,
296262 api_key : str | None = None ,
297- environment : Literal ["production" , "development" ] | NotGiven = NOT_GIVEN ,
298- base_url : str | httpx .URL | None | NotGiven = NOT_GIVEN ,
263+ base_url : str | httpx .URL | None = None ,
299264 timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
300265 max_retries : int = DEFAULT_MAX_RETRIES ,
301266 default_headers : Mapping [str , str ] | None = None ,
@@ -326,31 +291,10 @@ def __init__(
326291 )
327292 self .api_key = api_key
328293
329- self ._environment = environment
330-
331- base_url_env = os .environ .get ("CHANNEL3_BASE_URL" )
332- if is_given (base_url ) and base_url is not None :
333- # cast required because mypy doesn't understand the type narrowing
334- base_url = cast ("str | httpx.URL" , base_url ) # pyright: ignore[reportUnnecessaryCast]
335- elif is_given (environment ):
336- if base_url_env and base_url is not None :
337- raise ValueError (
338- "Ambiguous URL; The `CHANNEL3_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None" ,
339- )
340-
341- try :
342- base_url = ENVIRONMENTS [environment ]
343- except KeyError as exc :
344- raise ValueError (f"Unknown environment: { environment } " ) from exc
345- elif base_url_env is not None :
346- base_url = base_url_env
347- else :
348- self ._environment = environment = "production"
349-
350- try :
351- base_url = ENVIRONMENTS [environment ]
352- except KeyError as exc :
353- raise ValueError (f"Unknown environment: { environment } " ) from exc
294+ if base_url is None :
295+ base_url = os .environ .get ("CHANNEL3_BASE_URL" )
296+ if base_url is None :
297+ base_url = f"https://api.trychannel3.com"
354298
355299 super ().__init__ (
356300 version = __version__ ,
@@ -394,7 +338,6 @@ def copy(
394338 self ,
395339 * ,
396340 api_key : str | None = None ,
397- environment : Literal ["production" , "development" ] | None = None ,
398341 base_url : str | httpx .URL | None = None ,
399342 timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
400343 http_client : httpx .AsyncClient | None = None ,
@@ -430,7 +373,6 @@ def copy(
430373 return self .__class__ (
431374 api_key = api_key or self .api_key ,
432375 base_url = base_url or self .base_url ,
433- environment = environment or self ._environment ,
434376 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
435377 http_client = http_client ,
436378 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
0 commit comments