iRODS Python Client

3.3.0 · active · verified Fri Apr 17

python-irodsclient is a Python API for interacting with iRODS (integrated Rule-Oriented Data System) servers. It provides programmatic access to iRODS data objects, collections, metadata, and authentication mechanisms. The library is currently at version 3.3.0 and typically releases new versions quarterly, incorporating new iRODS features and Python compatibility updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a session with an iRODS server using environment variables for credentials and then list the contents of the user's home collection. It uses `iRODSSession` as the main entry point for all interactions and showcases basic collection traversal.

import os
from irods.session import iRODSSession

# Configure iRODS connection parameters using environment variables or defaults
host = os.environ.get('IRODS_HOST', 'localhost')
port = int(os.environ.get('IRODS_PORT', '1247'))
zone = os.environ.get('IRODS_ZONE', 'tempZone')
user = os.environ.get('IRODS_USER', 'rods')
password = os.environ.get('IRODS_PASSWORD', 'rods')

try:
    # Establish a session with iRODS
    with iRODSSession(host=host, port=port, zone=zone, user=user, password=password) as session:
        print(f"Successfully connected to iRODS zone: {session.zone} as user: {session.user}")

        # Example: List the contents of the user's home collection
        home_collection_path = f'/{session.zone}/home/{session.user}'
        print(f"\nListing contents of: {home_collection_path}")
        
        try:
            collection = session.collections.get(home_collection_path)
            for item in collection.data_objects:
                print(f"  Data Object: {item.name} (size: {item.size})")
            for sub_collection in collection.subcollections:
                print(f"  Sub-Collection: {sub_collection.name}")
        except Exception as e:
            print(f"  Could not retrieve collection {home_collection_path}: {e}")

except Exception as e:
    print(f"An error occurred during iRODS connection or operation: {e}")
    print("Please ensure your iRODS server is running and credentials are correct.")

view raw JSON →