diff --git a/README.md b/README.md index d136657b6..9c1b8862a 100644 --- a/README.md +++ b/README.md @@ -38,20 +38,61 @@ Uninstalling pip uninstall python-irodsclient -Establishing a (secure) connection ----------------------------------- +Establishing a connection +------------------------- -One way of starting a session is to pass iRODS credentials as keyword -arguments: +An `iRODSSession` instance is the interface object through which iRODS server +APIs can be invoked. One can create the object using the constructor form directly, +passing connection and authentication options within the call parameter list: ```python >>> from irods.session import iRODSSession >>> with iRODSSession(host='localhost', port=1247, user='bob', password='1234', zone='tempZone') as session: -... # workload -... ->>> +... # Any number of operations using the 'session' variable can go here. ``` +Another way to create the session object, assuming one has already successfully +set up a client environment via `iinit`, is by using the convenience function `make_session`: + +```python +>>> from irods.helpers import make_session +>>> session = make_session() +``` + +Once created, the `iRODSSession` instance can be managed from a choice between two +possible patterns. Firstly, one can allow references to the instance to persist as +is natural for the application. This allows Python interpreter's reference counting to +let the object pass out of scope and destroy the underlying server connection(s) at the +proper time. This casual approach usually ends up being generally the most efficient one, +as connections are expensive to create and destroy; furthermore, any single connection to +the iRODS server can freely be employed for a number of disparate server interactions, +one after the other. + +Alternatively, a context manager may be used. This forces all connections to be +provisionally cleared from the session object once a given block of code has +executed: + +```python +with make_session() as session: + my_user = session.users.get(session.username) + # We can have further usage of 'session' in this code block. At the end + # of it, session.cleanup() is implicitly called to remove any idle connections. +``` + +Either way, the session instance remains available for further use afterward, until +destructed. + +Of course, we should be mindful of how many still-connected `iRODSSession` +objects are allowed to proliferate in an application, since having more client connections +than the server can support database connections for can result in the spurious failure +of any new attempts to connect. + +Basic authentication and security +--------------------------------- + +As seen in the `iRODSSession` constructor call in the previous section, iRODS credentials may be passed +in as keyword arguments. + If you're an administrator acting on behalf of another user: ```python