---
title: "boto3"
description: "Use boto3 with EZGH Object Storage, with path-style or virtual-hosted URLs."
---

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

# boto3

Examples here use boto3 1.42. Set the endpoint, the region and `signature_version`:

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

s3 = boto3.client(
    "s3",
    endpoint_url="https://s3.us-west-1.ezghapps.com",
    region_name="us-west-1",
    aws_access_key_id="oak_…",
    aws_secret_access_key="…",
    config=Config(signature_version="s3v4"),
)
```

Leave the keys out to read them from `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.

`signature_version="s3v4"` is what makes
[presigned URLs](/object-storage/public-buckets-and-presigned-urls#presigned-urls) work: without it,
`generate_presigned_url` signs with SigV2, which is refused.

## Path-style and virtual-hosted URLs

With a custom endpoint, boto3 puts the bucket in the path. For virtual-hosted URLs, set
`addressing_style`:

```python
config = Config(signature_version="s3v4", s3={"addressing_style": "virtual"})
```

| Style | URL |
| --- | --- |
| `path` | `https://s3.us-west-1.ezghapps.com/my-bucket/report.pdf` |
| `virtual` | `https://my-bucket.s3.us-west-1.ezghapps.com/report.pdf` |

## Upload and download files

`upload_file` and `download_file` use multipart uploads and ranged downloads for large files.

```python
s3.upload_file("backup.tar", "my-bucket", "backups/backup.tar")
s3.download_file("my-bucket", "backups/backup.tar", "backup.tar")
```

## List objects

```python
paginator = s3.get_paginator("list_objects_v2")
for page in paginator.paginate(Bucket="my-bucket", Prefix="backups/"):
    for item in page.get("Contents", []):
        print(item["Key"], item["Size"])
```

## Handle errors

```python
from botocore.exceptions import ClientError

try:
    s3.head_object(Bucket="my-bucket", Key="missing.txt")
except ClientError as error:
    print(error.response["Error"]["Code"])
```

Operations outside the [supported list](/object-storage#supported-s3-operations) answer
`NotImplemented`.

Source: https://docs.ezghcloud.com/object-storage/boto3/index.mdx
