Skip to main content

mstransfer

Tests codecov

Transfer mass spectrometry files (mzML / MSZ) between machines over HTTP. Files are always transported in compressed MSZ format using mscompress — mzML sources are compressed on-the-fly without temp files, and the receiving end can optionally decompress back to mzML.

Documentation: https://chrisagrams.github.io/mstransfer/

Install

# Recommended — installs as an isolated CLI tool
uv tool install mstransfer

# Or with pipx
pipx install mstransfer

# Or as a project dependency
uv pip install mstransfer
pip install mstransfer

Quick start

Start a server on the receiving machine:

mstransfer serve --port 1319 --store-as msz

Upload files from the source machine:

mstransfer upload /data/experiment1.mzML /data/batch/ remote-host:1319

Usage

mstransfer serve

Start the receiver server.

mstransfer serve [--host 0.0.0.0] [--port 1319] [--output-dir ./received] [--store-as msz|mzml]
Flag Default Description
--host 0.0.0.0 Bind address
--port 1319 Listen port
--output-dir ./received Where received files are written
--store-as msz Store as msz (compressed) or mzml (decompress on arrival). .mszx archives are always stored as-is.

mstransfer upload

Upload files to a server. Accepts any mix of files and directories. The last positional argument is the target.

mstransfer upload <paths...> <host[:port]> [--recursive] [--parallel 4]
Flag Default Description
--recursive, -r off Recurse into directories
--parallel, -p 4 Number of concurrent uploads

Supported file types: .mzML, .msz, .mszx.

  • mzML files are compressed to MSZ on-the-fly via compress_stream() and streamed directly into the HTTP request — no temp files on the sender.
  • MSZ / MSZX files are streamed as-is.

The client sends the format in an X-Source-Format header (mzML, msz or mszx). The server stores .mszx uploads untouched as <stem>.mszx, whatever --store-as says.

The server names each stored file after the upload's stem, so run1.mzML and run1.msz both become run1.msz. It refuses an upload with 409 Conflict if that output file already exists or another transfer is still writing it. The refused file counts as failed, and the CLI exits non-zero.

mstransfer download

Download files from a server by URL, e.g. http://remote-host:1319/v1/files/run1.msz.

mstransfer download <urls...> [--output-dir ./downloads] [--parallel 4] [--connections 1] [--store-as msz|mzml|mszx] [--skip-existing] [--force] [--no-resume]
Flag Default Description
--output-dir, -o ./downloads Where downloaded files are written
--parallel, -p 4 Number of concurrent downloads
--connections, -c 1 HTTP connections per file (split via Range requests)
--store-as as-is Convert each download to msz, mzml or (for .mszx only) mszx
--skip-existing off Skip files whose output already exists
--force off Download again even if the output exists, discarding any partial download
--no-resume off Start interrupted downloads over instead of resuming them

If a download is interrupted (for example by a dropped connection or Ctrl-C), running the same command again picks up where it left off instead of starting over. If the file changed on the server in the meantime, or the server can't resume downloads, it starts from the beginning.

With --connections N (N > 1), each file is split into up to N byte ranges fetched concurrently, each by its own worker process on its own connection, and written into a preallocated .part file. Each part is at least 8 MiB (min_part_size in the Python API), so small files use fewer connections. If the server does not support Range requests, the download falls back to a single stream. --connections is independent of --parallel: up to parallel × connections requests (and worker processes) may be open at once. A split download is not resumable; if it fails, it starts over next time.

Authentication

serve, upload and download all take --api-key. On serve it makes the server require that key; on upload and download it is sent as Authorization: Bearer <key>. When --api-key is not given, each command reads the MS_API_KEY environment variable instead. If neither is set (or MS_API_KEY is empty), no key is used.

export MS_API_KEY=secret
mstransfer serve                                        # requires the key
mstransfer upload run1.mzML remote-host                 # sends the key
mstransfer download http://remote-host:1319/v1/files/run1.msz

Programmatic access

You can use mstransfer as a library to send files from your own Python code:

from pathlib import Path
from mstransfer.client import send_file, send_batch

# Send a single file (Path)
result = send_file(Path("experiment.mzML"), "http://remote-host:1319")

# Send an already-opened mscompress object
from mscompress import MZMLFile, MSZFile
from mscompress.mszx import MSZXFile

mzml = MZMLFile(b"/data/experiment.mzML")
send_file(mzml, "http://remote-host:1319")

msz = MSZFile(b"/data/experiment.msz")
send_file(msz, "http://remote-host:1319")

mszx = MSZXFile.open("/data/experiment.mszx")
send_file(mszx, "http://remote-host:1319")

# Send multiple files in parallel
send_batch(
    [Path("a.mzML"), Path("b.msz"), mszx],
    "http://remote-host:1319",
    parallel=4,
)

send_file and send_batch accept any mix of Path, MZMLFile, MSZFile, and MSZXFile inputs.

API

The server exposes a REST API under /v1/:

Endpoint Method Description
/v1/health GET Server status, version, storage mode
/v1/upload POST Upload a file (streamed MSZ body)
/v1/transfer/{id}/status GET Poll transfer state

Embedding in another app

The server is built as a FastAPI app factory:

from mstransfer import create_app

# Standalone
app = create_app(output_dir="/data/ms", store_as="mzml")

# Mount in an existing FastAPI app
from fastapi import FastAPI

main_app = FastAPI()
main_app.mount("/transfer", create_app())

auth= protects every route except /v1/health. To protect one direction only, pass upload_auth= (upload and transfer status) and/or download_auth= (file list and download) instead; a direction without auth is left open:

from mstransfer import APIKeyAuthProvider, create_app

# Anyone can download; only key holders can upload
app = create_app(upload_auth=APIKeyAuthProvider("secret"))

make_router takes the same split as upload_auth_dep= / download_auth_dep=.

file_provider= controls what /v1/files lists and serves (default: the output directory). A provider's get_file returns a Path, or a ServedFile when the bytes are stored under another name, such as a content-addressed blob:

from mstransfer.server.models import ServedFile


class BlobProvider:
    async def list_files(self): ...

    async def get_file(self, filename):
        blob = lookup_blob(filename)  # e.g. blobs/sha256/ab/cdef...
        return ServedFile(path=blob, name=filename) if blob else None

The download is streamed from path but sent as name, which sets the Content-Disposition filename and the media type. See File providers.

How it works

flowchart LR
    subgraph Sender
        mzML[".mzML"] --> compress["compress_stream()"]
        msz[".msz / .mszx"] --> read["read file"]
    end

    compress --> upload["POST /v1/upload\n(MSZ bytes)"]
    read --> upload

    subgraph Server
        upload --> kind{source format?}
        kind -- mszx --> keep["write .mszx as-is"]
        kind -- mzML / msz --> mode{store-as?}
        mode -- msz --> write["write to disk"]
        mode -- mzml --> temp["write temp .msz"]
        temp --> decompress["decompress"]
        decompress --> cleanup["cleanup temp"]
    end

Development

uv sync --dev
uv run pytest
uv run ruff check src/ tests/

Pre-commit hooks

Install the pre-commit hooks to automatically run linting, type checking, and tests before each commit:

uv run pre-commit install

Metadata

Release files for mstransfer 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mstransfer 0.4.0
File Size Uploaded Provenance Actions
mstransfer-0.4.0.tar.gz 2.2 MB With provenance Details for mstransfer-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mstransfer 0.4.0
File Interpreter ABI Platform Actions
mstransfer-0.4.0-py3-none-any.whl Python 3 none any Details for mstransfer-0.4.0-py3-none-any.whl

Total release size: 2.2 MB

Release files / mstransfer-0.4.0.tar.gz

Download URL mstransfer-0.4.0.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
3a4200ae17d853cd30fff6e30555d69a028fb61e102569ebc19c29a1d168f9e7
BLAKE2b-256 checksum
How to use checksums
51f66ce30d22da318cec3ab7eca0e7ea81b700884def6611004b0cec0d785755
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / mstransfer-0.4.0-py3-none-any.whl

Download URL mstransfer-0.4.0-py3-none-any.whl
Size 40.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ba7fc86d4e47820a336bb3bed6278c4af300a2b81daf9eafc04b3bb4a9bdc59
BLAKE2b-256 checksum
How to use checksums
d47bca52e6326610bee91b196546c985ffe75b15c47069505cf2090e3843301b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for mstransfer 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mstransfer-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page