Skip to content
IJK

Buffer Leasing in Python: Modes, Blocking and Compatibility

By IJK ·

The two lease modes, the non-blocking acquire and the compatibility stance the Language Summit 2026 write-up describes for the proposed buffer leasing APIs.

The gap the proposal addresses

The first issue was that the Python Buffer Protocol “didn’t support read and write coordination at the protocol level”. [1]

Storage addresses were stable, but contents were not. [2]

The Buffer Protocol supports a readonly attribute, but this value only applies to a single view, and writable access could not be made exclusive with existing APIs. [3]

Leases and their two modes

Nathan’s proposal to add safe coordination of reads and writes was through new buffer “leasing” C APIs, PyBufferLease and PyBufferAccessState, similar to Rust’s borrowing mechanism. [4]

These APIs would allow consumers to lease a buffer and declare their access pattern ahead of accessing a buffer view. [5]

Leases could be opened in either SHARED_READ or EXCLUSIVE_WRITE mode, and calling PyObject_AcquireBufferLease() would not block, instead immediately either succeeding or failing if an incompatible lease already exists. [6]

EXCLUSIVE_WRITE would provide writable access and exclude every other access to overlapping memory. [7]

SHARED_READone of the two modes a lease can be opened inEXCLUSIVE_WRITEwritable access, excluding every other access to ...
What do the two lease modes allow?

What stays the same

The existing PyObject_GetBuffer(), PyBuffer_Release(), and other related interfaces would remain unchanged under Nathan’s proposal. [8]

Buffer exporters would advertise explicit support for the new access modes, and exporters that don’t support the new access APIs would continue to use existing APIs as-is. [9]

Consumers would query the exporter using PyObject_GetBufferAccessModes() and use a lease if the desired access mode is available from the exporter. [10]

Sources

  1. The Python Software Foundation source says: The first issue was that the Python Buffer Protocol “didn’t support read and write coordination at the protocol level”. Memory Buffer Protocol (Python Language Summit 2026)
  2. The Python Software Foundation source says: Storage addresses were stable, but contents were not. Memory Buffer Protocol (Python Language Summit 2026)
  3. The Python Software Foundation source says: The Buffer Protocol supports a readonly attribute, but this value only applies to a single view, and writable access could not be made exclusive with existing APIs. Memory Buffer Protocol (Python Language Summit 2026)
  4. The Python Software Foundation source says: Nathan’s proposal to add safe coordination of reads and writes was through new buffer “leasing” C APIs, PyBufferLease and PyBufferAccessState, similar to Rust’s borrowing mechanism. Memory Buffer Protocol (Python Language Summit 2026)
  5. The Python Software Foundation source says: These APIs would allow consumers to lease a buffer and declare their access pattern ahead of accessing a buffer view. Memory Buffer Protocol (Python Language Summit 2026)
  6. The Python Software Foundation source says: Leases could be opened in either SHARED_READ or EXCLUSIVE_WRITE mode, and calling PyObject_AcquireBufferLease() would not block, instead immediately either succeeding or failing if an incompatible lease already exists. Memory Buffer Protocol (Python Language Summit 2026)
  7. The Python Software Foundation source says: EXCLUSIVE_WRITE would provide writable access and exclude every other access to overlapping memory. Memory Buffer Protocol (Python Language Summit 2026)
  8. The Python Software Foundation source says: The existing PyObject_GetBuffer(), PyBuffer_Release(), and other related interfaces would remain unchanged under Nathan’s proposal. Memory Buffer Protocol (Python Language Summit 2026)
  9. The Python Software Foundation source says: Buffer exporters would advertise explicit support for the new access modes, and exporters that don’t support the new access APIs would continue to use existing APIs as-is. Memory Buffer Protocol (Python Language Summit 2026)
  10. The Python Software Foundation source says: Consumers would query the exporter using PyObject_GetBufferAccessModes() and use a lease if the desired access mode is available from the exporter. Memory Buffer Protocol (Python Language Summit 2026)

Editorial (AI-assisted; automatically checked, not human-reviewed). Each statement is linked to its source; check the source before relying on a detail.

  • python
  • c api
  • buffers
  • concurrency