@@ -200,15 +200,31 @@ if (result.error) {
200200<TabItem value = " python" label = " Python" >
201201Example using the Python SDK boto3:
202202
203+ ``` shell
204+ pip install tigris-boto3-ext
205+ ```
206+
203207``` python
204- def create_bucket_with_snapshot_enabled (tigris , bucket_name ):
205- def add_header (request , ** kwargs ):
206- request.headers[" X-Tigris-Enable-Snapshot" ] = " true"
207- tigris.meta.events.register(" before-sign.s3.CreateBucket" , add_header)
208- try :
209- tigris.create_bucket(Bucket = bucket_name)
210- finally :
211- tigris.meta.events.unregister(" before-sign.s3.CreateBucket" , add_header)
208+ import boto3
209+ from tigris_boto3_ext import (
210+ TigrisSnapshotEnabled,
211+ create_snapshot_bucket,
212+ )
213+
214+ # Initialize boto3 S3 client
215+ s3_client = boto3.client(
216+ ' s3' ,
217+ endpoint_url = ' https://t3.storage.dev' , # Tigris endpoint
218+ aws_access_key_id = ' your-access-key' ,
219+ aws_secret_access_key = ' your-secret-key' ,
220+ )
221+
222+ # Create snapshot enabled bucket using context manager pattern
223+ with TigrisSnapshotEnabled(s3_client):
224+ s3_client.create_bucket(Bucket = ' my-snapshot-bucket' )
225+
226+ # Or, create snapshot enabled bucket using helper function
227+ create_snapshot_bucket(s3_client, ' my-snapshot-bucket' )
212228```
213229
214230</TabItem >
@@ -264,17 +280,32 @@ if (result.error) {
264280<TabItem value = " python" label = " Python" >
265281Example using the Python SDK boto3:
266282
283+ ``` shell
284+ pip install tigris-boto3-ext
285+ ```
286+
267287``` python
268- def create_bucket_snapshot (tigris , bucket_name , snapshot_name ):
269- def add_header (request , ** kwargs ):
270- request.headers[" X-Tigris-Snapshot" ] = f " true; name= { snapshot_name} "
271- tigris.meta.events.register(" before-sign.s3.CreateBucket" , add_header)
272- try :
273- response = tigris.create_bucket(Bucket = bucket_name)
274- headers = response.get(" ResponseMetadata" , {}).get(" HTTPHeaders" , {})
275- return headers.get(" x-tigris-snapshot-version" )
276- finally :
277- tigris.meta.events.unregister(" before-sign.s3.CreateBucket" , add_header)
288+ import boto3
289+ from tigris_boto3_ext import (
290+ create_snapshot_bucket,
291+ create_snapshot,
292+ get_snapshot_version,
293+ )
294+
295+ # Initialize boto3 S3 client
296+ s3_client = boto3.client(
297+ ' s3' ,
298+ endpoint_url = ' https://t3.storage.dev' , # Tigris endpoint
299+ aws_access_key_id = ' your-access-key' ,
300+ aws_secret_access_key = ' your-secret-key' ,
301+ )
302+
303+ # Create snapshot-enabled bucket
304+ create_snapshot_bucket(s3_client, ' bucket-with-snapshots' )
305+
306+ # Create snapshots
307+ result = create_snapshot(s3_client, ' bucket-with-snapshots' , snapshot_name = ' test-snapshot' )
308+ version = get_snapshot_version(result)
278309```
279310
280311</TabItem >
@@ -321,16 +352,34 @@ if (listSnapshots.error) {
321352<TabItem value = " python" label = " Python" >
322353Example using the Python SDK boto3:
323354
355+ ``` shell
356+ pip install tigris-boto3-ext
357+ ```
358+
324359``` python
325- def list_snapshots_for_bucket (tigris , bucket_name ):
326- def add_header (request , ** kwargs ):
327- request.headers[" X-Tigris-Snapshot" ] = bucket_name
328- tigris.meta.events.register(" before-sign.s3.ListBuckets" , add_header)
329- try :
330- snapshots = tigris.list_buckets()
331- finally :
332- tigris.meta.events.unregister(" before-sign.s3.ListBuckets" , add_header)
333- return snapshots
360+ import boto3
361+ from tigris_boto3_ext import (
362+ TigrisSnapshot,
363+ list_snapshots,
364+ )
365+
366+ # Initialize boto3 S3 client
367+ s3_client = boto3.client(
368+ ' s3' ,
369+ endpoint_url = ' https://t3.storage.dev' , # Tigris endpoint
370+ aws_access_key_id = ' your-access-key' ,
371+ aws_secret_access_key = ' your-secret-key' ,
372+ )
373+
374+ # Create snapshot-enabled bucket
375+ create_snapshot_bucket(s3_client, ' bucket-with-snapshots' )
376+
377+ # List snapshots for a bucket using context manager pattern
378+ with TigrisSnapshot(s3_client, ' bucket-with-snapshots' ):
379+ snapshots = s3_client.list_buckets()
380+
381+ # Or, list snapshots via the helper function
382+ snapshots = list_snapshots(s3_client, ' bucket-with-snapshots' )
334383```
335384
336385</TabItem >
@@ -385,7 +434,7 @@ Example using the Go SDK `github.com/aws/aws-sdk-go-v2/service/s3`:
385434``` go
386435func createBucketFork (ctx context .Context , client *s3 .Client , bucketName string ) error {
387436 _ , err := client.CreateBucket (ctx, &s3.CreateBucketInput {Bucket: aws.String (bucketName)}, func (options *s3.Options ) {
388- options.APIOptions = append (options.APIOptions , http.AddHeaderValue (" X-Tigris-Fork-Source-Bucket" , " PARENT_BUCKET_NAME " ))
437+ options.APIOptions = append (options.APIOptions , http.AddHeaderValue (" X-Tigris-Fork-Source-Bucket" , " source-bucket " ))
389438 })
390439 return err
391440}
@@ -400,8 +449,8 @@ Example using the Tigris SDK for JavaScript:
400449import { createBucket } from " @tigrisdata/storage" ;
401450
402451const result = await createBucket (" forked-bucket" , {
403- sourceBucketName: " PARENT_BUCKET_NAME " , // parent bucket name
404- sourceBucketSnapshot: " SNAPSHOT_VERSION " , // optional snapshot version e.g. 1759343574493973169
452+ sourceBucketName: " source-bucket " , // source bucket name
453+ sourceBucketSnapshot: " snapshot_version " , // optional snapshot version e.g. 1759343574493973169
405454});
406455
407456if (result .error ) {
@@ -415,15 +464,32 @@ if (result.error) {
415464<TabItem value = " python" label = " Python" >
416465Example using the Python SDK boto3:
417466
467+ ``` shell
468+ pip install tigris-boto3-ext
469+ ```
470+
418471``` python
419- def create_bucket_fork (tigris , bucket_name ):
420- def add_header (request , ** kwargs ):
421- request.headers[" X-Tigris-Fork-Source-Bucket" ] = " PARENT_BUCKET_NAME"
422- tigris.meta.events.register(" before-sign.s3.CreateBucket" , add_header)
423- try :
424- tigris.create_bucket(Bucket = bucket_name)
425- finally :
426- tigris.meta.events.unregister(" before-sign.s3.CreateBucket" , add_header)
472+ import boto3
473+ from tigris_boto3_ext import TigrisFork
474+
475+ # Initialize boto3 S3 client
476+ s3_client = boto3.client(
477+ ' s3' ,
478+ endpoint_url = ' https://t3.storage.dev' , # Tigris endpoint
479+ aws_access_key_id = ' your-access-key' ,
480+ aws_secret_access_key = ' your-secret-key' ,
481+ )
482+
483+ # Fork from current state
484+ with TigrisFork(s3_client, ' source-bucket' ):
485+ s3_client.create_bucket(Bucket = ' forked-bucket' )
486+
487+ # Fork from specific snapshot
488+ with TigrisFork(s3_client, ' source-bucket' , snapshot_version = ' 1759343574493973169' ):
489+ s3_client.create_bucket(Bucket = ' forked-from-snapshot' )
490+
491+ # Or, use a helper function to create forks
492+ create_fork(s3_client, ' new-bucket' , ' source-bucket' , snapshot_version = version)
427493```
428494
429495</TabItem >
@@ -540,21 +606,62 @@ async function getObjectFromSnapshot(client, bucket, key, snapshotVersion) {
540606<TabItem value="python" label="Python">
541607Example using the Python SDK boto3:
542608
609+ ` ` ` shell
610+ pip install tigris- boto3- ext
611+ ` ` `
612+
543613` ` ` python
544- def get_object_from_snapshot (s3_client, bucket_name, object_key, snapshot_version):
545- def add_header (request, ** kwargs):
546- request .headers [" X-Tigris-Snapshot-Version" ] = snapshot_version
547- s3_client .meta .events .register (" before-sign.s3.GetObject" , add_header)
548- try:
549- response = s3_client .get_object (Bucket= bucket_name, Key= object_key)
550- return response
551- finally:
552- s3_client .meta .events .unregister (" before-sign.s3.GetObject" , add_header)
614+ import boto3
615+ from tigris_boto3_ext import (
616+ TigrisSnapshot,
617+ get_object_from_snapshot,
618+ list_objects_from_snapshot,
619+ head_object_from_snapshot,
620+ )
621+
622+ # Initialize boto3 S3 client
623+ s3_client = boto3 .client (
624+ ' s3' ,
625+ endpoint_url= ' https://t3.storage.dev' , # Tigris endpoint
626+ aws_access_key_id= ' your-access-key' ,
627+ aws_secret_access_key= ' your-secret-key' ,
628+ )
629+
630+ # First, ensure bucket has snapshots enabled
631+ create_snapshot_bucket (s3_client, ' my-bucket' )
632+ s3_client .put_object (Bucket= ' my-bucket' , Key= ' file.txt' , Body= b' data' )
633+
634+ response = create_snapshot (
635+ s3,
636+ ' my-bucket' ,
637+ snapshot_name= ' daily-backup-2024-01-01'
638+ )
639+ snapshot_version = get_snapshot_version (response)
640+ print (f" Snapshot version: {snapshot_version}" )
641+
642+ # Read objects from a specific snapshot using context manager pattern
643+ with TigrisSnapshot (s3_client, ' my-bucket' , snapshot_version= snapshot_version):
644+ obj = s3_client .get_object (Bucket= ' my-bucket' , Key= ' file.txt' )
645+ objects = s3_client .list_objects_v2 (Bucket= ' my-bucket' )
646+
647+ # Or, use a helper function to access snapshot data
648+ obj = get_object_from_snapshot (s3_client , ' my-bucket' , ' file.txt' , snapshot_version )
649+ objects = list_objects_from_snapshot(s3_client, 'my-bucket', snapshot_version)
650+ metadata = head_object_from_snapshot(s3_client, 'my-bucket', 'file.txt', snapshot_version)
553651```
554652
555653</TabItem>
556654</Tabs>
557655
656+ :::note
657+
658+ Check out the
659+ [examples](https:// github.com/tigrisdata/tigris-boto3-ext/tree/main/examples) in
660+ the **tigris-boto3-ext** repo for more details on how to use the snapshot and
661+ forking feature with the Python boto3 SDK.
662+
663+ :::
664+
558665### Using a Forked Bucket
559666
560667Forked buckets behave the same as regular buckets, and you can use the usual
0 commit comments