Skip to main content

Python

The syq package runs syq from Python. Copy, 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.13.4+ 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.

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.

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 with async with, without await before client.map():

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.10.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.10.0
File Size Uploaded Provenance Actions
syq-0.10.0.tar.gz 3.2 MB Without provenance Details for syq-0.10.0.tar.gz

Built distributions (wheels)

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

Total release size: 60.6 MB

Release files / syq-0.10.0.tar.gz

Download URL syq-0.10.0.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
ac030f5f1087edbd9ab3fbc8f61e6a22d9b058789de12920e588fe0907d784b3
BLAKE2b-256 checksum
How to use checksums
8858a3d822bc6300552f5883921b470d72e2db6c156784a3f695ae80061d1953
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.10.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL syq-0.10.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 14.2 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
ef0bebdbc10617f359557ba084d7a8f380dc3ed1af1ba1bc60818fcf6d1f2deb
BLAKE2b-256 checksum
How to use checksums
9c7ff20359923e5c0e3424fd75c48d9b9f410b31e1a33547695f94b33824caf0
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.10.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL syq-0.10.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 15.2 MB
Tags Linux glibc 2.5+ x86-64 Python 3
SHA-256 checksum
How to use checksums
ed114da5d88bfaeaa93d8c1042e772c2bcff9c08defee0c8fc25defc621df2e5
BLAKE2b-256 checksum
How to use checksums
479d15b100c31a606f86d98486fc67ae7d7a78089481f3da5719adb89bfc746e
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.10.0-py3-none-macosx_11_0_arm64.whl

Download URL syq-0.10.0-py3-none-macosx_11_0_arm64.whl
Size 12.5 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
012887cfb43cd6c1a04e02eb23e2a733877c9acbac76b8df23b2a036e3d7ba5d
BLAKE2b-256 checksum
How to use checksums
673d40b1a7d35db31cdd36f06739ccfd74feeda87a0836be114f0576225020b0
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.10.0-py3-none-macosx_10_12_x86_64.whl

Download URL syq-0.10.0-py3-none-macosx_10_12_x86_64.whl
Size 15.5 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a8caff62d5c96c25c5c0b958a98b50e26b11d3d0e121a3c24975a07e2157e15d
BLAKE2b-256 checksum
How to use checksums
57f059c520892ae72f63edb4c9a9bac6bb78492095944da0544986c14186a725
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.10.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