Skip to content

Commit 7470d85

Browse files
committed
update the python code for snapshot/forking
1 parent e774563 commit 7470d85

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

docs/buckets/snapshots-and-forks.mdx

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,55 @@ async function hasSnapshotEnabled(s3Client, bucketName) {
553553
<TabItem value="python" label="Python">
554554
Example using the Python SDK boto3:
555555
556+
```shell
557+
pip install tigris-boto3-ext
558+
```
559+
556560
```python
557-
def has_snapshot_enabled(tigris, bucket_name):
558-
response = tigris.head_bucket(Bucket=bucket_name)
559-
headers = response.get("ResponseMetadata", {}).get("HTTPHeaders", {})
560-
return headers.get("x-tigris-enable-snapshot", "") == "true"
561+
import boto3
562+
from tigris_boto3_ext import (
563+
create_snapshot_bucket,
564+
create_snapshot,
565+
create_fork,
566+
get_snapshot_version,
567+
has_snapshot_enabled,
568+
get_bucket_info,
569+
)
570+
571+
# Initialize boto3 S3 client
572+
s3_client = boto3.client(
573+
's3',
574+
endpoint_url='https://t3.storage.dev', # Tigris endpoint
575+
aws_access_key_id='your-access-key',
576+
aws_secret_access_key='your-secret-key',
577+
)
578+
579+
# Check if a bucket has snapshots enabled
580+
bucket_name = 'my-bucket'
581+
582+
create_snapshot_bucket(s3_client, bucket_name)
583+
584+
if has_snapshot_enabled(s3_client, bucket_name):
585+
print(f"✓ Snapshots are enabled for {bucket_name}")
586+
else:
587+
print(f"✗ Snapshots are not enabled for {bucket_name}")
588+
589+
# Example: Check fork lineage
590+
source_bucket = 'production-data'
591+
create_snapshot_bucket(s3_client, source_bucket)
592+
593+
# Create a snapshot
594+
snapshot_result = create_snapshot(s3_client, source_bucket, snapshot_name='v1')
595+
snapshot_version = get_snapshot_version(snapshot_result)
596+
597+
# Create a fork
598+
forked_bucket = 'test-data'
599+
create_fork(s3_client, forked_bucket, source_bucket, snapshot_version=snapshot_version)
600+
601+
# Inspect the fork
602+
fork_info = get_bucket_info(s3_client, forked_bucket)
603+
print(f"Forked from: {fork_info['fork_source_bucket']}")
604+
print(f"Snapshot version: {fork_info['fork_source_snapshot']}")
561605
```
562606
563607
</TabItem>

0 commit comments

Comments
 (0)