Skip to main content

Python

The syq package runs syq from Python. Copy, list, remove, and reorganize files, and get typed results and events back, with a synchronous or asyncio client. The operations reference lists every argument.

Install

The syq package on PyPI supports Python 3.10+ on Linux and macOS:

python -m pip install syq

Prebuilt wheels include the matching syq executable, also available as the syq command in the Python environment.

On Linux, pip install --user syq puts the syq command in ~/.local/bin, the same place the standalone installer uses. If you use both for the same account, whichever you ran last replaces the other's command; a virtual environment avoids that.

Copy files

Copy a directory named data into backup, producing backup/data:

import syq

result = syq.cp("data", into="backup")
print(result.files_transferred, result.bytes_transferred)

To copy just its contents, use srcs_in:

result = syq.cp(srcs_in="data", into="backup")

Arguments use the command-line names, with underscores for hyphens and a trailing underscore on Python keywords such as from_ and as_. The copy guide explains the options.

Copy over SSH

Use to for an SSH destination and from_ for an SSH source:

syq.cp("data", to="user@server", into="/backup")
syq.cp("report.csv", from_="user@server", cwd="/exports", into="downloads")

Pass both from_ and to to copy between servers.

Preview changes

Pass dry_run=True to preview a copy or removal; the result counts the planned changes:

preview = syq.cp("data", into="backup", dry_run=True)
print(preview.files_transferred, preview.bytes_transferred)

Mirror a directory

prune=True also removes destination entries the source does not have. Here staging must already exist, and max_delete caps the deletions:

result = syq.cp(
    srcs_in="build",
    into_existing="staging",
    prune=True,
    max_delete=100,
)

Filter with expressions

where selects source files, and copy_if decides which files the copy may create or update:

syq.cp(srcs_in="project", into="backup",
       where='src.kind = "file" and src.size >= 1MiB',
       copy_if='not dst.exists or src.mtime > dst.mtime')

See Select entries with expressions for the fields and operators.

Remove files

result = syq.rm(src_dir="old-output", root="/srv/jobs")
print(result.entries_removed, result.selectors_missing)

Positional paths and src refuse directories; use src_dir to remove a tree or srcs_in to empty it. root keeps removal inside that directory. Pass on="server" or on="s3://bucket" to remove files elsewhere; see Remove files.

List files

Stream matching files and directories locally, on an SSH server, or in an S3 bucket:

with syq.ls("photos", on="s3://backups") as entries:
    for entry in entries:
        print(entry.path, entry.kind, entry.size)

with syq.find("src", where='extension = "rs" and size > 10KiB') as entries:
    paths = [entry.path for entry in entries]

See syq find and syq ls for options and the operations reference for FindEntry fields.

Handle failures

A failed copy or removal raises SyqOperationError with its typed result:

try:
    result = syq.cp("data", into="backup")
except syq.SyqOperationError as error:
    print(error.result.status, error.result.errors)
    print(error.stderr.decode(errors="replace"))

Pass check=False to get unsuccessful results back instead. Catch syq.SyqError for any SDK exception. Completed changes are not rolled back.

Watch events and save results

on_event receives records while the operation runs, for example each copied entry or planned change:

def observe(event: syq.AutomationEvent) -> None:
    if isinstance(event, (syq.TraceEvent, syq.OperationResult)):
        print(event.action, event.dst)

result = syq.cp("data", into="backup", on_event=observe)

Events are not kept in the result. To save them as NDJSON, pass a binary file:

with open("run.ndjson", "wb") as records:
    result = syq.cp("data", into="backup", results=records)

Rename while copying

Create a mapping, change its destination paths, then copy:

from dataclasses import replace

with syq.map(srcs_in="photos") as mapping:
    renamed = mapping.transform(
        lambda entry: replace(entry, dst=syq.RelativePath("archive") / entry.dst)
    )
    result = syq.cp(mapping=renamed, into="published")

This puts the contents of photos under published/archive. Return None from the transform to skip an entry. The mapping remembers where its sources are, so the same code works with map(from_="server") or map(from_="s3://bucket"). A failed transform copies nothing. See Rename and reorganize, or Pull and push DVC data for a complete program.

Generated data and binary streams

open_writer writes one file or object without a temporary file. For example, write an archive directly to S3:

import tarfile
import syq

with syq.open_writer(to="s3://backups", as_="dataset.tar") as output:
    with tarfile.open(fileobj=output, mode="w|") as archive:
        archive.add("dataset", arcname="dataset")

open_reader reads one local file, SSH file, or S3 object:

with syq.open_reader("dataset.tar", from_="s3://backups") as source:
    while chunk := source.read(65536):
        consume(chunk)

A writer publishes its file only when its with block exits without an exception. A reader checks that the transfer succeeded when its block exits, so if you extract files from a stream, use them only after both decoding and the reader's block finish successfully. See Byte streams.

To generate several files in one copy, put producers in a mapping:

from functools import partial

def pack(directory, output):
    with tarfile.open(fileobj=output, mode="w|") as archive:
        archive.add(directory, arcname=directory)

syq.cp(mapping=[syq.MappingEntry(syq.StreamSource(partial(pack, name)), f"{name}.tar")
                for name in ("images", "labels")],
       to="s3://backups", into="dataset", stream_concurrency=2)

StreamDestination(consumer) receives downloaded bytes the same way; see Callback mappings.

Use asyncio

AsyncClient takes the same arguments and returns the same results; await its operations:

import asyncio
import syq

async def main():
    client = syq.AsyncClient()
    result = await client.cp("data", into="backup")
    print(result.files_transferred)

asyncio.run(main())

Use mappings and listings with async with, without await before client.map(), client.find(), or client.ls():

async def copy_photos():
    client = syq.AsyncClient()
    async with client.map(srcs_in="photos") as mapping:
        return await client.cp(mapping=mapping, into="published")

Configure a client

Share a local working directory and timeout across calls:

client = syq.Client(process_cwd="/srv/jobs", timeout=3600)
result = client.cp("data", into="backup")

process_cwd sets the local working directory, while cwd sets the source base, which can be on a remote host. Pass timeout=None to disable the client's timeout for one call:

result = client.cp("data", into="backup", timeout=None)

Client(executable="/opt/bin/syq") runs another syq instead of the bundled one; see Compatibility.

Run other commands

run runs any syq command, such as rsync or receiver administration, and returns its captured output:

result = syq.run(["--help"])
print(result.stdout.decode())

To request a command on your receiving machine, use the syq executable you use for receiving:

import syq

result = syq.run(
    ["exec", "--on", "@laptop", "--cwd", "work/project", "--", "cargo", "test"],
    executable="/path/to/syq",
    timeout=600,
)
print(result.stdout.decode())

The receiving machine asks for approval first, and run raises if the command exits nonzero. See Run commands on your laptop.

Building from source

Installing from a source distribution builds the executable, which needs Rust and a C compiler. By default, a source build uploads its own executable to SSH servers, so they must be able to run it. See source builds.

Metadata

Release files for syq 0.11.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 syq 0.11.0
File Size Uploaded Provenance Actions
syq-0.11.0.tar.gz 3.6 MB Without provenance Details for syq-0.11.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for syq 0.11.0
File Actions
syq-0.11.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64, Linux musl 1.1+ ARM64 Details for syq-0.11.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl
syq-0.11.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.musllinux_1_1_x86_64.whl Python 3 none Linux musl 1.1+ x86-64, Linux glibc 2.5+ x86-64 Details for syq-0.11.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.musllinux_1_1_x86_64.whl
syq-0.11.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for syq-0.11.0-py3-none-macosx_11_0_arm64.whl
syq-0.11.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for syq-0.11.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 55.8 MB

Release files / syq-0.11.0.tar.gz

Download URL syq-0.11.0.tar.gz
Size 3.6 MB
Tags Source
SHA-256 checksum
How to use checksums
178de6fb237b7e2e858a5071d332ea6c8120c6f091bdce85a273dd743d3c5fd4
BLAKE2b-256 checksum
How to use checksums
88c21e918e717f9e5e7eb1883d9c27f01b265a3cdd3ba6962aeacd1392e7f5cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / syq-0.11.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl

Download URL syq-0.11.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl
Size 12.5 MB
Tags Linux glibc 2.17+ ARM64 Linux musl 1.1+ ARM64 Python 3
SHA-256 checksum
How to use checksums
9da6b88aa425b726c4d63c70d8f1c460561cc8664c39f05199860d7da7520b6b
BLAKE2b-256 checksum
How to use checksums
180bb95660033f6c4364672a50805bfb5640a44ec6e935502248efe8d54d0a4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / syq-0.11.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.musllinux_1_1_x86_64.whl

Download URL syq-0.11.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.musllinux_1_1_x86_64.whl
Size 13.3 MB
Tags Linux glibc 2.5+ x86-64 Linux musl 1.1+ x86-64 Python 3
SHA-256 checksum
How to use checksums
51855249a8422604cff2a597bbed14c49b37a70b620f38c2338bd8ba138a384e
BLAKE2b-256 checksum
How to use checksums
69e6a406bf71716cc52c080202c803af82573b503d7d8c33e720978ab6b54b0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / syq-0.11.0-py3-none-macosx_11_0_arm64.whl

Download URL syq-0.11.0-py3-none-macosx_11_0_arm64.whl
Size 11.0 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
038571aef72ba9290eefd8400ec2c59d41764db62739db49e5e573fb7b3828cb
BLAKE2b-256 checksum
How to use checksums
41315c6b9b945daa6e1cc377de39719bd18b98201e7234dbad5105b2d36e887e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / syq-0.11.0-py3-none-macosx_10_12_x86_64.whl

Download URL syq-0.11.0-py3-none-macosx_10_12_x86_64.whl
Size 15.3 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
3938a608f4feb82af2013c403f4fcaeb27871c1a7e6802a1f82754c6cdbfc79b
BLAKE2b-256 checksum
How to use checksums
f3ad8819869daa151cea5eff45b5ced23eadd689403b9f94e416ecad376ea4ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for syq 0.11.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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