ZeroIntensity/pointers.py

Bringing the hell of pointers to Python.

Python

936

214 commits

updated Jan 7, 2025

See the code

README

pointers.py

Tests

Bringing the hell of pointers to Python

Why would you ever need this

Examples

from pointers import _

text: str = "hello world"
ptr = _&text  # creates a new pointer object
ptr <<= "world hello"
print(text)  # world hello
from pointers import c_malloc, c_free, strcpy, printf

ptr = c_malloc(3)
strcpy(ptr, "hi")
printf("%s\n", ptr)  # hi
c_free(ptr)
from pointers import malloc, free

my_str = malloc(103)
my_str <<= "hi"
second_str = my_str[51]
second_str <<= "bye"
print(*my_str, *second_str)  # hi bye
free(my_str)

Features

  • Fully type safe
  • Pythonic pointer API
  • Bindings for the entire C standard library and CPython ABI
  • Segfaults

Why does this exist?

The main purpose of pointers.py is to simply break the rules of Python, but has some other use cases:

  • Can help C/C++ developers get adjusted to Python
  • Provides a nice learning environment for programmers learning how pointers work
  • Makes it very easy to manipulate memory in Python
  • Why not?

Installation

Linux/macOS

python3 -m pip install -U pointers.py

Windows

py -3 -m pip install -U pointers.py
memory
memory-allocation
memory-management
pointers
python
python-pointers

ZeroIntensity/pointers.py

Bringing the hell of pointers to Python.

Python

936

214 commits

updated Jan 7, 2025

See the code

README

pointers.py

Tests

Bringing the hell of pointers to Python

Why would you ever need this

Examples

from pointers import _

text: str = "hello world"
ptr = _&text  # creates a new pointer object
ptr <<= "world hello"
print(text)  # world hello
from pointers import c_malloc, c_free, strcpy, printf

ptr = c_malloc(3)
strcpy(ptr, "hi")
printf("%s\n", ptr)  # hi
c_free(ptr)
from pointers import malloc, free

my_str = malloc(103)
my_str <<= "hi"
second_str = my_str[51]
second_str <<= "bye"
print(*my_str, *second_str)  # hi bye
free(my_str)

Features

  • Fully type safe
  • Pythonic pointer API
  • Bindings for the entire C standard library and CPython ABI
  • Segfaults

Why does this exist?

The main purpose of pointers.py is to simply break the rules of Python, but has some other use cases:

  • Can help C/C++ developers get adjusted to Python
  • Provides a nice learning environment for programmers learning how pointers work
  • Makes it very easy to manipulate memory in Python
  • Why not?

Installation

Linux/macOS

python3 -m pip install -U pointers.py

Windows

py -3 -m pip install -U pointers.py
memory
memory-allocation
memory-management
pointers
python
python-pointers

Project health

Overall

3.1/10

Maintained

0/10

Code review

0/10
OpenSSF Scorecard

Latest release

3.0.1 · Apr 1, 2024

Releases this year

0

Significant stargazers

bluss

631 followers · starred Jun 2022

Jon Crall

245 followers · starred Jun 2024

Bruno Alla

304 followers · starred Mar 2024

refi64

354 followers · starred Mar 2022