ImageClient

class baseten.sandbox.ImageClient

Bases: object

Images that sandboxes are created from.

Pushes them from a build context or a registry, and finds and deletes them. Obtained from SandboxClient.images.

Parameters:

context (ImageClientContext)

cleanup()

Remove image versions that no sandbox uses.

Return type:

ImageCleanupResult

delete(*, name)

Delete an image and all its versions. Fails while a sandbox uses any version.

Parameters:

name (str) – Name of the image.

Return type:

ImageInfo

delete_tag(*, name, tag)

Delete one version of an image, returning the image as it is afterwards.

Fails while a sandbox uses the version.

Parameters:
  • name (str) – Name of the image.

  • tag (str) – Tag of the version to delete.

Return type:

ImageInfo

get_info(*, name)

Get an image’s current record.

Parameters:

name (str) – Name of the image.

Return type:

ImageInfo

list(*, name_prefix=None, sort=None, page_size=None)

List images, fetching further pages as iteration reaches them.

Parameters:
  • name_prefix (str | None) – Only images whose names start with this, case-sensitively.

  • sort (Literal['name:asc', 'name:desc', 'createdAt:asc', 'createdAt:desc'] | str | None) – Defaults to createdAt:desc.

  • page_size (int | None) – How many images to fetch per underlying request.

Return type:

Iterator[ImageInfo]

list_library()

List the built-in images available to every team.

Return type:

list[ImageLibraryInfo]

list_tags(*, name, name_prefix=None, sort=None, page_size=None)

List an image’s versions, fetching further pages as iteration reaches them.

Parameters:
  • name (str) – Name of the image.

  • name_prefix (str | None) – Only tags whose names start with this, case-sensitively. Sorts by name ascending.

  • sort (Literal['name:asc', 'name:desc'] | str | None) – Sort order of the tags.

  • page_size (int | None) – How many tags to fetch per underlying request.

Return type:

Iterator[ImageTagInfo]

logs(*, name, start_time=None, end_time=None)

Get the build log of an image’s latest build, including a failed one.

Oldest line first. Logs may take a short time to appear. Returns at most the 11,000 most recent lines in the range; narrow the range to see earlier ones.

Parameters:
  • name (str) – Name of the image.

  • start_time (datetime | None) – Start of the range, inclusive. Defaults to 24 hours before end_time.

  • end_time (datetime | None) – End of the range. Defaults to now. The range must not exceed 7 days.

Return type:

list[ImageLogLine]

push(*, name: str, builder: ImageBuilder, temp_file: bool | None = None, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) → ImageInfo
push(*, name: str, registry_image: str, docker_config: str | None = None, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) → ImageInfo
push(*, name: str, zip: bytes, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) → ImageInfo
push(*, name: str, directory: str, ignore_file_processor: Callable[[ImageIgnoreFileProcessorOptions], Callable[[ImageIgnoreFileOptions], bool]] | None = None, default_ignore_file: Callable[[ImageIgnoreFileOptions], bool] | None = None, temp_file: bool | None = None, memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) → ImageInfo
push(*, name: str, files: Mapping[str, str | bytes], memory: int | None = None, volume: int | None = None, wait: bool = True, timeout: timedelta | None = datetime.timedelta(seconds=900), poll_interval: timedelta = datetime.timedelta(seconds=3)) → ImageInfo

Push an image, from a registry or from a build context built into one.

Takes exactly one source. Waits for the image to be ready to use unless wait is false. To create a sandbox from it, pass <name>:latest as the sandbox’s image.

A build context read from local files, from directory or a builder’s local files and directories, is zipped into an anonymous temporary file unless temp_file is false; any other is zipped in memory. It is uploaded in one attempt. If the upload fails, the image is left as the service has it, so push again or delete it.

Parameters:
  • name (str) – Repository name. Pushing to an existing name adds a new version to it.

  • builder (ImageBuilder | None) – Source: a builder whose Dockerfile and files make up the build context.

  • registry_image (str | None) – Source: a registry image reference to import, including its registry host.

  • docker_config (str | None) – Serialized registry credentials for a private registry_image.

  • zip (bytes | None) – Source: a zip archive of the build context, with a Dockerfile at its root.

  • directory (str | None) – Source: a local directory holding the build context, with a Dockerfile at its root. Files keep their permissions, a link to a file within the directory stores a copy of the file, a link to a file outside it fails the push, a link to a directory stores an empty directory, and a broken link is left out. Paths are left out as a .dockerignore at the directory’s root says, read through ignore_file_processor, or else by default_ignore_file. The root Dockerfile and .dockerignore are always kept, as Docker keeps them.

  • ignore_file_processor (Callable[[ImageIgnoreFileProcessorOptions], Callable[[ImageIgnoreFileOptions], bool]] | None) – Parses the .dockerignore at the root of directory. Required if there is one; otherwise the push fails before anything is sent. This package has no .dockerignore parser of its own.

  • default_ignore_file (Callable[[ImageIgnoreFileOptions], bool] | None) – Filters directory when it has no .dockerignore. Defaults to default_image_ignore_file(). Pass lambda _: False to push everything.

  • files (Mapping[str, str | bytes] | None) – Source: build context files by relative path, with forward slashes. Must include Dockerfile. A string is written as UTF-8, and files get mode 0644.

  • temp_file (bool | None) – Whether to zip a directory or a builder with local files into a temporary file, rather than in memory. Defaults to true.

  • memory (int | None) – Memory in megabytes, from 1 to 32768, of the temporary environment that builds the build context or imports registry_image. None uses the default size. Does not change the memory of sandboxes created from the image.

  • volume (int | None) – Scratch disk in megabytes, from 0 to 131072, attached to the build environment for intermediate layers. Set it for a large image that runs out of space while building or importing. None or 0 builds in memory, which is the default. Teams with HIPAA compliance enabled accept only None or 0.

  • wait (bool) – Whether to return only once the image is ready to use.

  • timeout (timedelta | None) – How long to wait for the image. None waits with no limit. Processing continues regardless.

  • poll_interval (timedelta) – How long between checks while waiting.

Raises:
  • ImageUploadError – Uploading the build context failed.

  • ImageBuildError – The build failed, or the wait timed out.

Return type:

ImageInfo

wait_built(*, name, timeout=datetime.timedelta(seconds=900), poll_interval=datetime.timedelta(seconds=3))

Wait for an image to be ready to use.

Checks the image’s current status, so right after pushing a new version of an image that was already built, this may return before the new version is processed; push with wait left on to avoid that.

Parameters:
  • name (str) – Name of the image.

  • timeout (timedelta | None) – How long to wait. None waits with no limit. Processing continues regardless.

  • poll_interval (timedelta) – How long between checks.

Raises:

ImageBuildError – The build failed, or the wait timed out.

Return type:

ImageInfo