Skip to main content

S3 git filter for Peagen using s3fs

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_gitfilter_s3fs


Swarmauri Git Filter S3FS

Git filter implementation for Peagen that streams artifacts to Amazon S3 (or S3-compatible services) through s3fs. The filter registers as a StorageAdapter named S3FSFilter and supports the full git clean/smudge cycle by delegating reads and writes to the configured S3 bucket.

Features

  • Implements :class:~swarmauri_base.storage.StorageAdapterBase and :class:~swarmauri_base.git_filters.GitFilterBase to provide streaming upload and download operations.
  • Recursively uploads local directories via upload_dir and reconstructs prefixes back onto disk with download_prefix.
  • Lists existing objects under a prefix with iter_prefix to back git history reconstruction.
  • Reads configuration from peagen.toml ([storage.filters.s3fs]) or the AWS_* environment variables when instantiated through :meth:S3FSFilter.from_uri.

Installation

Install the package with your preferred Python packaging tool:

pip install swarmauri_gitfilter_s3fs
poetry add swarmauri_gitfilter_s3fs
uv pip install swarmauri_gitfilter_s3fs

Configuration

Create the filter by supplying your bucket name and optional connection parameters:

  • bucket – Target bucket name (required).
  • prefix – Optional key prefix to scope uploads.
  • key / secret – Credentials for the S3 endpoint. SecretStr instances are supported.
  • endpoint_url – Custom S3-compatible endpoint (useful for MinIO or LocalStack).
  • region_name – Region for the endpoint.

When using :meth:S3FSFilter.from_uri, the URI sets the bucket and prefix while credentials are loaded from peagen.toml at [storage.filters.s3fs] (key, secret, endpoint_url, and region). Missing configuration falls back to AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ENDPOINT_URL, and AWS_REGION respectively.

Usage

The example below patches s3fs with an in-memory stub so it can run without network access. The logic mirrors how S3FSFilter writes data to S3 and returns the URI of the uploaded object.

from contextlib import nullcontext
from io import BytesIO
from unittest.mock import MagicMock, patch

from swarmauri_gitfilter_s3fs import S3FSFilter

with patch("swarmauri_gitfilter_s3fs.s3fs_filter.s3fs.S3FileSystem") as fs_cls:
    fake_fs = MagicMock()
    buffer = BytesIO()
    fake_fs.open.return_value = nullcontext(buffer)
    fs_cls.return_value = fake_fs

    filt = S3FSFilter.from_uri("s3://demo-bucket/models")
    location = filt.upload("artifacts/model.bin", BytesIO(b"model-weights"))

    assert location == "s3://demo-bucket/models/artifacts/model.bin"
    fake_fs.open.assert_called_with(
        "demo-bucket/models/artifacts/model.bin",
        "wb",
    )
    assert buffer.getvalue() == b"model-weights"

In a production workflow you do not need to patch s3fs – instantiate the filter with your credentials and bucket, then use clean/smudge or upload/download to move artifacts between git and S3.

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

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

swarmauri_gitfilter_s3fs-0.3.0.dev44.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file swarmauri_gitfilter_s3fs-0.3.0.dev44.tar.gz.

File metadata

  • Download URL: swarmauri_gitfilter_s3fs-0.3.0.dev44.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_gitfilter_s3fs-0.3.0.dev44.tar.gz
Algorithm Hash digest
SHA256 17ade9a92f79fa7d9ba3e187919925b42bfce509f0775bff90f7e4e84e2a69d0
MD5 67b3a811ae81e08c0804b3bbb5bbee4f
BLAKE2b-256 db6086314fc17457229604680dab2b4297ea17906655eee11134a9a4c6519507

See more details on using hashes here.

File details

Details for the file swarmauri_gitfilter_s3fs-0.3.0.dev44-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_gitfilter_s3fs-0.3.0.dev44-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_gitfilter_s3fs-0.3.0.dev44-py3-none-any.whl
Algorithm Hash digest
SHA256 0dec28084aae779a9e460df037e4894d22be11772dab7e9fc34dc9177b6978b2
MD5 7085c92675aab0ba438a5e34e75500ad
BLAKE2b-256 3e3c15af07e3b6e4a53e2a3a5e9e6a66ba8e7742f6fcae2ae2ccf3c9ffd31490

See more details on using hashes here.

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