Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Python results and events

Typed operations return results and can deliver events as work progresses. Use this reference to interpret those objects and handle failures. See the operations reference for calling conventions, or streams and mappings for their completion rules.

Operation results

cp and rm return a frozen dataclass once syq has exited and its results stream has been checked; a stream cut short raises even if syq exits successfully. A dry run returns the same type with planned totals, and a failed call counts the work done before it stopped.

CpResult

Returned by cp(), and available as SyqOperationError.result after an unsuccessful copy. Besides the common result fields below, it has:

AttributeTypeMeaning
files_transferredintRegular files transferred
files_unchangedintRegular files skipped as unchanged
files_excludedintSource entries excluded from copying, including ignore matches; an ignored directory counts once
directories_createdintDirectories created
symlinks_createdintSymbolic links created
specials_createdintSpecial filesystem objects created
bytes_transferredintFile-content bytes transferred, not compressed network traffic
bytes_total_knownbool | NoneFor byte streams, whether the source length is known; otherwise None
bytes_unchangedintBytes not copied because the destination already had them: unchanged files and data reused inside transferred files
deletions_plannedint or NoneEntries selected for pruning; None without prune or prune_before
deletions_completedint or NoneEntries pruned; None without pruning
deletions_blockedint or NoneDeletions blocked by a safety limit; None without pruning
replaced_not_in_placedict[str, int] or NoneWith in_place="update", existing files replaced instead of updated in place, by reason

RmResult

Returned by rm(), and available as SyqOperationError.result after an unsuccessful removal. Besides the common result fields below, it has:

AttributeTypeMeaning
selectors_totalintExplicit source selectors supplied
selectors_resolvedintSelectors that resolved to an object
selectors_missingintSelectors already missing; this is not an error
entries_plannedintEntries a dry run would remove; zero in live runs
entries_removedintEntries removed; zero in dry runs
entries_already_absentintEntries gone by removal time; zero in dry runs
entries_failedintRemoval or inspection failures, including during dry runs
modestrAlways "rm"

A selector is one path you asked to remove, and an entry is one object that removal visits, so a directory selector can account for many entries.

Common result fields

Both CpResult and RmResult include:

AttributeTypeMeaning
statusOperationStatusOutcome from the table below
exit_codeintsyq process exit code
dry_runboolWhether this was a preview
errorsintCounted errors
timingsTimingsTime spent in each phase, in milliseconds
protocolProtocolMetadataAutomation envelope; also present on every event

Timings

To see where a run spent its time, read result.timings, or event.timings on progress events. Values are wall-clock milliseconds. They overlap, so do not add them together. None means syq does not measure that phase for this operation; zero means there was no such work, or it took under a millisecond. See measurement boundaries.

AttributeTypeMeaning
total_msintThe whole measured run, including installing syq on servers
setup_msint | NonePreparing and connecting to the source and destination, excluding installation
planning_msint | NoneFinding source entries, checking destinations, and deciding what to copy
transfer_msint | NoneFrom the first file operation to the last
finalization_msint | NoneWork after file copying ends, such as pruning and directory metadata
helper_install_msint | NoneInstalling syq on servers

ProtocolMetadata

Frozen dataclass at result.protocol and event.protocol. The SDK checks these fields; you need them only to record or diagnose a results stream.

AttributeTypeMeaning
schemastr"syq.automation"
schema_versionint4; callback mappings use 5
seqintRecord sequence number, starting at zero
typestrRecord type; "result" for the final totals

OperationStatus

String enum: compare with syq.OperationStatus.SUCCESS, or use .value for "success".

MemberValueExit codeMeaning
SUCCESS"success"0Requested operation succeeded
PARTIAL"partial"23Some entries failed; the rest of the work finished
REFUSED"refused"25A safety limit such as max_delete refused the deletions; cp only
ABORTED"aborted"1The copy stopped partway, for example when the destination filled up; cp only
FAILED"failed"1Fatal failure

Event callbacks

on_event receives each event in the order syq reports it; events are not kept in the result. With AsyncClient, the callback can be async, and awaiting it counts toward the timeout.

An event is one of the event types below, a final CpResult or RmResult, or a MappingStreamResult from callback mappings. Each is a frozen dataclass with protocol: ProtocolMetadata. Fields match the automation results records, except that class is class_ and paths are PathValue; optional fields are None when absent.

results= saves the checked records as NDJSON to a binary file-like object, whose write(bytes) must return a positive count for nonempty data, and leaves it open. If checking the stream, the process, or a callback fails, the final record is left out, so the saved stream shows an incomplete run. If writing fails, the operation is aborted and the error raised.

To retry a failed mapping entry, call retry_entry() on an OperationResult whose is_retryable is true. It returns a MappingEntry with the same expected_hash and metadata, or None if the event does not identify the whole entry. Use these entries only once the call has returned success or partial; the client never retries by itself.

Event types

Each event type lists its protocol.type and its fields besides protocol.

RunEvent

Sent first. started_at is Unix seconds, mode is "cp" or "rm", and prune and mapping are None for removal.

protocol.type = "run":

run_id: str
started_at: int
syq_version: str
mode: str
prune: bool | None
mapping: bool | None
dry_run: bool
endpoints: tuple[Endpoint, ...]

ProgressEvent

Periodic progress for displays; use the final result for totals. activity holds diagnostic measurements when syq collects them.

protocol.type = "progress":

bytes_done: int
bytes_total: int
bytes_unchanged: int
files_done: int
files_total: int
files_unchanged: int
files_excluded: int
scanned: int
scan_done: bool
timings: Timings
activity: dict[str, Any] | None
rate_bytes_per_second: int | None
eta_ms: int | None

TraceEvent

One change a dry run would make, and the reason for it. dst is relative to the destination directory, and src is the mapping source when available.

protocol.type = "trace":

action: OperationAction
dst: PathValue
src: PathValue | None
kind: EntryKind
bytes: int | None
reason: TraceReason

OperationResult

The outcome of one copy change. src is present for mapping entries when available, and error fields when known. Outcomes reported by a restricted receiver have no src, attempts, or retryable.

protocol.type = "operation_result":

action: OperationAction
dst: PathValue
src: PathValue | None
kind: EntryKind | None
disposition: Disposition
bytes: int | None
attempts: int | None
retryable: Retryability | None
class_: ErrorClass | None
os_kind: OsKind | None
message: str | None
expected_hash: Hash | None
metadata: DestinationMetadata | None

SelectionResult

One removal selector, indexed from zero, and whether it resolved.

protocol.type = "selection_result":

selector: int
path: PathValue
status: SelectionStatus
kind: EntryKind | None

RemovalTrace

One entry a dry run would remove, under the selector it came from.

protocol.type = "removal_trace":

selector: int
path: PathValue
kind: EntryKind
disposition: RemovalDisposition
s3_version_id: str | None
s3_delete_marker: bool | None

RemovalResult

One removal outcome, or a dry run’s failure to inspect an entry.

protocol.type = "removal_result":

selector: int
path: PathValue
kind: EntryKind | None
disposition: RemovalDisposition
attempts: int
retryable: Retryability | None
class_: ErrorClass | None
os_kind: OsKind | None
message: str | None
s3_version_id: str | None
s3_delete_marker: bool | None

ErrorEvent

One error. It counts toward the result’s errors unless it has diagnostic_for: then it explains why a restricted receiver reported that destination path as failed, and the receiver’s own error counts the failure.

protocol.type = "error":

message: str
class_: ErrorClass | None
os_kind: OsKind | None
diagnostic_for: PathValue | None

Endpoint

A nested frozen dataclass used by run events:

TypeFieldsMeaning
Endpointrole: EndpointRole, kind: EndpointKind, host: str | None, user: str | NoneSource/destination and local/SSH/S3 identity; host and user are optional

Enums

All enums are string enums exported by syq. Members use uppercase names and values lowercase, for example EntryKind.FILE.value == "file". OperationStatus is described with the results above.

TypeMembers
EntryKindFILE, DIR, SYMLINK, SPECIAL
EndpointKindLOCAL, SSH, S3
EndpointRoleSOURCE, DESTINATION
OperationActionTRANSFER_FILE, CREATE_DIRECTORY, CREATE_SYMLINK, CREATE_SPECIAL, DELETE
DispositionSUCCEEDED, FAILED, BLOCKED
RetryabilityYES, NO, UNKNOWN
ErrorClassIO, TRANSPORT, CONFLICT, INTEGRITY, SAFETY_LIMIT, USAGE, INTERNAL
OsKindNOT_FOUND, PERMISSION_DENIED, ALREADY_EXISTS, INVALID_INPUT, NO_SPACE, QUOTA_EXCEEDED, READ_ONLY, OTHER
TraceReasonDESTINATION_MISSING, TYPE_DIFFERS, CONTENT_DIFFERS, METADATA_DIFFERS, DESTINATION_ONLY
SelectionStatusRESOLVED, MISSING
RemovalDispositionWOULD_REMOVE, REMOVED, ALREADY_ABSENT, FAILED

Failure model

Catch SyqError for every exception the SDK defines, or a subclass to tell an unsuccessful operation from a broken results stream:

ExceptionMeaning / useful attributes
SyqInstallErrorBundled executable is missing, or a managed download or its verification failed
SyqInvocationErrorInvalid Python arguments
SyqOperationErrorTyped operation was unsuccessful; .result and .stderr (last 8 KiB)
SyqProtocolErrorResults stream was invalid, unsupported, inconsistent, or incomplete; .returncode, .stderr
SyqProcessErrorRaw run exited nonzero; .result contains complete output
SyqOutputErrorA function such as version() got output it could not parse

check=False makes cp and rm return an unsuccessful result instead of raising, and run return a nonzero exit; it suppresses nothing else. Failures to start syq, timeouts (subprocess.TimeoutExpired), and ordinary type and value errors are standard Python exceptions, not SyqError. Exceptions from your callbacks and mapping iterators propagate unchanged, and async cancellation stays asyncio.CancelledError.

A timeout, cancellation, early exit from a mapping, or stream failure stops syq and every process it started locally, including SSH. Completed changes are not rolled back.