blob: 74de3f952005fd7220a4e298d967a464faa6f47a [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`grp` --- The group database
2=================================
3
4.. module:: grp
5 :platform: Unix
6 :synopsis: The group database (getgrnam() and friends).
7
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04008--------------
Georg Brandl116aa622007-08-15 14:28:22 +00009
10This module provides access to the Unix group database. It is available on all
11Unix versions.
12
13Group database entries are reported as a tuple-like object, whose attributes
14correspond to the members of the ``group`` structure (Attribute field below, see
15``<pwd.h>``):
16
17+-------+-----------+---------------------------------+
18| Index | Attribute | Meaning |
19+=======+===========+=================================+
20| 0 | gr_name | the name of the group |
21+-------+-----------+---------------------------------+
22| 1 | gr_passwd | the (encrypted) group password; |
23| | | often empty |
24+-------+-----------+---------------------------------+
25| 2 | gr_gid | the numerical group ID |
26+-------+-----------+---------------------------------+
27| 3 | gr_mem | all the group member's user |
28| | | names |
29+-------+-----------+---------------------------------+
30
31The gid is an integer, name and password are strings, and the member list is a
32list of strings. (Note that most users are not explicitly listed as members of
33the group they are in according to the password database. Check both databases
R. David Murrayec073312010-12-14 16:20:53 +000034to get complete membership information. Also note that a ``gr_name`` that
35starts with a ``+`` or ``-`` is likely to be a YP/NIS reference and may not be
36accessible via :func:`getgrnam` or :func:`getgrgid`.)
Georg Brandl116aa622007-08-15 14:28:22 +000037
38It defines the following items:
39
40
41.. function:: getgrgid(gid)
42
43 Return the group database entry for the given numeric group ID. :exc:`KeyError`
44 is raised if the entry asked for cannot be found.
45
Serhiy Storchaka9cc4ed52016-01-18 18:49:57 +020046 .. deprecated:: 3.6
47 Since Python 3.6 the support of non-integer arguments like floats or
48 strings in :func:`getgrgid` is deprecated.
Georg Brandl116aa622007-08-15 14:28:22 +000049
50.. function:: getgrnam(name)
51
52 Return the group database entry for the given group name. :exc:`KeyError` is
53 raised if the entry asked for cannot be found.
54
55
56.. function:: getgrall()
57
58 Return a list of all available group entries, in arbitrary order.
59
60
61.. seealso::
62
63 Module :mod:`pwd`
64 An interface to the user database, similar to this.
65
66 Module :mod:`spwd`
67 An interface to the shadow password database, similar to this.
68