# Python.array() or Python.memoryview() converters for Mojo types

**URL:** <https://forum.modular.com/t/python-array-or-python-memoryview-converters-for-mojo-types/2113>\
**Category:** Mojo\
**Tags:** gpu, python-interop\
**Created:** [August 11, 2025, 11:52pm UTC](https://forum.modular.com/t/python-array-or-python-memoryview-converters-for-mojo-types/2113 "2025-08-11T23:52:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![laranzu](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/laranzu/32/724_2.png) [@laranzu](https://forum.modular.com/u/laranzu)\
**Post date:** [August 11, 2025, 11:52pm UTC](https://forum.modular.com/t/python-array-or-python-memoryview-converters-for-mojo-types/2113/1 "2025-08-11T23:52:55Z")

</div>

Proposal: the Mojo python.Python module should have a function that creates a` Python array.array` or `memoryview` object from a Mojo array of numbers like object, such as a GPu `HostBuffer`.

Use case: I wrote my first Mojo GPU program recently (Julia set fractal) and by far the slowest part of the code was converting the Mojo HostBuffer into a Python list. (I use the Python PIL to save as PNG.)

Python has a built-in module `array` for C-style arrays of numbers which are popular with Python number crunchers and graphic programmers, and these Python arrays support the `memoryview` buffer protocol which is widely supported by Python native extensions such as numpy. Memory views are just chunks of memory while arrays have an element type, so the latter is more useful but harder to get at from C/C++ ☹

I would like to see at minimum the GPU HostBuffer type should implement the `ConvertableToPython` trait, as an array.array or buffer protocol object. I think a Python array() or memoryview() function that converts any Mojo sequence of numbers/SIMD numbers into a Python array like object would be very useful for people using Mojo as a Python accelerator or with other Python extensions.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [February 7, 2026, 11:53pm UTC](https://forum.modular.com/t/python-array-or-python-memoryview-converters-for-mojo-types/2113/2 "2026-02-07T23:53:47Z")

</div>

Closed on February 7, 2026, 11:53pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
