# Connect S3 clients

> Configure mc, rclone, Python boto3, DuckDB httpfs, and s3fs to talk to pgs3. Every client needs three settings: SigV4 signing, path-style addressing, and an explicit endpoint URL.

---

LLMS index: [llms.txt](/llms.txt)

---

Any S3 client that speaks **AWS Signature Version 4** and **path-style URLs** (`http://host:9000/bucket/key`) works against `pgs3`. Because `pgs3` does not implement virtual-host routing (`http://bucket.host:9000/key`), always disable virtual-host addressing in your client configuration.

All examples below reuse the shell variables from [Getting started](/docs/pgs3/getting-started/) (or your production HTTPS proxy URL and tenant credentials):

```bash
export PGS3_ENDPOINT=http://127.0.0.1:9000
export PGS3_ACCESS_KEY=PGS3DEMOACCESS01
export PGS3_SECRET_KEY='<your-secret-key>'
export PGS3_BUCKET=my-artifacts
```

## mc (MinIO Client) {#mc}

`mc` (packaged as `mcli` on some Linux distributions) is the fastest day-to-day CLI for buckets, objects, directory mirrors, version history, and presigned download links.

### Configure an alias

Pass `--api S3v4 --path on` so `mc` always signs with SigV4 and sends path-style requests:

```bash
mc alias set pgs3 "$PGS3_ENDPOINT" "$PGS3_ACCESS_KEY" "$PGS3_SECRET_KEY" --api S3v4 --path on
mc ls pgs3
```

### Everyday object operations

```bash
# Create a bucket and upload with Content-Type and custom metadata
mc mb "pgs3/$PGS3_BUCKET"
printf 'hello pgs3\n' > hello.txt
mc cp --attr "Content-Type=text/plain;owner=docs" hello.txt "pgs3/$PGS3_BUCKET/notes/hello.txt"

# Inspect metadata, read content, and list a prefix
mc stat "pgs3/$PGS3_BUCKET/notes/hello.txt"
mc cat  "pgs3/$PGS3_BUCKET/notes/hello.txt"
mc ls   "pgs3/$PGS3_BUCKET/notes/"

# Server-side copy (reuses the underlying SHA-256 blob without re-uploading)
mc cp "pgs3/$PGS3_BUCKET/notes/hello.txt" "pgs3/$PGS3_BUCKET/archive/hello.txt"

# Mirror a local directory into a dedicated prefix
mc mirror ./reports "pgs3/$PGS3_BUCKET/reports"
```

### Work with object versions

`pgs3` keeps versioning permanently enabled on every bucket:

```bash
# List every revision and delete marker for a key
mc ls --versions "pgs3/$PGS3_BUCKET/notes/hello.txt"

# Read or download a specific historical version
mc cat --version-id 1 "pgs3/$PGS3_BUCKET/notes/hello.txt"
mc cp  --version-id 1 "pgs3/$PGS3_BUCKET/notes/hello.txt" ./hello-v1.txt

# Ordinary delete (writes a delete marker; earlier versions remain intact)
mc rm "pgs3/$PGS3_BUCKET/notes/hello.txt"

# Permanent delete of a single version
mc rm --version-id 1 "pgs3/$PGS3_BUCKET/notes/hello.txt"
```

### Generate a temporary download URL

`mc share download` signs a presigned GET URL locally without calling any extra API:

```bash
mc share download --expire=10m "pgs3/$PGS3_BUCKET/archive/hello.txt"
```

> [!NOTE]
> MinIO-specific and unsupported S3 subcommands (`mc admin`, `mc anonymous`, `mc ilm`, `mc retention`, `mc tag`) are outside the `pgs3` API subset and return `501 NotImplemented`.

## rclone {#rclone}

`rclone` is part of the `pgs3` release acceptance matrix and works well for automated sync jobs, integrity verification, and large multipart transfers.

### Configuration file

Add a remote to `~/.config/rclone/rclone.conf`:

```ini
[pgs3]
type = s3
provider = Other
endpoint = http://127.0.0.1:9000
region = us-east-1
force_path_style = true
access_key_id = PGS3DEMOACCESS01
secret_access_key = <your-secret-key>
```

To avoid storing secrets in a config file, replace `access_key_id` and `secret_access_key` with `env_auth = true` and export `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`, or configure the remote purely with environment variables (`RCLONE_CONFIG_PGS3_TYPE=s3`, `RCLONE_CONFIG_PGS3_PROVIDER=Other`, `RCLONE_CONFIG_PGS3_ENDPOINT`, `RCLONE_CONFIG_PGS3_FORCE_PATH_STYLE=true`, `RCLONE_CONFIG_PGS3_REGION=us-east-1`, plus access/secret keys).

### Sync, verify, and restore

```bash
# Create a bucket (idempotent if you already own it)
rclone mkdir "pgs3:$PGS3_BUCKET"

# Mirror a local folder into a dedicated prefix
rclone sync ./reports "pgs3:$PGS3_BUCKET/reports" --checkers 4 --transfers 4

# Verify byte-for-byte integrity by downloading and comparing hashes
rclone check --download ./reports "pgs3:$PGS3_BUCKET/reports"

# Download back to a local directory
rclone copy "pgs3:$PGS3_BUCKET/reports" ./reports-restored
```

> [!WARNING]
> Only run `rclone sync` against a dedicated destination prefix. Any object under that destination prefix that does not exist in the local source directory receives a delete marker.

## Python (boto3) {#boto3}

Set `signature_version="s3v4"` and `addressing_style="path"` in `botocore.config.Config`. Large files automatically use multipart upload (every non-final part must be at least 5 MiB).

### Upload, conditional writes, and download

```python
import os
import boto3
from botocore.config import Config

s3 = boto3.client(
    "s3",
    endpoint_url=os.environ["PGS3_ENDPOINT"],
    aws_access_key_id=os.environ["PGS3_ACCESS_KEY"],
    aws_secret_access_key=os.environ["PGS3_SECRET_KEY"],
    region_name="us-east-1",
    config=Config(
        signature_version="s3v4",
        s3={"addressing_style": "path"},
        retries={"max_attempts": 3},
        request_checksum_calculation="when_supported",
        response_checksum_validation="when_supported",
    ),
)

bucket = os.environ["PGS3_BUCKET"]

# Create only if the key does not exist yet (returns 412 PreconditionFailed otherwise)
put_res = s3.put_object(
    Bucket=bucket,
    Key="python/config.json",
    Body=b'{"mode":"v1"}\n',
    ContentType="application/json",
    Metadata={"service": "worker"},
    IfNoneMatch="*",
)
etag = put_res["ETag"]

# Compare-and-swap update guarded by the current ETag
s3.put_object(
    Bucket=bucket,
    Key="python/config.json",
    Body=b'{"mode":"v2"}\n',
    ContentType="application/json",
    IfMatch=etag,
)

# Read back the latest revision
obj = s3.get_object(Bucket=bucket, Key="python/config.json")
assert obj["Body"].read() == b'{"mode":"v2"}\n'
```

### Presigned GET and PUT URLs

Presigned URLs delegate temporary read or write access to browsers or untrusted workers without sharing the tenant secret. They enforce the exact HTTP method, path, query string, expiry, and the underlying PostgreSQL role's RLS visibility.

```python
import urllib.request

put_url = s3.generate_presigned_url(
    "put_object",
    Params={"Bucket": bucket, "Key": "python/upload.txt"},
    ExpiresIn=300,
)
get_url = s3.generate_presigned_url(
    "get_object",
    Params={"Bucket": bucket, "Key": "python/upload.txt"},
    ExpiresIn=300,
)

req = urllib.request.Request(put_url, data=b"uploaded via presigned PUT\n", method="PUT")
with urllib.request.urlopen(req) as resp:
    assert resp.status == 200

with urllib.request.urlopen(get_url) as resp:
    assert resp.read() == b"uploaded via presigned PUT\n"
```

Always distribute presigned URLs over HTTPS through a TLS-terminating proxy in production.

## DuckDB (httpfs) {#duckdb}

DuckDB can query Parquet, CSV, or JSON files stored inside `pgs3` over range-capable HTTP GET requests.

1. Generate a Parquet file and upload it with `mc`:

   ```bash
   duckdb -c "COPY (SELECT i AS id, 'row-' || i AS label FROM range(100) t(i)) TO 'sample.parquet' (FORMAT PARQUET)"
   mc cp sample.parquet "pgs3/$PGS3_BUCKET/analytics/sample.parquet"
   ```

2. Query it directly from DuckDB (`ENDPOINT` expects `host:port` without a scheme; set `USE_SSL true` behind a TLS proxy):

   ```sql
   INSTALL httpfs;
   LOAD httpfs;

   CREATE SECRET pgs3_local (
       TYPE s3,
       KEY_ID 'PGS3DEMOACCESS01',
       SECRET '<your-secret-key>',
       REGION 'us-east-1',
       ENDPOINT '127.0.0.1:9000',
       URL_STYLE 'path',
       USE_SSL false
   );

   SELECT count(*), min(id), max(id)
   FROM read_parquet('s3://my-artifacts/analytics/sample.parquet');
   ```

   ```text
   ┌──────────────┬─────────┬─────────┐
   │ count_star() │ min(id) │ max(id) │
   │    int64     │  int64  │  int64  │
   ├──────────────┼─────────┼─────────┤
   │          100 │       0 │      99 │
   └──────────────┴─────────┴─────────┘
   ```
{.steps}

## s3fs (Linux FUSE mount) {#s3fs}

On Linux hosts with `/dev/fuse` and `fusermount3`, you can mount a `pgs3` bucket as a local directory for legacy tools that only read and write filesystem paths:

```bash
umask 077
printf '%s:%s\n' "$PGS3_ACCESS_KEY" "$PGS3_SECRET_KEY" > /tmp/pgs3.passwd
mkdir -p /tmp/pgs3-mnt

s3fs "$PGS3_BUCKET" /tmp/pgs3-mnt \
  -o passwd_file=/tmp/pgs3.passwd \
  -o "url=$PGS3_ENDPOINT" \
  -o use_path_request_style

ls -la /tmp/pgs3-mnt
fusermount3 -u /tmp/pgs3-mnt
rm -f /tmp/pgs3.passwd
```

`s3fs` translates renames and in-place edits into multiple S3 API calls and does not provide POSIX file locking or atomic directory moves. Do not place databases, Git repositories, or lock-sensitive workloads on an `s3fs` mount.

---

Backlinks:

- [Getting started](/docs/pgs3/getting-started/)
