Skip to content

PEP 782: Add PyBytesWriter C API #62

@vstinner

Description

@vstinner

Hi,

After multiple iterations on the API, I decided to write down a PEP for the PyBytesWriter C API. It's easier to understand the API with its documentation, examples, and discussions around it. A single document (the PEP) should help the discussion.

-> Read PEP 782: Add PyBytesWriter C API <-

The API is now based on sizes rather than pointers, even if two functions using pointers are provided for convenience.

I plan to submit the PEP to the Steering Council, but first I would like to get the opinion of the C API Working Group.

The API was discussed in length, see the PEP for all links to prior discussions. The most recent thread: https://discuss.python.org/t/pep-782-add-pybyteswriter-c-api/86617.

Abstract

Add a new PyBytesWriter C API to create bytes objects.

Soft deprecate PyBytes_FromStringAndSize(NULL, size) and _PyBytes_Resize() APIs. These APIs treat an immutable bytes object as a mutable object. They remain available and maintained, don't emit deprecation warning, but are no longer recommended when writing new code.

Vote

I abstain from voting on my own PEP :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions