Documentation Index
Fetch the complete documentation index at: https://mintlify.com/python/cpython/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Bytes objects represent sequences of bytes (integers 0-255). They are immutable.
Type Object
PyTypeObject PyBytes_Type
Type Checking
int PyBytes_Check(PyObject *o)
int PyBytes_CheckExact(PyObject *o)
Creating Bytes
PyObject* PyBytes_FromString(const char *v)
PyObject* PyBytes_FromStringAndSize(const char *v, Py_ssize_t len)
Example:
PyObject *data = PyBytes_FromString("binary\\x00data");
PyObject *buf = PyBytes_FromStringAndSize(buffer, buffer_len);
Accessing Bytes
char* PyBytes_AsString(PyObject *o)
Py_ssize_t PyBytes_Size(PyObject *o)
Example:
char *data = PyBytes_AsString(bytes_obj);
Py_ssize_t size = PyBytes_Size(bytes_obj);
for (Py_ssize_t i = 0; i < size; i++) {
printf("%02x ", (unsigned char)data[i]);
}
See Also