> ## 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.

# Bytes Objects

> Working with Python bytes type

## Overview

Bytes objects represent sequences of bytes (integers 0-255). They are immutable.

## Type Object

```c theme={null}
PyTypeObject PyBytes_Type
```

## Type Checking

```c theme={null}
int PyBytes_Check(PyObject *o)
int PyBytes_CheckExact(PyObject *o)
```

## Creating Bytes

```c theme={null}
PyObject* PyBytes_FromString(const char *v)
PyObject* PyBytes_FromStringAndSize(const char *v, Py_ssize_t len)
```

**Example:**

```c theme={null}
PyObject *data = PyBytes_FromString("binary\\x00data");
PyObject *buf = PyBytes_FromStringAndSize(buffer, buffer_len);
```

## Accessing Bytes

```c theme={null}
char* PyBytes_AsString(PyObject *o)
Py_ssize_t PyBytes_Size(PyObject *o)
```

**Example:**

```c theme={null}
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

* [Unicode Objects](/c-api/unicode)
* [Object Protocol](/c-api/object)
