API Reference¶
This page documents the public Python API. The C extension (pyquota._native) is not
documented here; use the man page for low-level semantics.
Module contents¶
PyQuota: Python wrapper for Linux quotactl(2) APIs.
Kernel support: >= 2.4.22. Project quota requires >= 4.1; Q_GETNEXTQUOTA requires >= 4.6.
- exception pyquota.APIError¶
- exception pyquota.InvalidError¶
- class pyquota.NextQuota(block_hard_limit: int, block_soft_limit: int, block_current: int, inode_hard_limit: int, inode_soft_limit: int, inode_current: int, block_time: int, inode_time: int, id: int)¶
Quota for the next ID >= given ID that has an active quota (includes id).
- block_current: int¶
Alias for field number 2
- block_hard_limit: int¶
Alias for field number 0
- block_soft_limit: int¶
Alias for field number 1
- block_time: int¶
Alias for field number 6
- id: int¶
Alias for field number 8
- inode_current: int¶
Alias for field number 5
- inode_hard_limit: int¶
Alias for field number 3
- inode_soft_limit: int¶
Alias for field number 4
- inode_time: int¶
Alias for field number 7
- class pyquota.NextQuotaPartial(block_hard_limit: int | None, block_soft_limit: int | None, block_current: int | None, inode_hard_limit: int | None, inode_soft_limit: int | None, inode_current: int | None, block_time: int | None, inode_time: int | None, id: int)¶
Next-quota from get_next_*_quota_partial. Quota fields are None when not set by kernel; id is always set.
- block_current: int | None¶
Alias for field number 2
- block_hard_limit: int | None¶
Alias for field number 0
- block_soft_limit: int | None¶
Alias for field number 1
- block_time: int | None¶
Alias for field number 6
- id: int¶
Alias for field number 8
- inode_current: int | None¶
Alias for field number 5
- inode_hard_limit: int | None¶
Alias for field number 3
- inode_soft_limit: int | None¶
Alias for field number 4
- inode_time: int | None¶
Alias for field number 7
- exception pyquota.NotFoundError¶
- exception pyquota.PermissionError¶
- class pyquota.Quota(block_hard_limit: int, block_soft_limit: int, block_current: int, inode_hard_limit: int, inode_soft_limit: int, inode_current: int, block_time: int, inode_time: int)¶
Disk quota limits and current usage for one user/group/project.
Block limits are in 1024-byte disk quota blocks; block_current is in bytes. block_time and inode_time are Unix timestamps (seconds since epoch) when the grace period for exceeding the soft limit expires, or 0 if not over limit.
- block_current: int¶
Alias for field number 2
- block_hard_limit: int¶
Alias for field number 0
- block_soft_limit: int¶
Alias for field number 1
- block_time: int¶
Alias for field number 6
- inode_current: int¶
Alias for field number 5
- inode_hard_limit: int¶
Alias for field number 3
- inode_soft_limit: int¶
Alias for field number 4
- inode_time: int¶
Alias for field number 7
- class pyquota.QuotaErrno(*values)¶
Errno values for APIError.errno (quotactl(2) ERRORS). Compare e.errno with these.
- EACCES = 13¶
- EBUSY = 16¶
- EFAULT = 14¶
- EINVAL = 22¶
- ENOENT = 2¶
- ENOSYS = 38¶
- ENOTBLK = 15¶
- EPERM = 1¶
- ERANGE = 34¶
- ESRCH = 3¶
- class pyquota.QuotaFormat(*values)¶
Quota filesystem format for quota_on / get_*_quota_format. Values match kernel QFMT_*.
- VFS_OLD = 1¶
- VFS_V0 = 2¶
- VFS_V1 = 4¶
- class pyquota.QuotaInfo(block_grace: int, inode_grace: int, flags: int)¶
Quotafile info: grace periods and flags. Tuple-like (indexing, unpacking).
- block_grace: int¶
Alias for field number 0
- flags: int¶
Alias for field number 2
- inode_grace: int¶
Alias for field number 1
- property root_squash: bool¶
True if QuotaInfoFlags.ROOT_SQUASH is set (v1 format root squash enabled).
- property sys_file: bool¶
True if QuotaInfoFlags.SYS_FILE is set (quota stored in system inode).
- class pyquota.QuotaInfoFlags(*values)¶
Flags for get_*_quota_info / set_*_quota_info (kernel DQF_*). Combine with | for set_*_quota_info(…, flags=…).
- ROOT_SQUASH = 1¶
- SYS_FILE = 65536¶
- class pyquota.QuotaInfoPartial(block_grace: int | None, inode_grace: int | None, flags: int | None)¶
Quotafile info from get_*_quota_info_partial. Fields are None when not set (per man 2 quotactl dqi_valid).
- block_grace: int | None¶
Alias for field number 0
- flags: int | None¶
Alias for field number 2
- inode_grace: int | None¶
Alias for field number 1
- class pyquota.QuotaPartial(block_hard_limit: int | None, block_soft_limit: int | None, block_current: int | None, inode_hard_limit: int | None, inode_soft_limit: int | None, inode_current: int | None, block_time: int | None, inode_time: int | None)¶
Quota from get_*_quota_partial. Fields are None when the kernel did not supply them (per man 2 quotactl dqb_valid).
- block_current: int | None¶
Alias for field number 2
- block_hard_limit: int | None¶
Alias for field number 0
- block_soft_limit: int | None¶
Alias for field number 1
- block_time: int | None¶
Alias for field number 6
- inode_current: int | None¶
Alias for field number 5
- inode_hard_limit: int | None¶
Alias for field number 3
- inode_soft_limit: int | None¶
Alias for field number 4
- inode_time: int | None¶
Alias for field number 7
- pyquota.get_group_quota(device: str, gid: int) Quota¶
Get group quota. See also: set_group_quota, get_group_quota_partial.
- pyquota.get_group_quota_format(device: str) int¶
Get group quota format. See also: QuotaFormat.
- pyquota.get_group_quota_info(device: str) QuotaInfo¶
Get group quotafile info. See also: set_group_quota_info.
- pyquota.get_group_quota_info_partial(device: str) QuotaInfoPartial¶
- pyquota.get_group_quota_partial(device: str, gid: int) QuotaPartial¶
See also: get_group_quota.
- pyquota.get_next_group_quota(device: str, gid: int) NextQuota¶
Get next group quota (id >= gid). See also: iter_group_quotas, get_group_quota.
- pyquota.get_next_group_quota_partial(device: str, gid: int) NextQuotaPartial¶
- pyquota.get_next_project_quota(device: str, projid: int) NextQuota¶
Get next project quota (id >= projid). See also: iter_project_quotas, get_project_quota.
- pyquota.get_next_project_quota_partial(device: str, projid: int) NextQuotaPartial¶
- pyquota.get_next_user_quota(device: str, uid: int) NextQuota¶
Get next user quota (id >= uid). Returns NextQuota named tuple (tuple-compatible). See also: iter_user_quotas, get_user_quota.
- pyquota.get_next_user_quota_partial(device: str, uid: int) NextQuotaPartial¶
See also: get_next_user_quota.
- pyquota.get_project_quota(device: str, projid: int) Quota¶
Get project quota. See also: set_project_quota, get_project_quota_partial.
- pyquota.get_project_quota_format(device: str) int¶
Get project quota format. See also: QuotaFormat.
- pyquota.get_project_quota_info(device: str) QuotaInfo¶
Get project quotafile info. See also: set_project_quota_info.
- pyquota.get_project_quota_info_partial(device: str) QuotaInfoPartial¶
- pyquota.get_project_quota_partial(device: str, projid: int) QuotaPartial¶
See also: get_project_quota.
- pyquota.get_user_quota(device: str, uid: int) Quota¶
Get user quota. Returns Quota named tuple (tuple-compatible). See also: set_user_quota, get_user_quota_partial.
- pyquota.get_user_quota_format(device: str) int¶
Get user quota format (QFMT_*). See also: QuotaFormat, user_quota_on.
- pyquota.get_user_quota_info(device: str) QuotaInfo¶
Get user quotafile info. Returns QuotaInfo (tuple-like; .root_squash, .sys_file). See also: set_user_quota_info.
- pyquota.get_user_quota_info_partial(device: str) QuotaInfoPartial¶
See also: get_user_quota_info.
- pyquota.get_user_quota_partial(device: str, uid: int) QuotaPartial¶
Get user quota allowing partial kernel data. Unset fields are None. See also: get_user_quota.
- pyquota.group_quota_off(device: str) None¶
Turn off group quotas. See also: group_quota_on.
- pyquota.group_quota_on(device: str, quota_format: int, quota_file: str) None¶
Turn on group quotas. See also: group_quota_off, QuotaFormat.
- pyquota.iter_group_quotas(device: str, start_gid: int = 0) Iterator[NextQuota]¶
Yield NextQuota for each group with quota on device (id >= start_gid). See also: get_next_group_quota.
- pyquota.iter_project_quotas(device: str, start_projid: int = 0) Iterator[NextQuota]¶
Yield NextQuota for each project with quota on device (id >= start_projid). See also: get_next_project_quota.
- pyquota.iter_user_quotas(device: str, start_uid: int = 0) Iterator[NextQuota]¶
Yield NextQuota for each user with quota on device (id >= start_uid). Uses get_next_user_quota. See also: get_next_user_quota.
- pyquota.project_quota_off(device: str) None¶
Turn off project quotas. See also: project_quota_on.
- pyquota.project_quota_on(device: str, quota_format: int, quota_file: str) None¶
Turn on project quotas. See also: project_quota_off, QuotaFormat.
- pyquota.set_group_quota(device: str, gid: int, block_hard_limit: int | None = None, block_soft_limit: int | None = None, inode_hard_limit: int | None = None, inode_soft_limit: int | None = None, *, limits_from=None)¶
Set group quota limits. Pass the four limits or limits_from=; limits must be non-negative ints. See also: get_group_quota.
- pyquota.set_group_quota_info(device: str, block_grace: int, inode_grace: int, flags: int) None¶
Set group quotafile info. See also: get_group_quota_info.
- pyquota.set_project_quota(device: str, projid: int, block_hard_limit: int | None = None, block_soft_limit: int | None = None, inode_hard_limit: int | None = None, inode_soft_limit: int | None = None, *, limits_from=None)¶
Set project quota limits. Pass the four limits or limits_from=; limits must be non-negative ints. See also: get_project_quota.
- pyquota.set_project_quota_info(device: str, block_grace: int, inode_grace: int, flags: int) None¶
Set project quotafile info. See also: get_project_quota_info.
- pyquota.set_user_quota(device: str, uid: int, block_hard_limit: int | None = None, block_soft_limit: int | None = None, inode_hard_limit: int | None = None, inode_soft_limit: int | None = None, *, limits_from=None)¶
Set user quota limits. Pass the four limits, or limits_from=<Quota/8-tuple> to use the four limit fields from get_user_quota. Limits must be non-negative ints. QuotaPartial with None limits is not accepted. See also: get_user_quota.
- pyquota.set_user_quota_info(device: str, block_grace: int, inode_grace: int, flags: int) None¶
Set user quotafile info (grace periods, flags). See also: get_user_quota_info.
- pyquota.sync_group_quotas(device: str | None) None¶
Sync group quota usage to disk. device=None syncs all.
- pyquota.sync_project_quotas(device: str | None) None¶
Sync project quota usage to disk. device=None syncs all.
- pyquota.sync_user_quotas(device: str | None) None¶
Sync user quota usage to disk. device=None syncs all. See also: sync_group_quotas.
- pyquota.user_quota_off(device: str) None¶
Turn off user quotas. See also: user_quota_on.
- pyquota.user_quota_on(device: str, quota_format: int, quota_file: str) None¶
Turn on user quotas. See also: user_quota_off, QuotaFormat.
Named types¶
Quota:
block_hard_limit,block_soft_limit,block_current(bytes), inode fields,block_time,inode_time. Block limits in 1024-byte blocks. Returned byget_*_quota(tuple-compatible).NextQuota: same as Quota plus
id(uid/gid/projid). Returned byget_next_*_quotaand yielded byiter_*_quotas(tuple-compatible).QuotaInfo:
block_grace,inode_grace(seconds),flags. Returned byget_*_quota_info(tuple-compatible). Properties ``.root_squash`` and ``.sys_file``; use ``QuotaInfoFlags`` forset_*_quota_info(..., flags=...).QuotaPartial, NextQuotaPartial, QuotaInfoPartial: same fields as above but with
Optional[int]; fields the kernel did not set areNone. Returned byget_*_quota_partialandget_*_quota_info_partial.
Enums and constants¶
QuotaFormat (IntEnum):
VFS_OLD,VFS_V0,VFS_V1forquota_on/get_*_quota_format(compare return value ofget_*_quota_formatwith these).QuotaInfoFlags (IntEnum):
ROOT_SQUASH,SYS_FILEforset_*_quota_info(..., flags=...)(combine with|);QuotaInfo.root_squash/.sys_filereflect these.QuotaErrno (IntEnum):
EACCES,EBUSY,EFAULT,EINVAL,ENOENT,ENOSYS,ENOTBLK,EPERM,ERANGE,ESRCHfor comparing withAPIError.errno.
Exceptions¶
- exception pyquota.APIError¶
Base for quotactl failures. See quotactl(2) ERRORS. When raised from the public API, ``.device`` and ``.id`` are set when applicable. Subclasses:
PermissionError (EPERM)
NotFoundError (ENOENT, ESRCH)
InvalidError (EINVAL, ERANGE, EFAULT, etc.)
All have an
errnoattribute.