•  Home
  •  Dashboard
  •  Company
    • About Us
    • Blog
    • Careers
    • Contact Us
    • Data Centers
    • Looking Glass
    • Network
    • Reseller
  •  Hosting Services
    • Infrastructure
      • iColocation
    • Compute
      • cMetal
      • cVirtual
    • Storage
      • sObject
      • sBlock
    • Networking
      • nIP Transit
      • nWavelength
    • Protection
      • pBackup
      • pDDoS
  •  Solutions
    • Ecommerce
    • Finance
    • Gaming
    • Hosting
    • Management
    • Security
    • System Integrator
  •  Support
    • Community
    • Knowledge Base
    • Open A Ticket
    • Status
  •  USA & Canada: 800-933-1517
  •  International: 626-549-2801
  •  Email: sales@psychz.net
  • Services
    • new-colocation-header-img
      Infrastructure
      • iColocation
    • new-compute-header-img
      Compute
      • cMetal
      • cVirtual
    • new-storage-header-img
      Storage
      • sObject
      • sBlock
    • new-networking-header-img
      Networking
      • nIP Transit
      • nWavelength
    • new-protection-header-img
      Protection
      • pBackup
      • pDDoS
  • Solutions
    • Ecommerce
    • Security
    • Gaming
    • Hosting
    • Management
    • Finance
    • System Integrator
  • Dashboard

sObject - Python Examples

  • Home
  • Client
  • Knowledgebase
  • Storage
  • sObject
  • sObject - Python Examples

Table Of Content

    Related Articles

    • sObject – Bucket Policy Examples
    • sObject – Sub-User Permissions
    • s3Express Guide
    • sObject - Javascript Examples
    • sObject - PHP Examples
    • sObject - Configuring CORS and Bucket Policies Using S3 Browser
    • sObject - SSE (Server Side Encryption) Guide
    • sObject - CNAME Guide
    • sObject - CrossFTP Guide
    • sObject - WinSCP Guide
    • sObject - S3 Browser Guide
    • sObject - Keys
    • sObject - Buckets
    • sObject - Access Using S3tools
    • sObject - Limits and Best Practices
    • sObject - Delete
    • sObject - Intro
    • sObject - Create

    sObject - Python Examples

    Publisher: Psychz Networks March 21,2025
    • Prerequisites
    • Creating a Connection
    • Listing Buckets
    • Creating Buckets
    • Listing Bucket's Content
    • Deleting Bucket
    • Creating Object
    • Uploading Object
    • Downloading Object
    • Deleting Object
    • Changing Object's ACL
    • Generating Object Download URL
    • Conclusion

    Integrating sObject with Python

    sObject provides an S3-compatible API that allows you to interact with your object storage. This article walks you through setting up a connection and executing a variety of operations using Python and boto3.

    Prerequisites

    • Python installed on your system
    • boto3 installed (install via pip install boto3) (# pip install boto3)
    • sObject endpoint, access key, and secret key

    Creating a Connection

    To start, import boto3 and create both a client and a resource object. Replace the placeholder values with sObject endpoint, access key, and secret key.

    import boto3
    from botocore.config import Config
    # sObject endpoint URL (e.g., "http://sobject.psychz.net:8000")
    endpoint_url = "http://sobject.psychz.net:port"
    # Your sObject access credentials
    access_key = "your-access-key"
    secret_key = "your-secret-key"
    # Create an S3 client for low-level operations
    s3_client = boto3.client(
        's3',
        endpoint_url=endpoint_url,
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_key
        config=Config(signature_version='s3'),
    )
    # Create an S3 resource for higher-level object-oriented operations
    s3_resource = boto3.resource(
        's3',
        endpoint_url=endpoint_url,
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_key
    )

    Listing Owned Buckets

    You can list all buckets available to your account using either the client or resource interface.

    Using the client:

    response = s3_client.list_buckets()
    for bucket in response['Buckets']:
        print(bucket['Name'])

    Using the resource:

    for bucket in s3_resource.buckets.all():
        print(bucket.name)

    Creating a Bucket

    To create a new bucket, choose a unique bucket name. Note that bucket naming conventions must be followed.

    bucket_name = "my-new-bucket"
    # Using client
    s3_client.create_bucket(Bucket=bucket_name)
    
    # Alternatively, using resource:
    # bucket = s3_resource.create_bucket(Bucket=bucket_name)

    Listing a Bucket's Content

    List all objects (files) stored within a specific bucket.

    bucket = s3_resource.Bucket(bucket_name)
    for obj in bucket.objects.all():
        print(obj.key)

    Deleting a Bucket

    Before deleting a bucket, ensure it is empty. The following code snippet first deletes all objects in the bucket and then removes the bucket.

    bucket = s3_resource.Bucket(bucket_name)
    
    # Delete all objects in the bucket
    for obj in bucket.objects.all():
        obj.delete()
    
    # Delete the bucket
    s3_client.delete_bucket(Bucket=bucket_name)

    Creating an Object

    Creating an object can be as simple as using the put_object method to store data directly.

    object_key = "sample.txt"
    data = "This is a sample text file."
    s3_client.put_object(Bucket=bucket_name, Key=object_key, Body=data)

    Uploading an Object

    To upload a local file to your bucket, use the upload_file method.

    local_file = "path/to/your/local/file.txt"
    object_key = "uploaded-file.txt"
    s3_client.upload_file(local_file, bucket_name, object_key)

    Downloading an Object

    Download an object from your bucket to a local file using the download_file method.

    download_path = "path/to/downloaded/file.txt"
    s3_client.download_file(bucket_name, object_key, download_path)

    Deleting an Object

    Remove an object from your bucket with the delete_object method.

    s3_client.delete_object(Bucket=bucket_name, Key=object_key)

    Changing an Object's ACL

    You can modify an object’s access control list (ACL). For example, to make an object publicly readable:

    s3_client.put_object_acl(Bucket=bucket_name, Key=object_key, ACL='public-read')

    Generating an Object Download URL

    Signed URL (Temporary Access)

    Generate a time-limited signed URL that allows secure access to a private object:

    signed_url = s3_client.generate_presigned_url(
        'get_object',
        Params={'Bucket': bucket_name, 'Key': object_key},
        ExpiresIn=3600  # URL expires in 1 hour
    )
    print("Signed URL:", signed_url)

    Unsigned URL (For Public Objects)

    If your object is publicly accessible, you can construct an unsigned URL manually:

    unsigned_url = f"{endpoint_url}/{bucket_name}/{object_key}"
    print("Unsigned URL:", unsigned_url)

    Conclusion

    By following these examples, you can easily integrate sObject storage into your Python applications. Adjust the code samples as needed to suit your environment and security policies. For more detailed information, refer to the boto3 documentation.

    Views: (1737) Votes: (0)

    Related Articles

    • sObject – Bucket Policy Examples
    • sObject – Sub-User Permissions
    • s3Express Guide
    • sObject - Javascript Examples
    • sObject - PHP Examples
    • sObject - Configuring CORS and Bucket Policies Using S3 Browser
    • sObject - SSE (Server Side Encryption) Guide
    • sObject - CNAME Guide
    • sObject - CrossFTP Guide
    • sObject - WinSCP Guide
    • sObject - S3 Browser Guide
    • sObject - Keys
    • sObject - Buckets
    • sObject - Access Using S3tools
    • sObject - Limits and Best Practices
    • sObject - Delete
    • sObject - Intro
    • sObject - Create
    Copyright © 2026 Psychz Networks,
    A Profuse Solutions Inc Company
    Hosting Services
    • Catalog
    Infrastructure
    • iColocation
    Compute
    • cMetal
    • cVirtual
    Storage
    • sObject
    • sBlock
    Networking
    • nIP Transit
    • nWavelength
    Protection
    • pBackup
    • pDDoS
    Company
    • About Us
    • Blog
    • Careers
    • Contact Us
    • Data Centers
    • Looking Glass
    • Network
    • Reseller
    Policies
    • Acceptable Usage Policy
    • Privacy Policy
    • Service Level Agreement
    • Terms and Conditions
    Support
    • Community
    • Knowledge Base
    • Open A Ticket
    • Status
    Get In Touch
    • Psychz Networks,
      A Profuse Solutions Company
      611 Wilshire Blvd #300
      Los Angeles,California 90017
      USA
    • US/Canada: 800-933-1517
    • International: 626-549-2801