Arena utilities

Upload helpers shared by ArenaClient.

agilerl.arena.utils.extract_filename(disposition: str | None) str | None

Parse a filename from a Content-Disposition header value.

agilerl.arena.utils.prepare_env_upload(source: str | PathLike[str] | bytes) tuple[str, BinaryIO | bytes]

Resolve an environment source into an upload-ready (name, payload) pair.

source may be:

  • A path to a directory — compressed into .tar.gz automatically.

  • A path to a single file — compressed into .tar.gz automatically.

  • A path to an existing .tar.gz file — opened for streaming as-is.

  • Raw bytes — used directly (assumed to be a valid .tar.gz).

Path inputs resolve to open binary handles so httpx streams the upload in chunks instead of holding the whole artifact in memory; the caller is responsible for closing them once the request has been sent.

Parameters:

source (str | os.PathLike[str] | bytes) – The source of the environment.

Returns:

The name and payload (open handle or bytes) of the environment.

Return type:

tuple[str, BinaryIO | bytes]

Raises:

ArenaFileNotFoundError – If source is a path that does not exist.

agilerl.arena.utils.prepare_file_upload(source: str | PathLike[str] | bytes, *, default_name: str, content_type: str, filename: str | None = None) tuple[str, BinaryIO | bytes, str]

Resolve a path or raw bytes into an httpx multipart file tuple.

Path inputs resolve to open binary handles so httpx streams the upload in chunks instead of reading the whole file into memory; the caller is responsible for closing them once the request has been sent.

Parameters:
  • source (str | os.PathLike[str] | bytes) – File path or raw file contents.

  • default_name (str) – Filename used when source is raw bytes.

  • content_type (str) – MIME type for the upload part.

  • filename (str | None) – Multipart filename override (relative parquet shard path).

Returns:

(filename, payload, content_type) for httpx files=.

Return type:

tuple[str, BinaryIO | bytes, str]

Raises:

ArenaFileNotFoundError – If source is a path that does not exist.