snowflake.core.code_bundle.CodeBundleResource

class snowflake.core.code_bundle.CodeBundleResource(name: str, collection: CodeBundleCollection)

Bases: CodeBundleResourceBase

Represents a reference to a Snowflake code bundle.

With this code bundle reference, you can fetch information about a code bundle, as well as perform certain actions on it, such as adding a version, executing it, or dropping it.

Attributes

database

The DatabaseResource this reference belongs to.

fully_qualified_name

Return the fully qualified name of the object this reference points to.

root

The Root object this reference belongs to.

Methods

add_version(add_version_code_bundle_request: AddVersionCodeBundleRequest) None

Add a version to a code bundle.

Parameters:

add_version_code_bundle_request (AddVersionCodeBundleRequest) – (required)

add_version_async(add_version_code_bundle_request: AddVersionCodeBundleRequest) PollingOperation[None]

An asynchronous version of add_version().

Refer to PollingOperation for more information on asynchronous execution and the return type.

drop(if_exists: bool | None = None) None

Delete a code bundle.

Parameters:

if_exists (bool) – Parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn’t exist.

drop_async(if_exists: bool | None = None) PollingOperation[None]

An asynchronous version of drop().

Refer to PollingOperation for more information on asynchronous execution and the return type.

execute(execute_code_bundle_request: ExecuteCodeBundleRequest, async_exec: bool | None = None) SuccessResponse | SuccessAcceptedResponse

Execute this code bundle.

Parameters:
  • execute_code_bundle_request (ExecuteCodeBundleRequest) – The execution specification, including the entry point to run (entrypoint). (required) The bundle configuration captured when the bundle was created is used by default; it can be overridden inline through the request’s specification field, a typed CodeBundleSpecification wrapping a BundleSpec (a plain dict of the same shape is still accepted).

  • async_exec (bool, optional) – Whether the code bundle should be executed asynchronously on the server. When True, the server accepts the execution and returns a SuccessAcceptedResponse carrying the job id. Defaults to None (synchronous execution on the server).

Returns:

A SuccessResponse when the execution completes synchronously, or a SuccessAcceptedResponse (with the job_id) when the server accepts it for asynchronous processing.

Return type:

Union[SuccessResponse, SuccessAcceptedResponse]

Examples

Executing a code bundle:

>>> code_bundles["my_code_bundle"].execute(ExecuteCodeBundleRequest(entrypoint="main.py"))

Overriding the bundle configuration with a typed, inline specification:

>>> from snowflake.core.code_bundle import BundleSpec, CodeBundleSpecification
>>> code_bundles["my_code_bundle"].execute(
...     ExecuteCodeBundleRequest(
...         entrypoint="main.py",
...         specification=CodeBundleSpecification(
...             bundle=BundleSpec(type="custom", compute_type="warehouse", language="python")
...         ),
...     )
... )
execute_async(execute_code_bundle_request: ExecuteCodeBundleRequest, async_exec: bool | None = None) PollingOperation[SuccessResponse | SuccessAcceptedResponse]

An asynchronous version of execute().

Refer to PollingOperation for more information on asynchronous execution and the return type.

fetch() CodeBundle

Fetch a code bundle.

fetch_async() PollingOperation[CodeBundle]

An asynchronous version of fetch().

Refer to PollingOperation for more information on asynchronous execution and the return type.