Usage

This section demonstrates the main functionalities of the Jetraw Python SDK.

Importing SDK Components

from jetraw import Client
from jetraw import JetrawPath
from jetraw import JetrawTrash

Setting up Logging

It is recommended to set up logging for better debugging:

import logging
handler = logging.FileHandler('your_log_file.log')
logger = logging.getLogger('jetraw')
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

Initializing a Client

The Client class is the main entry point for Python SDK operations. Here are different ways to initialize it and load credentials:

# Initialize a client without parameters (uses default credentials)
client = Client()
print(f"Default host: {client.host}")

# Initialize with specific parameters
custom_client = Client(host="https://ORGANIZATION_NAME.clients.jetraw.com", access_token=None)

# Initialize a client with a specific organization
client.load_configuration(organization="ORGANIZATION_NAME", config_file="", shared_credentials_file="")

Authentication

To authenticate a client:

client.authorize()

Note

client.authorize() will automatically start a browser to authenticate the client. Please make sure to authenticate before using any other operations.

File System Operations

JetrawPath provides a path-like interface for working with Jetraw:

# Create a JetrawPath instance to home directory
root_path = JetrawPath("", client=client)
if root_path.exists:
    print(f"Root path: {root_path}")

# List contents of a directory
home_contents = root_path.iterdir()
print("Contents of root directory:")
for item in home_contents[:10]:  # Show first 10 items
    print(f"{item}")

# Create a new directory
test_dir = JetrawPath("/home/new/directory", client=client)
try:
    test_dir.mkdir(exist_ok=True)
    print(f"Created directory: {test_dir}")
except Exception as e:
    print(f"Error creating directory: {e}")

# Check path properties
if test_dir.exists:
    print(f"{test_dir} exists")
    print(f"Is directory: {test_dir.is_dir()}")
    print(f"Is empty: {test_dir.is_empty()}")

Note

The exist_ok parameter is used to avoid raising an error when the directory already exists.

Storage Destinations

Working with storage destinations:

# List all available storage destinations
storage_destinations = client.destinations.list()
print("Available storage destinations:")
for storage in storage_destinations:
    print(f"- {storage}")

# Add a new storage destination
storage_destination = client.destinations.add("local-storage", "/Users/user/Desktop/local-jetraw", "local")

File Transfer Operations

Uploading and downloading files:

# Upload a file
local_file = "/Users/user/Desktop/local_file"
remote_path = "/home/remote_path"
client.upload(local_file, remote_path, storages=["local-storage"])

# Download a file
remote_file = "/home/remote_file"
local_destination = "/Users/user/Desktop/local_destination"
client.download(remote_file, local_destination, storages=["local-storage"])

Trash Operations

Managing files in the trash:

# Initialize the trash object
trash = JetrawTrash(client=client)

# List all files in the trash
trash.list()

# Move a file to trash
file = JetrawPath("/home/path/to/file.dng")
success = trash.remove(file)
if success:
    print(f"Successfully moved '{file.name}' to trash")

# Restore a file from trash
restored_path, restore_success = trash.restore(file)
if restore_success:
    print(f"Successfully restored '{file.name}' to '{restored_path}'")

# Delete a file from trash
file_to_delete = JetrawPath("/trash/file.dng")
delete_success = trash.delete(file_to_delete, force=True)
if delete_success:
    print(f"Successfully deleted '{file_to_delete.name}' from trash")

Warning

When deleting a file from trash, the file is permanently deleted from the storage and cannot be restored. A confirmation is required to delete the file. Use force=True to skip the confirmation.