Skip to main content

ctypes but usable

Project description

dtypes

Yo yo what's this?

Well it's ✨dtypes✨ which is extra stuff to make ctypes usable. Or as the my future kids like to say, "dtypes is on ctypes like butter is on toast".

Who wants to do

class Yolo(ctypes.structure):
    _fields_ = [
        ("a", ctypes.c_int),
        ("b", ctypes.c_float),
        ("c", ctypes.c_double),
    ]

when you can do

from dtypes.structify import structify

@structify
class Yolo(ctypes.structure):
    a : ctypes.c_int
    b : ctypes.c_float
    c : ctypes.c_double

And then, who wants to deal with the messy and incomplete way of working with forward declarations in pure ctypes?

class Yeet(ctypes.structure):
    pass

class Chonko(ctypes.structure):
    _fields_ = [
        ("yeet", ctypes.POINTER(Yeet)),
    ]

Yeet._fields_ =[
    ("chonker", Chonko),
    ("this", ctypes.POINTER(Yeet),
]

when you can do

from dtypes.structify import structify
from dtypes.fwd import fwd, ThisPtr, Pointer

Yeet = fwd()

@structify
class Chonko(ctypes.structure):
    yeet : Pointer(Yeet)

@structify
class Yeet(ctypes.structure, Yeet):
    chonker : Chonko
    this    : ThisPtr
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dtypes-0.0.1.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

dtypes-0.0.1-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page