Skip to content

Client

Uploading

sender

BatchProgressCallback

Bases: Protocol

Callback protocol for observing batch upload progress.

async_send_file async

async_send_file(
    source: Path | MZMLFile | MSZFile | MSZXFile,
    base_url: str,
    progress_callback: Callable[[int], None] | None = None,
    timeout: Timeout | None = None,
    poll_timeout: float | None = 3600.0,
    chunk_size: int = 1048576,
    api_key: str | None = None,
    client: AsyncClient | None = None,
) -> UploadResponse

Send a single file to the mstransfer listener (async).

Accepts a file path, or an already-opened MZMLFile / MSZFile / MSZXFile from mscompress. Returns the final transfer status from the server.

timeout replaces client's timeouts for the upload request; pass httpx.Timeout(None) for no limit. If None, client's timeouts are used (10 s connect, 3600 s otherwise, without client).

poll_timeout is how long to wait without server-side progress while polling for completion, in seconds, or None to wait forever. Status polls use client's timeout, or 10 s without client.

async_send_batch async

async_send_batch(
    sources: Sequence[Path | MZMLFile | MSZFile | MSZXFile],
    base_url: str,
    parallel: int = 4,
    chunk_size: int = 1048576,
    progress: BatchProgressCallback | None = None,
    api_key: str | None = None,
    client: AsyncClient | None = None,
    timeout: Timeout | None = None,
    poll_timeout: float | None = 3600.0,
) -> list[FileResult[UploadResponse]]

Send multiple files with configurable parallelism (async).

Returns one FileResult per source, in input order, carrying the final transfer status or the error.

timeout and poll_timeout are passed to async_send_file for each file.

send_file

send_file(
    source: Path | MZMLFile | MSZFile | MSZXFile,
    base_url: str,
    progress_callback: Callable[[int], None] | None = None,
    timeout: Timeout | None = None,
    poll_timeout: float | None = 3600.0,
    chunk_size: int = 1048576,
    api_key: str | None = None,
    client: AsyncClient | None = None,
) -> UploadResponse

Send a single file to the mstransfer listener.

Accepts a file path, or an already-opened MZMLFile / MSZFile / MSZXFile from mscompress. Returns the final transfer status from the server.

This is a synchronous wrapper around async_send_file.

send_batch

send_batch(
    sources: Sequence[Path | MZMLFile | MSZFile | MSZXFile],
    base_url: str,
    parallel: int = 4,
    chunk_size: int = 1048576,
    progress: BatchProgressCallback | None = None,
    api_key: str | None = None,
    client: AsyncClient | None = None,
    timeout: Timeout | None = None,
    poll_timeout: float | None = 3600.0,
) -> list[FileResult[UploadResponse]]

Send multiple files with configurable parallelism.

timeout and poll_timeout are passed to async_send_file for each file.

This is a synchronous wrapper around async_send_batch.

Downloading

downloader

DownloadProgressCallback

Bases: Protocol

Callback protocol for observing single-file download progress.

BatchDownloadProgress

Bases: Protocol

Callback protocol for observing batch download progress.

DownloadRequest dataclass

DownloadRequest(url: str, dest: Path)

A single download request: URL to fetch and local destination path.

DownloadResult dataclass

DownloadResult(
    request: DownloadRequest,
    path: Path,
    skipped: bool = False,
)

A completed download: the request and where its output was written.

skipped is True when the output already existed and nothing was downloaded (see skip_existing).

async_download_file async

async_download_file(
    url: str,
    dest: Path,
    *,
    store_as: DownloadFormat | None = None,
    chunk_size: int = 1048576,
    timeout: Timeout | None = None,
    progress_callback: DownloadProgressCallback
    | None = None,
    skip_existing: bool = False,
    force: bool = False,
    resume: bool = True,
    api_key: str | None = None,
    client: AsyncClient | None = None,
) -> Path

Download a single file from url to dest (async).

The file is streamed to a temporary .part file first, then atomically renamed (or converted) to the final destination on success.

With resume, an interrupted download keeps its partial .part file (and a .part.json describing it) next to dest, and a later call continues from the bytes already received. A partial is only kept when the server sent a strong ETag and the body size, and it is only resumed with an If-Range request carrying that ETag. If the server does not support ranges, or the file changed, the download restarts from zero. The finished file must have exactly the expected size.

Parameters:

Name Type Description Default
url str

The URL to download from.

required
dest Path

The local path where the file should be saved. If store_as requires a format conversion, the extension will be adjusted automatically.

required
store_as DownloadFormat | None

Desired output format — "msz", "mzml", "mszx", or None to keep the file as-is. When set, the downloaded file is converted after download using mscompress. Conversion to "mszx" is only supported when the source is already .mszx (no-op). When a multi-member (batch) .mszx is stored as "msz" or "mzml", its members are written to a directory named after the archive, dest.parent/<dest stem>/<entry stem>.<ext>. The directory appears only once every member is written, and replaces any existing directory of that name.

None
chunk_size int

Number of bytes per read chunk (default 1 MiB).

1048576
timeout Timeout | None

Timeouts for the request, replacing client's; pass httpx.Timeout(None) for no limit. If None, client's timeouts are used (10 s connect, 300 s otherwise, without client).

None
progress_callback DownloadProgressCallback | None

Optional callback. on_total is invoked once the server responds, with the file size (or None if unknown); on_progress is invoked with byte deltas per chunk. A resumed download first reports the bytes it already had as one delta.

None
skip_existing bool

If True and the final destination already exists, skip the download. For an .mszx stored as "msz" or "mzml", an existing archive directory (see store_as) also counts.

False
force bool

If True, re-download even if the destination already exists (overrides skip_existing), discarding any partial download.

False
resume bool

If True (the default), resume a partial download of url to dest and keep this one's partial if it is interrupted. Only one download to dest at a time can do so; a concurrent one uses a private .part file that is never resumed. If False, start from zero and keep nothing on failure; on success, remove the partial an earlier download left, unless one is using it.

True
api_key str | None

Optional API key, sent as Authorization: Bearer <key>.

None
client AsyncClient | None

Optional httpx.AsyncClient to reuse; a temporary one is created and closed otherwise.

None

Returns:

Type Description
Path

The final destination path (may differ from dest if the extension

Path

was adjusted for format conversion), or the archive directory for a

Path

multi-member .mszx.

Raises:

Type Description
NotImplementedError

The source cannot be converted to store_as.

ValueError

Two members of a multi-member .mszx map to the same output name (raised before anything is written), the downloaded size does not match the size the server announced, or the server sent part of the file when it was not asked to.

async_download_batch async

async_download_batch(
    files: list[DownloadRequest],
    *,
    store_as: DownloadFormat | None = None,
    parallel: int = 4,
    chunk_size: int = 1048576,
    timeout: Timeout | None = None,
    progress: BatchDownloadProgress | None = None,
    skip_existing: bool = False,
    force: bool = False,
    resume: bool = True,
    api_key: str | None = None,
    client: AsyncClient | None = None,
) -> list[FileResult[DownloadResult]]

Download multiple files in parallel (async).

Parameters:

Name Type Description Default
files list[DownloadRequest]

List of DownloadRequest objects (url + dest pairs).

required
store_as DownloadFormat | None

Desired output format — "msz", "mzml", "mszx", or None to keep files as-is. Forwarded to each async_download_file call.

None
parallel int

Maximum number of concurrent downloads (capped to file count).

4
chunk_size int

Number of bytes per read chunk.

1048576
timeout Timeout | None

Timeouts for each request, replacing client's; pass httpx.Timeout(None) for no limit. If None, client's timeouts are used (10 s connect, 300 s otherwise, without client).

None
progress BatchDownloadProgress | None

Optional batch progress callback.

None
skip_existing bool

If True, skip files whose destination already exists.

False
force bool

If True, re-download even if destination exists.

False
resume bool

If True (the default), resume partial downloads and keep resumable partials of failed ones (see async_download_file).

True
api_key str | None

Optional API key, sent as Authorization: Bearer <key>.

None
client AsyncClient | None

Optional httpx.AsyncClient shared by every download; a temporary one is created per request otherwise.

None

Returns:

Type Description
list[FileResult[DownloadResult]]

One result per request, in input order, named after the request's

list[FileResult[DownloadResult]]

dest, carrying either a DownloadResult or the error. A

list[FileResult[DownloadResult]]

multi-member .mszx yields its archive directory as the path. A

list[FileResult[DownloadResult]]

file skipped by skip_existing has skipped set and is still

list[FileResult[DownloadResult]]

reported to progress as complete.

download_file

download_file(
    url: str,
    dest: Path,
    *,
    store_as: DownloadFormat | None = None,
    chunk_size: int = 1048576,
    timeout: Timeout | None = None,
    progress_callback: DownloadProgressCallback
    | None = None,
    skip_existing: bool = False,
    force: bool = False,
    resume: bool = True,
    api_key: str | None = None,
    client: AsyncClient | None = None,
) -> Path

Download a single file from url to dest.

This is a synchronous wrapper around async_download_file.

download_batch

download_batch(
    files: list[DownloadRequest],
    *,
    store_as: DownloadFormat | None = None,
    parallel: int = 4,
    chunk_size: int = 1048576,
    timeout: Timeout | None = None,
    progress: BatchDownloadProgress | None = None,
    skip_existing: bool = False,
    force: bool = False,
    resume: bool = True,
    api_key: str | None = None,
    client: AsyncClient | None = None,
) -> list[FileResult[DownloadResult]]

Download multiple files in parallel.

This is a synchronous wrapper around async_download_batch.

Results

results

FileResult dataclass

FileResult(
    filename: str,
    response: T | None = None,
    error: Exception | None = None,
)

Bases: Generic[T]

Result of transferring a single file in a batch.

Uploads return FileResult[UploadResponse] and downloads return FileResult[DownloadResult], one per input, in input order.

Exactly one of response and error is set: response on success, error the exception that failed the transfer. An exception raised by the batch's completion progress callback is logged and does not count as a failure.

Utilities

resolve_inputs

resolve_inputs(
    paths: list[str], recursive: bool = False
) -> list[Path]

Resolve files and directories into a sorted list of valid MS files.