python-utmp consists of three modules, providing access to utmp records.
It is quite difficult to access utmp record portably, because every UNIX
has different structure of utmp files. Currently, python-utmp works on
platforms which provide getutent, getutid, getutline,  pututline,
setutent, endutent and utmpname functions. Such systems are
GNU systems (Linux and hurd) and System V unices. python-utmp is known
to work on linux with glibc2.0, glibc2.1, SunOS 5.6, HP-UX B.10.20.
It currently does not work on *BSD systems.
     
Usually, system provides functions for accessing utmp, but  on *BSD
systems the only way (IMHO) is to read utmp file as consisting of
C-structures. It is difficuult to unite both worlds. The best way would
be probably to write getutent() & comp. as a library for each specific
platform, and build python-utmp on top of it, emulating fields present
on glibc utmp but missing at the specific platform.

Currently, python-utmp provides linux-like utmp structure, if native
platform misses some members of this structure, sensible defaults are
used instead.

Missing member:    Default used instead:
ut_type                 USER_PROCESS
ut_pid                  0
ut_id                   ''
ut_host                 ''
ut_exit                 0, 0
ut_tv.tv_sec            ut_time
ut_tv.tv_usec           0
ut_addr_v6              0
ut_session              0


CAVEAT:
If native platform misses ut_type, it means all the entries are real
user processes. Therefore, if you write into utmp and your ut_type
is not USER_PROCESS, corresponding utmp entry is cleared (=filled
with zeros). Depending on your system, this may or may not be the
right thing to do.
Reading from utmp and wtmp is safe.

utmpaccess.py provides following functions
(see getutent(3) and utmp(5) for more information):

getutent():
    returns None if there is an error (e.g. going past the end of utmp file)
    otherwise returns tuple of:
    (ut_type, ut_pid, ut_line, ut_id, ut_user, ut_host,
     ut_e_termination, ut_e_exit, ut_session,
     ut_tv_sec, ut_tv_usec, ut_addr_v6)

getutid(ut_type[, ut_id]):
    returns None if there is an error (e.g. not found), otherwise returns
    tuple of:
    (ut_type, ut_pid, ut_line, ut_id, ut_user, ut_host,
     ut_e_termination, ut_e_exit, ut_session,
     ut_tv_sec, ut_tv_usec, ut_addr_vut_line6)

getutline(ut_line):
    returns None if there is an error (e.g. not found), otherwise returns
    tuple of:
    (ut_type, ut_pid, ut_line, ut_id, ut_user, ut_host,
     ut_e_termination, ut_e_exit, ut_session,
     ut_tv_sec, ut_tv_usec, ut_addr_v6)

pututline(ut_type, ut_pid, ut_line, ut_id, ut_user, ut_host,
          ut_e_termination, ut_e_exit, ut_session,
          ut_tv_sec, ut_tv_usec, ut_addr_vut_line6):
    returns None

setutent():
    returns None

endutent()
    returns None

utmpname(fname):
    returns None



UTMPCONST.py provides convenient constants for work with utmpaccess.py
(see UTMPCONST.py source)



utmp.py provides class UtmpRecord with following methods:

getutent()
getutent_dict()
    like getutent(), but returns a dictionary instead of tuple.
    returns {} if there was an error.
getutid(ut_type[, ut_id]):
getutid_dict(ut_type[, ut_id]):
    like getutid(), but returns a dictionary instead of tuple.
    returns {} if there was an error.
getutline(ut_line)
getutline_dict(ut_line)
    like getutline(), but returns a dictionary instead of tuple.
    returns {} if there was an error.
pututline(ut_type, ut_pid, ut_line, ut_id, ut_user, ut_host,
          ut_e_termination, ut_e_exit, ut_session,
          ut_tv_sec, ut_tv_usec, ut_addr_vut_line6)
or pututline(t) where t is tuple as returned by getutent.
pututline_dict(d)
    like pututline(), but d is a dictionary as returned by getutent_dict()
setutent()
endutent()
You pass filename for utmpname() when creating instance of the class, 
e.g. a=Utmp.UtmpRecord("/var/log/wtmp")

