Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Support overriding the api_url directly (#946)
Joseph Lombrozo8c77cb04db8a
diff --git a/.changeset/hungry-mayflies-chew.md b/.changeset/hungry-mayflies-chew.mdnew file mode 100644index 000000000..6b7854294--- /dev/null+++ b/.changeset/hungry-mayflies-chew.md@@ -0,0 +1,5 @@+---+'@e2b/python-sdk': patch+---++Support overriding api_url via E2B_API_URLdiff --git a/packages/python-sdk/e2b/connection_config.py b/packages/python-sdk/e2b/connection_config.pyindex e6d2bb71d..e20ae4ba0 100644--- a/packages/python-sdk/e2b/connection_config.py+++ b/packages/python-sdk/e2b/connection_config.py@@ -31,6 +31,9 @@ class ApiParams(TypedDict, total=False):domain: Optional[str]"""E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable."""+ api_url: Optional[str]+ """URL to use for the API, defaults to `https://api.<domain>`. For internal use only."""+debug: Optional[bool]"""Whether to use debug mode, defaults to `E2B_DEBUG` environment variable."""@@ -55,6 +58,10 @@ class ConnectionConfig:def _api_key():return os.getenv("E2B_API_KEY")+ @staticmethod+ def _api_url():+ return os.getenv("E2B_API_URL")+@staticmethoddef _access_token():return os.getenv("E2B_ACCESS_TOKEN")@@ -64,6 +71,7 @@ class ConnectionConfig:domain: Optional[str] = None,debug: Optional[bool] = None,api_key: Optional[str] = None,+ api_url: Optional[str] = None,access_token: Optional[str] = None,request_timeout: Optional[float] = None,headers: Optional[Dict[str, str]] = None,@@ -93,7 +101,9 @@ class ConnectionConfig:self.request_timeout = REQUEST_TIMEOUTself.api_url = (- "http://localhost:3000" if self.debug else f"https://api.{self.domain}"+ api_url+ or ConnectionConfig._api_url()+ or ("http://localhost:3000" if self.debug else f"https://api.{self.domain}"))@staticmethod@@ -129,6 +139,7 @@ class ConnectionConfig:headers = opts.get("headers")request_timeout = opts.get("request_timeout")api_key = opts.get("api_key")+ api_url = opts.get("api_url")domain = opts.get("domain")debug = opts.get("debug")proxy = opts.get("proxy")@@ -140,6 +151,7 @@ class ConnectionConfig:return dict(ApiParams(api_key=api_key if api_key is not None else self.api_key,+ api_url=api_url if api_url is not None else self.api_url,domain=domain if domain is not None else self.domain,debug=debug if debug is not None else self.debug,request_timeout=self.get_request_timeout(request_timeout),diff --git a/packages/python-sdk/tests/test_connection_config.py b/packages/python-sdk/tests/test_connection_config.pynew file mode 100644index 000000000..197d2f106--- /dev/null+++ b/packages/python-sdk/tests/test_connection_config.py@@ -0,0 +1,25 @@+from e2b import ConnectionConfig+++def test_api_url_defaults_correctly():+ config = ConnectionConfig()+ assert config.api_url == "https://api.e2b.app"+++def test_api_url_in_args():+ config = ConnectionConfig(api_url="http://localhost:8080")+ assert config.api_url == "http://localhost:8080"+++def test_api_url_in_env_var(monkeypatch):+ monkeypatch.setenv("E2B_API_URL", "http://localhost:8080")++ config = ConnectionConfig()+ assert config.api_url == "http://localhost:8080"+++def test_api_url_has_correct_priority(monkeypatch):+ monkeypatch.setenv("E2B_API_URL", "http://localhost:1111")++ config = ConnectionConfig(api_url="http://localhost:8080")+ assert config.api_url == "http://localhost:8080"