Skip to main content

Remote-backed workspace sync for Temporal activities

Project description

Workspace Sync for Temporal Activities

Sync a local directory with remote storage before and after a Temporal activity. Enables file-based activities to work across distributed workers where disk is not shared.

Problem

Temporal activities that read/write files on local disk break when you scale to multiple worker instances. Each worker has its own disk. This module syncs a remote storage location to a local temp directory before the activity runs, and pushes changes back after.

Install

pip install temporal-workdir

# With a specific cloud backend:
pip install temporal-workdir gcsfs    # Google Cloud Storage
pip install temporal-workdir s3fs     # Amazon S3
pip install temporal-workdir adlfs    # Azure Blob Storage

Usage

As a context manager (generic, works anywhere)

from temporal_workdir import Workspace

async with Workspace("gs://my-bucket/pipeline/component-x") as ws:
    # ws.path is a local Path — read and write files normally
    data = json.loads((ws.path / "component.json").read_text())
    (ws.path / "result.csv").write_text("col1,col2\nval1,val2")
    # On clean exit: local dir is archived and uploaded
    # On exception: no upload (remote state unchanged)

As a Temporal activity decorator

from temporalio import activity
from temporal_workdir import workspace, get_workspace_path

@workspace("gs://my-bucket/{workflow_id}/{activity_type}")
@activity.defn
async def extract(input: ExtractInput) -> ExtractOutput:
    ws = get_workspace_path()
    # Template vars resolved from activity.info()
    source = (ws / "source.json").read_text()
    (ws / "output.csv").write_text(process(source))
    return ExtractOutput(success=True)

Custom template variables

@workspace(
    "gs://my-bucket/{workflow_id}/components/{component}",
    key_fn=lambda input: {"component": input.component_name},
)
@activity.defn
async def register(input: RegisterInput) -> RegisterOutput:
    ws = get_workspace_path()
    ...

How It Works

  1. Pull: On entry, downloads {remote_url}.tar.gz and unpacks to a temp directory
  2. Execute: Your activity reads/writes files in the local directory
  3. Push: On clean exit, packs the directory into tar.gz and uploads

If the archive doesn't exist yet (first run), the local directory starts empty. If the activity raises an exception, no push happens. Remote state is untouched.

Storage Backends

Any backend supported by fsspec:

Scheme Backend Extra package
gs:// Google Cloud Storage gcsfs
s3:// Amazon S3 s3fs
az:// Azure Blob Storage adlfs
file:// Local filesystem (none)
memory:// In-memory (testing) (none)

Pass backend-specific options as keyword arguments:

Workspace("gs://bucket/key", project="my-gcp-project", token="cloud")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

temporal_workdir-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

temporal_workdir-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file temporal_workdir-0.1.0.tar.gz.

File metadata

  • Download URL: temporal_workdir-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for temporal_workdir-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6de3c627e685ff6d575780cab8e945ca633f74b7bf5efcb3a2d24c1d4be4abe9
MD5 6600d43887836f8a364e9f9ad2e39ae3
BLAKE2b-256 77c5ea1e5a6fe4a08a322f17e3fa77d43a78da9d755fb7d9a391279cb300eb8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for temporal_workdir-0.1.0.tar.gz:

Publisher: release.yml on saeedseyfi/temporal-workdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file temporal_workdir-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for temporal_workdir-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d8e1ab5f2c38cf95d43231e3348ffe3d2c8bb274d53f3d7ff73bd329e519b61
MD5 c71b55f61a220b1f46e87e254e92a4b2
BLAKE2b-256 d3acbb724740af66a1c5c4b5bd6f71eb49a0d9dc3919ccced964955783673493

See more details on using hashes here.

Provenance

The following attestation bundles were made for temporal_workdir-0.1.0-py3-none-any.whl:

Publisher: release.yml on saeedseyfi/temporal-workdir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page