Python client library

Python client library#

Through the ‘python-irodsclient’ package you are able to interact with iRODS from python. Documentation and installation details can be found at: https://github.com/irods/python-irodsclient

The following code shows a basic method of connecting and retrieving the contents of a folder (or as iRODS calls it: a collection)

from irods.session import iRODSSession
import os

irods_host = os.getenv('IRODS_HOST', 'irods.tudelft.nl')
irods_user = os.getenv('IRODS_USER')
irods_password = os.getenv('IRODS_PASSWORD')
irods_zone = os.getenv('IRODS_ZONE', 'tud')

folder = f"/{irods_zone}/projects/mycoolproject"

ssl_settings = {
    'client_server_negotiation': 'request_server_negotiation',
    'client_server_policy': 'CS_NEG_REQUIRE',                
    'encryption_algorithm': 'AES-256-CBC',
    'encryption_key_size': 32,
    'encryption_num_hash_rounds': 16,
    'encryption_salt_size': 8,
    'ssl_verify_server': 'hostname',
}

common_settings = { 
    'authentication_scheme': "pam_password", 
    'port': 1247, 
    'zone': irods_zone, 
    **ssl_settings 
}


with iRODSSession(host=irods_host, user=irods_user, password=irods_password, **common_settings) as session:
    c = session.collections.get(folder)

    for d in c.data_objects:
        print(f"Found data object {d.name}")

        for r in d.replicas:
            print(f"  replica present on {r.resource_name} at path {r.path}")

    for s in c.subcollections:
        print(f"Found subcollection: {s.name}")

Writing to a specific resource#

When you want your data to land on a specific resource server, you can specify this while writing:


... preamble as above

with iRODSSession(host=irods_host, user=irods_user, password=irods_password, **common_settings) as session:
    with session.data_objects.open('/tud/home/mschenk/test.txt', 'w', destRescName='tudRescDaic') as f:
        f.write(b'Hello, iRODS on tudRescDaic!\n')