Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Rename alias exists > name exists (#1100)
Mish Ushakov07ef17f1b031
diff --git a/.changeset/neat-tips-stick.md b/.changeset/neat-tips-stick.mdnew file mode 100644index 000000000..e8367e384--- /dev/null+++ b/.changeset/neat-tips-stick.md@@ -0,0 +1,6 @@+---+'@e2b/python-sdk': patch+'e2b': patch+---++deprecate aliasexists and add existsdiff --git a/packages/js-sdk/src/template/index.ts b/packages/js-sdk/src/template/index.tsindex 0712b1810..c40184ab3 100644--- a/packages/js-sdk/src/template/index.ts+++ b/packages/js-sdk/src/template/index.ts@@ -20,7 +20,6 @@ import { parseDockerfile } from './dockerfileParser'import { LogEntry, LogEntryEnd, LogEntryStart } from './logger'import { ReadyCmd, waitForFile } from './readycmd'import {- AliasExistsOptions,BuildInfo,BuildOptions,CopyItem,@@ -268,6 +267,28 @@ export class TemplateBase})}+ /**+ * Check if a template with the given name exists.+ *+ * @param name Template name to check+ * @param options Authentication options+ * @returns True if the name exists, false otherwise+ *+ * @example+ * ```ts+ * const exists = await Template.exists('my-python-env')+ * if (exists) {+ * console.log('Template exists!')+ * }+ * ```+ */+ static async exists(+ name: string,+ options?: ConnectionOpts+ ): Promise<boolean> {+ return TemplateBase.aliasExists(name, options)+ }+/*** Check if a template with the given alias exists.*@@ -275,6 +296,7 @@ export class TemplateBase* @param options Authentication options* @returns True if the alias exists, false otherwise*+ * @deprecated Use `exists` instead.* @example* ```ts* const exists = await Template.aliasExists('my-python-env')@@ -285,7 +307,7 @@ export class TemplateBase*/static async aliasExists(alias: string,- options?: AliasExistsOptions+ options?: ConnectionOpts): Promise<boolean> {const config = new ConnectionConfig(options)const client = new ApiClient(config)@@ -1223,6 +1245,7 @@ export function Template(options?: TemplateOptions): TemplateFromImage {Template.build = TemplateBase.buildTemplate.buildInBackground = TemplateBase.buildInBackgroundTemplate.getBuildStatus = TemplateBase.getBuildStatus+Template.exists = TemplateBase.existsTemplate.aliasExists = TemplateBase.aliasExistsTemplate.assignTags = TemplateBase.assignTagsTemplate.removeTags = TemplateBase.removeTags@@ -1230,7 +1253,6 @@ Template.toJSON = TemplateBase.toJSONTemplate.toDockerfile = TemplateBase.toDockerfileexport type {- AliasExistsOptions,BuildInfo,BuildOptions,BuildStatusReason,diff --git a/packages/js-sdk/src/template/types.ts b/packages/js-sdk/src/template/types.tsindex 5d0feabdf..23999de7c 100644--- a/packages/js-sdk/src/template/types.ts+++ b/packages/js-sdk/src/template/types.ts@@ -158,11 +158,6 @@ export type TemplateTagInfo = {tags: string[]}-/**- * Options for checking if a template alias exists.- */-export type AliasExistsOptions = ConnectionOpts-/*** Types of instructions that can be used in a template.*/diff --git a/packages/js-sdk/tests/template/aliasExists.test.ts b/packages/js-sdk/tests/template/aliasExists.test.tsdeleted file mode 100644index a91449dfb..000000000--- a/packages/js-sdk/tests/template/aliasExists.test.ts+++ /dev/null@@ -1,14 +0,0 @@-import { randomUUID } from 'node:crypto'-import { expect, test } from 'vitest'-import { Template } from '../../src'--test('check if base template alias exists', async () => {- const exists = await Template.aliasExists('base')- expect(exists).toBe(true)-})--test('check non existing alias', async () => {- const nonExistingAlias = `nonexistent-${randomUUID()}`- const exists = await Template.aliasExists(nonExistingAlias)- expect(exists).toBe(false)-})diff --git a/packages/js-sdk/tests/template/exists.test.ts b/packages/js-sdk/tests/template/exists.test.tsnew file mode 100644index 000000000..aa62857c7--- /dev/null+++ b/packages/js-sdk/tests/template/exists.test.ts@@ -0,0 +1,14 @@+import { randomUUID } from 'node:crypto'+import { expect, test } from 'vitest'+import { Template } from '../../src'++test('check if base template name exists', async () => {+ const exists = await Template.exists('base')+ expect(exists).toBe(true)+})++test('check non existing name', async () => {+ const nonExistingName = `nonexistent-${randomUUID()}`+ const exists = await Template.exists(nonExistingName)+ expect(exists).toBe(false)+})diff --git a/packages/python-sdk/e2b/template_async/main.py b/packages/python-sdk/e2b/template_async/main.pyindex 8a1746b4d..a459af2cc 100644--- a/packages/python-sdk/e2b/template_async/main.py+++ b/packages/python-sdk/e2b/template_async/main.py@@ -376,6 +376,29 @@ class AsyncTemplate(TemplateBase):logs_offset,)+ @staticmethod+ async def exists(+ name: str,+ **opts: Unpack[ApiParams],+ ) -> bool:+ """+ Check if a template with the given name exists.++ :param name: Template name to check+ :return: True if the name exists, False otherwise++ Example+ ```python+ from e2b import AsyncTemplate++ exists = await AsyncTemplate.exists('my-python-env')+ if exists:+ print('Template exists!')+ ```+ """++ return await AsyncTemplate.alias_exists(name, **opts)+@staticmethodasync def alias_exists(alias: str,@@ -384,6 +407,8 @@ class AsyncTemplate(TemplateBase):"""Check if a template with the given alias exists.+ Deprecated Use `exists` instead.+:param alias: Template alias to check:return: True if the alias exists, False otherwise@@ -391,7 +416,7 @@ class AsyncTemplate(TemplateBase):```pythonfrom e2b import AsyncTemplate- exists = await AsyncTemplate.alias_exists('base')+ exists = await AsyncTemplate.alias_exists('my-python-env')if exists:print('Template exists!')```diff --git a/packages/python-sdk/e2b/template_sync/main.py b/packages/python-sdk/e2b/template_sync/main.pyindex 10a6012f8..1278e4d0c 100644--- a/packages/python-sdk/e2b/template_sync/main.py+++ b/packages/python-sdk/e2b/template_sync/main.py@@ -377,6 +377,29 @@ class Template(TemplateBase):logs_offset,)+ @staticmethod+ def exists(+ name: str,+ **opts: Unpack[ApiParams],+ ) -> bool:+ """+ Check if a template with the given name exists.++ :param name: Template name to check+ :return: True if the name exists, False otherwise++ Example+ ```python+ from e2b import Template++ exists = Template.exists('my-python-env')+ if exists:+ print('Template exists!')+ ```+ """++ return Template.alias_exists(name, **opts)+@staticmethoddef alias_exists(alias: str,@@ -385,6 +408,8 @@ class Template(TemplateBase):"""Check if a template with the given alias exists.+ Deprecated Use `exists` instead.+:param alias: Template alias to check:return: True if the alias exists, False otherwise@@ -392,7 +417,7 @@ class Template(TemplateBase):```pythonfrom e2b import Template- exists = Template.alias_exists('base')+ exists = Template.alias_exists('my-python-env')if exists:print('Template exists!')```diff --git a/packages/python-sdk/tests/async/template_async/test_alias_exists.py b/packages/python-sdk/tests/async/template_async/test_alias_exists.pydeleted file mode 100644index da2b7093d..000000000--- a/packages/python-sdk/tests/async/template_async/test_alias_exists.py+++ /dev/null@@ -1,20 +0,0 @@-import uuid--import pytest--from e2b import AsyncTemplate--[email protected]_debug()-async def test_check_base_template_alias_exists():- """Test that the base template alias exists."""- exists = await AsyncTemplate.alias_exists("base")- assert exists is True--[email protected]_debug()-async def test_check_non_existing_alias():- """Test that a non-existing alias returns False."""- non_existing_alias = f"nonexistent-{uuid.uuid4()}"- exists = await AsyncTemplate.alias_exists(non_existing_alias)- assert exists is Falsediff --git a/packages/python-sdk/tests/async/template_async/test_exists.py b/packages/python-sdk/tests/async/template_async/test_exists.pynew file mode 100644index 000000000..6da560947--- /dev/null+++ b/packages/python-sdk/tests/async/template_async/test_exists.py@@ -0,0 +1,20 @@+import uuid++import pytest++from e2b import AsyncTemplate++[email protected]_debug()+async def test_check_base_template_name_exists():+ """Test that the base template name exists."""+ exists = await AsyncTemplate.exists("base")+ assert exists is True++[email protected]_debug()+async def test_check_non_existing_name():+ """Test that a non-existing name returns False."""+ non_existing_name = f"nonexistent-{uuid.uuid4()}"+ exists = await AsyncTemplate.exists(non_existing_name)+ assert exists is Falsediff --git a/packages/python-sdk/tests/sync/template_sync/test_alias_exists.py b/packages/python-sdk/tests/sync/template_sync/test_alias_exists.pydeleted file mode 100644index 43397db90..000000000--- a/packages/python-sdk/tests/sync/template_sync/test_alias_exists.py+++ /dev/null@@ -1,20 +0,0 @@-import uuid--import pytest--from e2b import Template--[email protected]_debug()-def test_check_base_template_alias_exists():- """Test that the base template alias exists."""- exists = Template.alias_exists("base")- assert exists is True--[email protected]_debug()-def test_check_non_existing_alias():- """Test that a non-existing alias returns False."""- non_existing_alias = f"nonexistent-{uuid.uuid4()}"- exists = Template.alias_exists(non_existing_alias)- assert exists is Falsediff --git a/packages/python-sdk/tests/sync/template_sync/test_exists.py b/packages/python-sdk/tests/sync/template_sync/test_exists.pynew file mode 100644index 000000000..641b58ba0--- /dev/null+++ b/packages/python-sdk/tests/sync/template_sync/test_exists.py@@ -0,0 +1,20 @@+import uuid++import pytest++from e2b import Template++[email protected]_debug()+def test_check_base_template_name_exists():+ """Test that the base template name exists."""+ exists = Template.exists("base")+ assert exists is True++[email protected]_debug()+def test_check_non_existing_name():+ """Test that a non-existing name returns False."""+ non_existing_name = f"nonexistent-{uuid.uuid4()}"+ exists = Template.exists(non_existing_name)+ assert exists is False