---
source: https://iinventedlight.com/library/notes/python-fcntl.md
title: "Python fcntl: file and I/O control on Unix descriptors"
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, fcntl — The fcntl and ioctl system calls; CPython, fcntl 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-fcntl"
tags: [python, fcntl, ioctl, unix, file-descriptors]
client: Librarian
sources:
  - id: S1
    title: "fcntl — The fcntl and ioctl system calls"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/fcntl.html
    accessed: 2026-11-24
    license: "PSF License Version 2"
  - id: S2
    title: "fcntl documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/fcntl.rst
    accessed: 2026-11-24
    license: "PSF License Version 2"
---
# Python fcntl: file and I/O control on Unix descriptors
**Answer:** The fcntl module performs file and I/O control on Unix file descriptors.

## What the module is for

It is a Python interface to the Unix fcntl and ioctl routines.

Every function takes a file descriptor as its first argument.

That argument may be an integer, or an object that provides a fileno method.

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

## Errors, locks, and platform constants

Operations that used to raise IOError now raise OSError.

flock performs a lock operation on a file descriptor.

lockf is essentially a wrapper around the fcntl locking calls.

On macOS, F_GETPATH obtains the path of a file from a file descriptor.

## See also

- [python-os-path](https://iinventedlight.com/library/notes/python-os-path/)
- [python-io](https://iinventedlight.com/library/notes/python-io/)
- [python-select](https://iinventedlight.com/library/notes/python-select/)

## Claims

- id: C1
  claim: The module performs file and I/O control on file descriptors.
  source: S1
  evidence: "This module performs file and I/O control on file descriptors."

- id: C2
  claim: The module is an interface to the Unix fcntl and ioctl routines.
  source: S1
  evidence: "It is an interface to the fcntl() and ioctl() Unix routines."

- id: C3
  claim: The module performs file and I/O control on file descriptors.
  source: S2
  evidence: "This module performs file and I/O control on file descriptors."

- id: C4
  claim: Operations that used to raise IOError now raise OSError.
  source: S2
  evidence: "used to raise an :exc:`IOError` where they now raise an :exc:`OSError`."

## Sources

- [S1] fcntl — The fcntl and ioctl system calls. Python Software Foundation. https://docs.python.org/3/library/fcntl.html . License: PSF License Version 2. Accessed 2026-11-24.

- [S2] fcntl documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/fcntl.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, fcntl — The fcntl and ioctl system calls; CPython, fcntl 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).
