> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archil.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Files and objects

> Read, write, list, and share files on a disk by key, without mounting it.

A disk is also an S3-compatible bucket. From the SDKs you can read, write, list, and delete its files by key, and
create links that let anyone download a file. These calls authenticate with your API key. To use an S3 client or the AWS CLI instead, create [S3 credentials](https://docs.archil.com/disks/access.md#s3-credentials) and see the
[S3-compatible API](https://docs.archil.com/protocols/s3-api.md).

A key is the file's path on the disk, without a leading slash: `reports/2026-01/data.json` is the file
`/mnt/archil/reports/2026-01/data.json` when the disk is mounted at `/mnt/archil`.

## Read and write files

```typescript TypeScript theme={null}
import * as archil from "disk";

const disk = await archil.getDisk("dsk-abc123");

// Write a string, Uint8Array, or ArrayBuffer. The content type is optional.
await disk.putObject("reports/2026-01/data.json", JSON.stringify({ rows: 1234 }), "application/json");

// Read the bytes back.
const bytes = await disk.getObject("reports/2026-01/data.json");
const text = new TextDecoder().decode(bytes);

// Check for a file without downloading it. headObject returns null when it's missing.
const meta = await disk.headObject("reports/2026-01/data.json");
const exists = await disk.objectExists("reports/2026-01/data.json");

// Delete a file. Deleting a missing key succeeds.
await disk.deleteObject("reports/2026-01/data.json");
```

```python Python theme={null}
import json
import archil

disk = archil.get_disk("dsk-abc123")

# Write a str or bytes. The content type is optional.
disk.put_object("reports/2026-01/data.json", json.dumps({"rows": 1234}), "application/json")

# Read the bytes back.
data = disk.get_object("reports/2026-01/data.json")
text = data.decode("utf-8")

# Check for a file without downloading it. head_object returns None when it's missing.
meta = disk.head_object("reports/2026-01/data.json")
exists = disk.object_exists("reports/2026-01/data.json")

# Delete a file. Deleting a missing key succeeds.
disk.delete_object("reports/2026-01/data.json")
```

Reading a missing key raises an `ArchilS3Error` with status 404 and code `NoSuchKey`.

## Large files

One call handles any size. Files larger than the multipart threshold (16 MiB by default) are uploaded in parts, in
parallel, and assembled on the disk. Tune the upload with these options:

```typescript TypeScript theme={null}
await disk.putObject("backups/2026-01.tar", bigBuffer, {
  contentType: "application/x-tar",
  multipartThreshold: 5 * 1024 * 1024, // upload in parts above 5 MiB
  partSize: 32 * 1024 * 1024,          // at least 5 MiB; default 16 MiB
  concurrency: 8,                      // parts in flight; default 4
});
```

```python Python theme={null}
disk.put_object(
    "backups/2026-01.tar",
    big_bytes,
    content_type="application/x-tar",
    multipart_threshold=5 * 1024 * 1024,  # upload in parts above 5 MiB
    part_size=32 * 1024 * 1024,           # at least 5 MiB; default 16 MiB
    concurrency=8,                        # parts in flight; default 4
)
```

To run the multipart steps yourself, for example to upload parts from separate processes, use `disk.multipart`:
`create`, `uploadPart`, `complete`, `abort`, `listParts`, and `listUploads` (snake\_case in Python).

## Append to a file

`appendObject` adds bytes to the end of a file, creating it if it doesn't exist. Each call appends up to 1 MiB.

```typescript TypeScript theme={null}
await disk.appendObject("logs/app.log", "first line\n");
await disk.appendObject("logs/app.log", "second line\n");
```

```python Python theme={null}
disk.append_object("logs/app.log", "first line\n")
disk.append_object("logs/app.log", "second line\n")
```

## Ownership and directories

Files written through the object API are owned by `root:root` with mode `0644` unless you set `uid`, `gid`, and
`mode`. Set them when a non-root process will use the files:

```typescript TypeScript theme={null}
await disk.putObject("app/data/config.json", "{}", { uid: 1000, gid: 1000, mode: 0o640 });

// A key ending in "/" creates a directory.
await disk.putObject("app/cache/", "", { uid: 1000, gid: 1000, mode: 0o750 });
```

```python Python theme={null}
disk.put_object("app/data/config.json", "{}", uid=1000, gid=1000, mode=0o640)

# A key ending in "/" creates a directory.
disk.put_object("app/cache/", b"", uid=1000, gid=1000, mode=0o750)
```

Missing parent directories are created with the same `uid` and `gid` and mode `0755`. Existing directories keep their
owner and mode. To set the owner of the disk's root directory, pass `rootAttrs` (`root_attrs` in Python) when you
create the disk.

## List files

`listObjects` returns every key under a prefix. By default it lists one level, like a directory listing: files in
`objects` and subdirectories in `commonPrefixes`. Pass `recursive` to list the whole subtree.

```typescript TypeScript theme={null}
const level = await disk.listObjects("reports/");
const everything = await disk.listObjects("reports/", { recursive: true });
const first100 = await disk.listObjects("reports/", { limit: 100 });

// Stream large listings a page at a time.
for await (const page of disk.listObjectsPages("reports/", { recursive: true })) {
  for (const obj of page.objects) console.log(obj.key, obj.size);
}
```

```python Python theme={null}
level = disk.list_objects("reports/")
everything = disk.list_objects("reports/", recursive=True)
first_100 = disk.list_objects("reports/", limit=100)

# Stream large listings a page at a time.
for page in disk.list_objects_pages("reports/", recursive=True):
    for obj in page.objects:
        print(obj.key, obj.size)
```

## Delete many files

`deleteObjects` deletes a list of keys in batches of 1,000 and reports failures per key instead of throwing.

```typescript TypeScript theme={null}
const { errors } = await disk.deleteObjects(["a.txt", "logs/b.txt", "c.txt"]);
for (const e of errors) console.log(e.key, e.code, e.message);
```

```python Python theme={null}
result = disk.delete_objects(["a.txt", "logs/b.txt", "c.txt"])
for e in result.errors:
    print(e.key, e.code, e.message)
```

## Share a file

`share` creates a signed link that lets anyone download one file, with no API key. It returns the `url` and its
lifetime in seconds, `expiresIn`. Links last 24 hours by default and up to 7 days.

```typescript TypeScript theme={null}
const { url, expiresIn } = await disk.share("reports/2026-01/summary.pdf");
console.log(expiresIn); // 86400
const weekLink = await disk.share("reports/2026-01/summary.pdf", { expiresIn: 604800 });
```

```python Python theme={null}
link = disk.share("reports/2026-01/summary.pdf")
print(link.url, link.expires_in)  # expires_in: 86400
week_link = disk.share("reports/2026-01/summary.pdf", expires_in=604800)
```

The link serves the file with its content type and supports HTTP `Range` requests. After it expires, requests to it
return `401`.

## Retries

The SDKs retry rate limits, server errors, and network failures with backoff. `appendObject` and completing a
multipart upload run once, so a lost response never appends twice.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.