Server¶
App factory¶
create_app
¶
create_app(
output_dir: str = "./received",
store_as: StoreFormat = "msz",
auth: AuthProvider | Callable[..., Any] | None = None,
file_provider: FileProvider | None = None,
*,
upload_auth: AuthProvider
| Callable[..., Any]
| None = None,
download_auth: AuthProvider
| Callable[..., Any]
| None = None,
) -> FastAPI
Create a configured mstransfer FastAPI application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory where received files are stored. |
'./received'
|
store_as
|
StoreFormat
|
Output format — "msz" or "mzml". |
'msz'
|
auth
|
AuthProvider | Callable[..., Any] | None
|
Authentication provider, raw FastAPI dependency, or None (no auth). Protects both uploads and downloads. Can't be combined with upload_auth or download_auth. |
None
|
file_provider
|
FileProvider | None
|
File discovery provider, or None to default to scanning output_dir on disk. |
None
|
upload_auth
|
AuthProvider | Callable[..., Any] | None
|
Like auth, but only for |
None
|
download_auth
|
AuthProvider | Callable[..., Any] | None
|
Like auth, but only for |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If auth is combined with upload_auth or download_auth, or any of them has an unsupported type. |
Router¶
make_router
¶
make_router(
auth_dep: Callable[..., Any] | None = None,
state: AppState | None = None,
*,
upload_auth_dep: Callable[..., Any] | None = None,
download_auth_dep: Callable[..., Any] | None = None,
) -> APIRouter
Create the API router, optionally protecting routes with auth dependencies.
Routes are split into two groups that can be protected separately:
- upload:
POST /uploadandGET /transfer/{transfer_id}/status - download:
GET /filesandGET /files/{filename}
GET /health is never protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth_dep
|
Callable[..., Any] | None
|
Optional FastAPI dependency applied to both groups. Can't be combined with upload_auth_dep or download_auth_dep. |
None
|
state
|
AppState | None
|
Optional |
None
|
upload_auth_dep
|
Callable[..., Any] | None
|
Optional dependency for the upload group only. |
None
|
download_auth_dep
|
Callable[..., Any] | None
|
Optional dependency for the download group only. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If auth_dep is combined with upload_auth_dep or download_auth_dep. |
Authentication¶
auth
¶
Extensible authentication for mstransfer.
AuthContext
¶
Bases: BaseModel
Identity returned by an auth provider.
AuthProvider
¶
Bases: Protocol
Contract that auth providers must satisfy.
NoAuthProvider
¶
Default no-op provider — allows all requests.
APIKeyAuthProvider
¶
Validates Authorization: Bearer <key> or ?api_key= query param.
make_auth_dependency
¶
make_auth_dependency(
provider: AuthProvider,
) -> Callable[[Request], Awaitable[AuthContext]]
Convert an AuthProvider into a FastAPI dependency callable.
File providers¶
fileprovider
¶
Extensible file discovery for mstransfer.
FileProvider
¶
Bases: Protocol
Contract that file providers must satisfy.
Implementations may return FileInfo subclasses from
list_files; the return type is Sequence
so that subclass lists are accepted without type errors.
get_file returns the file to serve for filename, or None for a
404. A Path is served under its own name. When the file is
stored under a different name (e.g. a content-addressed blob with no
extension), return a ServedFile instead: its path is streamed and
its name is used for Content-Disposition and the media type.
DirectoryFileProvider
¶
Default provider — scans a directory for .msz/.mszx/.mzML files.
State¶
state
¶
AppState
¶
AppState(
output_dir: Path,
store_as: StoreFormat,
files: FileProvider,
)
Bases: State
Application state object to hold configuration and transfer registry.
OutputClaims
¶
Output paths that in-flight uploads are writing.
Lets an upload refuse a destination another transfer already holds, so two uploads never write to the same file. Paths compare case-insensitively, as macOS and Windows filesystems do.
TransferRegistry
¶
In-memory LRU registry of transfer records.
When the number of records exceeds maxsize, the least-recently-used terminal (DONE / ERROR) record is evicted. In-progress transfers are never evicted; the registry may temporarily exceed maxsize if all records are active.