NumPy & Cython's Zero-Copy Edge: Enabled by PEP 3118

The protocol is foundational for scientific computing, allowing libraries like NumPy and Cython to efficiently share large, multi-dimensional data without costly copies. Cython's memoryviews directly utilize PEP 3118 to provide C-speed access to underlying data buffers from various sources.

The top 3

  1. PEP 3118's Predecessor: The Old Buffer Protocol's Limits: Before PEP 3118, Python's original buffer protocol (PEP 229) was limited to 1D byte arrays, making efficient exchange of multi-dimensional or typed data between extensions cumbersome and often requiring data copies.
  2. Beyond NumPy & Cython: Key Libraries Using PEP 3118: Many other high-performance Python libraries, including SciPy, Pandas, PyTorch, and TensorFlow, extensively utilize PEP 3118's buffer protocol to efficiently share data with C/C++ extensions, avoiding costly data copies.
  3. Zero-Copy's Core: Metadata, Not Data Transfer: PEP 3118 enables zero-copy by allowing extensions to share not the actual data, but a 'view' containing crucial metadata like data type, shape, and strides, allowing direct access to the same memory block.

Sources

Open the full topic