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.1

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

Built distributions (wheels)

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

Total release size: 60.6 MB

Release files / syq-0.10.1.tar.gz

Download URL syq-0.10.1.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
584f067521acb1ed145a5cb59e7899e4456bebea0c105b39d166b86a25b44a1c
BLAKE2b-256 checksum
How to use checksums
4df4d096a06b0f3a22cdd026b68832aff609b6387830153c17ea2652abe93f49
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.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL syq-0.10.1-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
d0631228fd39e195f59a5e1f58dc8772e66783d8f9d0363fc0a1cb2c7aac04f4
BLAKE2b-256 checksum
How to use checksums
830d343369493dc04df01442aa1ab03a1395ef1c8a7da97fa1d3daf8255e111a
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.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL syq-0.10.1-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
92e72111ec52ba3d91e876ce102fee20e6bb7d9fe65f6a93a3454885bce15d7d
BLAKE2b-256 checksum
How to use checksums
74971a70275487ec598b9261769d575c50d82b5fe74492b30179cd71a48a6d24
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.1-py3-none-macosx_11_0_arm64.whl

Download URL syq-0.10.1-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
a5195f914a3aa593aefcedfb1717c7c82d54709464e340aa8a0bb3b81c7a6f23
BLAKE2b-256 checksum
How to use checksums
0719a0bf48810c481b92bf0f523902e6ec468edb4044e141d0efc43bbd332e90
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.1-py3-none-macosx_10_12_x86_64.whl

Download URL syq-0.10.1-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
4c649b2976b4b9b9516658ced69952423c638bca6dd158d2e5fa554e5a1d4057
BLAKE2b-256 checksum
How to use checksums
54fcd7408ea5d2c90ae7a0a4e1e7a052539c429f1fdb64bf3ead7009ea3f687b
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.1

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