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 operations

The module functions syq.cp, syq.rm, syq.map, syq.find, syq.ls, syq.open_reader, and syq.open_writer use a default Client; create your own client to share settings across calls. AsyncClient takes the same arguments and returns the same types. Await its operations, except map, find, ls, open_reader, and open_writer, which return async context managers.

Client and executable selection

Client(*, executable=None, cache_dir=None, process_cwd=None, env=None, timeout=None) and AsyncClient(...) accept:

ArgumentMeaning
executablePath of another syq, or a name to find on PATH; default: the bundled syq
cache_dirDownload a verified syq into this cache directory instead of using the bundled one
process_cwdWorking directory of the syq process; default: inherited
envEnvironment of the syq process; default: inherited
timeoutTimeout for each operation, in seconds; default: none

client.version() and syq.version(executable=None) return the executable’s version. See Compatibility for how the executable is chosen.

Arguments and validation

Arguments use the CLI option names, with underscores for hyphens and a trailing underscore on Python keywords (from_, as_). Paths can be str, bytes, or os.PathLike, and a selector takes one path or an iterable of paths: src=["a", "b"] is the CLI’s --srcs a b.

Shared by cp, rm, and mapMeaning
*sources, srcSelect named objects
srcs_inSelect a directory’s contents
src_non_dir, src_dirSelect objects that must be non-directories or directories
cwdDirectory that relative source paths start from, on the source machine
rootLike cwd, but refuse any path that escapes it; selectors must be relative; cannot combine with cwd
follow, follow_srcFollow source symlinks; for cp, follow also follows destination symlinks
auth_from"auto", "ssh", "@NAME", or an SSH provider endpoint, as for --auth-from. For S3 cp and rm, "@NAME" asks that machine to authorize the operation
timeoutSeconds, or None for no timeout; omitted: the client’s timeout

Flags default to False and other optional arguments to None, except check, which defaults to True, and timeout, which defaults to the client’s timeout. Invalid combinations raise SyqInvocationError.

cp

cp(*sources, **options) → CpResult copies files. Choose one placement argument unless every destination is a callback. Besides the shared arguments, it accepts the following; Copy files, Remote copy details, and Object storage describe what they do.

OptionsValues / purpose
from_, toSSH endpoint or s3://BUCKET; omitted means local. With one of each, the server runs the copy and this machine signs its storage requests
into, into_new, into_existingDestination directory
as_, as_new, as_existingExact destination path
mappingMapping, MapStream, manifest path, or iterable of MappingEntry, instead of selectors; conflicts with as_*, prune, and prune_before. Async clients also accept AsyncMapping and async iterables
stream_concurrencyMost callback entries active at once; default 4, range 1..256
follow_dstFollow destination symlinks
prune, dry_run, hashMirror, preview, or compare contents
prune_beforeLike prune, but remove extras before copying, to free space; a later failure does not restore them
max_deleteRefuse all deletions if more than this many are planned; requires prune or prune_before
hash_or_copyLike hash, but compare only where blocks can be reused and copy other files whole; cannot combine with hash
integrity_checkingString such as "transfer=sha256"; default: size and time comparison, no extra checks
if_exists"error-if-different", "error", "keep", "update" (default), or "update-if-older"
where, copy_ifExpressions: where selects non-directory sources; copy_if decides which entries may be created or updated
ignorePattern, IgnoreFrom(path), or an ordered iterable of both
ignore_fromRule file path or paths; applied after ignore
copy_metadataString or iterable of --copy-metadata values (times is an alias for mtime); applies to unchanged files too
widen_dirs"none" (default), "rsync", or "all": which of your directories may briefly get the owner permission the copy needs, as --widen-dirs describes
open_noatimeRead without updating access times where possible; warns otherwise
sparseWrite zero ranges as sparse holes on filesystem destinations
in_place"new": write new files at their final names instead of under a temporary name, except a new file that must not replace anything (as_new, or under if_exists="error" or "error-if-different"). "update": also update existing files in place, as --in-place=update describes
no_compressDisable compression
transfer_strategy"whole-file", "aligned-block", or "locality" (default); filesystem copies only; see transfer strategies
performance_tuningOverrides such as "workers=4" or "s3-objects=4,s3-parts-per-object=8"; default: automatic
resource_limitsCeilings such as "bandwidth=10M,workers=4", below which tuning stays automatic; a concurrency key cannot also appear in performance_tuning
s3_endpoint, s3_region, s3_profileS3 endpoint URL, signing region, and AWS profile
s3_headerIterable of "NAME: VALUE" headers added before signing to every S3 request
s3_write_headerLike s3_header, but only on requests that create or replace objects
s3_directory_markers"all" (default), "empty", or "none": which directories get 0-byte dir/ markers on an S3 destination
s3_retriesRetries per S3 request after a temporary failure or throttling, 0 to 100; default 10
coordinate_at, rsh, peer_authAs --coordinate-at, --rsh, and --peer-auth
pscopeA persistence scope for connections and saved authorization choices
syq_path, no_bootstrapUse this remote syq, or the one on the remote PATH, instead of installing one
no_tcp_encryption, no_tcp, tcp_ports, tcp_congestionAs the CLI options of the same names
receiver_max_entries, receiver_max_bytesLimits for a restricted copy: an entry count, and a size string or byte count
on_event, results, checkSee events and failures

To copy between two SSH servers, cp uses restricted copying on the destination (the first copy sets it up, as in the CLI), approved account access to both servers, or coordinate_at="local". For --detach and human-readable output options, use run.

IgnoreFrom(path) names a rule file, so you can interleave files and patterns: ignore=[syq.IgnoreFrom("rules"), "!keep.tmp"]. The last matching rule wins.

rm

rm(*sources, **options) → RmResult removes the selected entries locally, on an SSH server (on="server"), or in S3 (on="s3://bucket"); see Remove files. Besides the shared arguments, it accepts on, dry_run, performance_tuning, syq_path, no_bootstrap, pscope, on_event, results, and check, as on cp. performance_tuning="workers=N" sets how many filesystem deletions run at once, and "s3-requests=N" does the same for S3.

Selectors follow the syq rm rules: positional sources and src refuse directories, src_dir removes a directory, and srcs_in empties it.

For S3, s3_endpoint, s3_region, s3_profile, s3_header, s3_retries, and auth_from="@NAME" work as on cp. In a versioned bucket, s3_all_versions=True permanently removes all versions and delete markers of the selected keys, and s3_version_id="ID" removes one version of one exact key; use at most one of them.

find and ls

find(*paths, **options) → FindStream lists files and directories locally, on an SSH server (on="server"), or in an S3 bucket (on="s3://bucket"); ls(*paths, **options) → FindStream defaults depth to 1. See syq find and syq ls for listing rules.

They accept on, cwd, root, follow, follow_src, depth, ignore, ignore_from, where, include, performance_tuning, rsh, syq_path, no_bootstrap, auth_from, pscope, s3_endpoint, s3_region, s3_profile, s3_header, s3_retries, and timeout. On S3, cwd and root name a key prefix; follow and follow_src apply only to filesystems.

Use a FindStream in a with block and an AsyncFindStream in async with. Iterating to the end checks that the listing succeeded and raises SyqProtocolError if the listing failed or was incomplete; leaving the block early stops the listing. Streams cannot be reused after closing or exhaustion.

Each item is a frozen FindEntry dataclass:

path: str
kind: str | None = None
size: int | None = None
mtime: int | None = None
s3_last_modified: int | None = None
etag: str | None = None
mode: int | None = None
uid: int | None = None
gid: int | None = None
ctime: int | None = None
link_target: str | None = None

By default, include is None: filesystem listings populate kind, size (omitted for directories), and mtime, and S3 listings populate kind, size, s3_last_modified, and etag from the listing alone. Pass include with field names (such as ["kind", "mode", "link_target"]) to select specific fields after path. On S3, requesting kind, mtime, mode, uid, or gid via include, or a where condition on fields the listing lacks, sends a per-object HEAD request; see List objects.

Paths must be valid UTF-8 strings, as must symlink targets when link_target is included; to handle non-UTF-8 byte names call run(["find", "--null", ...]), and for human-readable long output call run(["find", "--long", ...]).

run

client.run(args, *, check=True, cwd=None, env=None, timeout=CLIENT_DEFAULT, input=None) runs syq with any arguments and returns a Result with the captured output. Use it for commands without a typed method. args are the arguments after the executable name, passed without a shell; input is optional bytes for standard input.

Here cwd is the working directory of the syq process. cwd and env fall back to the client’s settings when omitted or None; timeout falls back only when omitted, and None disables it. Module-level syq.run also takes executable=None, and has no timeout by default.

To pass the client’s timeout through your own wrapper, give its parameter the default syq.CLIENT_DEFAULT. syq.Timeout is the type of a timeout: a number, None, or that sentinel:

def copy_data(client: syq.Client, *, timeout: syq.Timeout = syq.CLIENT_DEFAULT):
    return client.cp("data", into="backup", timeout=timeout)

A timeout covers only the syq process, not downloading a managed executable or reading a mapping iterable before syq starts.

For syq exec, cwd= sets only the local directory; put --cwd DIR in args for the receiving machine, as in the command example.

Result

Frozen dataclass returned by run() and held in SyqProcessError.result:

AttributeTypeMeaning
argvtuple[str | bytes, ...]Executed argument list, including the executable
returncodeintProcess exit status
stdoutbytesComplete captured standard output
stderrbytesComplete captured standard error

Compatibility

The package supports Python 3.10 and later on Linux and macOS, with no runtime Python dependencies. Each package version runs one syq release; syq.__version__ and syq.PINNED_SYQ_VERSION report them. Pin the package version in your dependencies to keep the same syq.

Bundled executable

By default the SDK runs the syq installed with its wheel, without searching PATH or downloading anything.

Managed executable

Client(cache_dir=DIR) instead downloads the matching syq on first use into DIR/syq/sdk/python/v<version>/<target>/, where <target> names the platform, such as linux-x86_64. It verifies the download against the release manifest in the package and checks it again before every use. DIR must belong to you or root. Other accounts may write it only if it is a sticky directory such as /tmp, except that your own private group may: your primary group, when it is named after you and has no other members. The SDK keeps the directories it creates in DIR private to you. It does not check macOS access control lists on them. syq.managed_executable(cache_dir=None) downloads ahead of time and returns the executable’s path. Without cache_dir, DIR is $XDG_CACHE_HOME when that is an absolute path, and ~/.cache otherwise.

Custom executable

Client(executable="/opt/bin/syq") runs that file, and Client(executable="syq") searches PATH. The SDK then skips its bundled and downloaded copies and their verification, so the executable’s compatibility and origin are up to you. If it cannot run, the call fails without falling back to another syq.