---
source: https://iinventedlight.com/library/notes/python-resource.md
title: "Python resource: measure and limit Unix resource use"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, resource — Resource usage information; CPython, resource documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-resource"
tags: [python, resource, unix, rlimit, process]
client: Librarian
sources:
  - id: S1
    title: "resource — Resource usage information"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/resource.html
    accessed: 2026-11-24
    license: "PSF License Version 2"
  - id: S2
    title: "resource documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/resource.rst
    accessed: 2026-11-24
    license: "PSF License Version 2"
---
# Python resource: measure and limit Unix resource use
**Answer:** The resource module measures and controls system resources used by a program on Unix.

## Where it runs

The module is available on Unix, and not on WASI.

Symbolic constants name particular system resources.

You can ask about the current process or its children.

A failed system call raises OSError.

## Soft and hard limits

Each resource has a soft limit and a hard limit.

The soft limit is the current limit, and a process may change it over time.

The soft limit can never exceed the hard limit.

Only a super-user process can raise a hard limit.

getrlimit returns a tuple with the current soft and hard limits.

## See also

- [python-os-environ](https://iinventedlight.com/library/notes/python-os-environ/)
- [python-signal](https://iinventedlight.com/library/notes/python-signal/)
- [python-mmap](https://iinventedlight.com/library/notes/python-mmap/)

## Claims

- id: C1
  claim: The module measures and controls system resources a program uses.
  source: S1
  evidence: "measuring and controlling system resources utilized by a program"

- id: C2
  claim: Each resource has a soft limit and a hard limit.
  source: S1
  evidence: "a pair of limits: a soft limit and a hard limit"

- id: C3
  claim: The soft limit can never exceed the hard limit.
  source: S2
  evidence: "The soft limit can never exceed the hard limit"

- id: C4
  claim: getrlimit returns the current soft and hard limits.
  source: S1
  evidence: "Returns a tuple (soft, hard) with the current soft and hard limits"

## Sources

- [S1] resource — Resource usage information. Python Software Foundation. https://docs.python.org/3/library/resource.html . License: PSF License Version 2. Accessed 2026-11-24.

- [S2] resource documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/resource.rst . License: PSF License Version 2. Accessed 2026-11-24.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, resource — Resource usage information; CPython, resource documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
