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.9.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.9.0
File Size Uploaded Provenance Actions
syq-0.9.0.tar.gz 3.1 MB Without provenance Details for syq-0.9.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for syq 0.9.0
File Actions
syq-0.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for syq-0.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
syq-0.9.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.9.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
syq-0.9.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for syq-0.9.0-py3-none-macosx_11_0_arm64.whl
syq-0.9.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for syq-0.9.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 60.2 MB

Release files / syq-0.9.0.tar.gz

Download URL syq-0.9.0.tar.gz
Size 3.1 MB
Tags Source
SHA-256 checksum
How to use checksums
641faf555f16531d6018600b49fb5d74bc5d3b8ac0f2a82ea5d98818f877292c
BLAKE2b-256 checksum
How to use checksums
ba54875017fb019495e5a1e2eea2b4bd23ff5474af81b08652b5bbe7bccba77a
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.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL syq-0.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 14.1 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
6df86a0f77511f78a8aaee8d694736260d1ab7062c5b910faa25e81a62cf88b7
BLAKE2b-256 checksum
How to use checksums
8b81c60ce4107d391b2ef6aab53ad2e36a86598920cbda3d51f884d11b5508bd
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.9.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL syq-0.9.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
23c1ed98a3305ae01536c59aa3f12113f50368c703a742e40ae95ea829febab7
BLAKE2b-256 checksum
How to use checksums
c9fde94e427d0f9f2806fd5cc311cb09300c41976cd8e578b43f14a7c143e4d3
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.9.0-py3-none-macosx_11_0_arm64.whl

Download URL syq-0.9.0-py3-none-macosx_11_0_arm64.whl
Size 12.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ecb8d9c2b44cb6469d0a6167644f3cd0338e265055f657753aaa012b80821bfd
BLAKE2b-256 checksum
How to use checksums
25d9e26358329d5c6ecdd4c99af2478f6f655faaebd014d086c787c20c2a795b
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.9.0-py3-none-macosx_10_12_x86_64.whl

Download URL syq-0.9.0-py3-none-macosx_10_12_x86_64.whl
Size 15.4 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2e37490bc16060a809da9d824be4af7a4026f49fec9aff6f1618231ba44610b1
BLAKE2b-256 checksum
How to use checksums
e78ac3663e8956df63c288dac56a35a2c9f4e2990b1c987623c3493ce8867a16
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.9.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