Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zerointensity/pointers.py
Bringing the hell of pointers to Python.
https://github.com/zerointensity/pointers.py
memory memory-allocation memory-management pointers python python-pointers
Last synced: 14 days ago
JSON representation
Bringing the hell of pointers to Python.
- Host: GitHub
- URL: https://github.com/zerointensity/pointers.py
- Owner: ZeroIntensity
- License: mit
- Created: 2022-03-09T22:46:07.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-08T21:12:41.000Z (2 months ago)
- Last Synced: 2024-10-13T09:31:03.040Z (about 1 month ago)
- Topics: memory, memory-allocation, memory-management, pointers, python, python-pointers
- Language: Python
- Homepage: https://pointers.zintensity.dev/
- Size: 495 KB
- Stars: 916
- Watchers: 6
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# pointers.py
![Tests](https://github.com/ZeroIntensity/pointers.py/actions/workflows/tests.yml/badge.svg)
## Bringing the hell of pointers to Python
Why would you ever need this
- [Documentation](https://pointers.zintensity.dev/)
- [Source](https://github.com/ZeroIntensity/pointers.py)
- [PyPI](https://pypi.org/project/pointers.py)### Examples
```py
from pointers import _text: str = "hello world"
ptr = _&text # creates a new pointer object
ptr <<= "world hello"
print(text) # world hello
``````py
from pointers import c_malloc, c_free, strcpy, printfptr = c_malloc(3)
strcpy(ptr, "hi")
printf("%s\n", ptr) # hi
c_free(ptr)
``````py
from pointers import malloc, freemy_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
```