ctypes-plus
A dataclass-like interface for ctypes data types.
Installation
pip install ctypes-plus
Usage
Decorate an annotated class with @structure or @union. Each annotation
becomes a _fields_ entry, and the result is a ctypes.Structure /
ctypes.Union subclass usable anywhere ctypes is expected.
from ctypes_plus import structure, union
from ctypes_plus.types import CharP, Double, Int32, UInt64
@structure
class LogEvent:
event_id: Int32
timestamp: UInt64
message: CharP
@union
class Number:
as_int: Int32
as_double: Double
event = LogEvent(event_id=2, timestamp=1234, message=b"foo")
print(event) # LogEvent(event_id=2, timestamp=1234, message=b'foo')
Typed field aliases
ctypes_plus.types provides Annotated types that map a native Python type
to its ctypes type, so construction and attribute access type-check cleanly.
Plain ctypes types (a: c_int), your own Annotated[..., ctype] aliases and
type aliases of either are all accepted too.
Introspection
>>> from ctypes_plus import asdict, fields
>>> fields(LogEvent)
(Field(name='event_id', type=<class 'ctypes.c_int'>), ...)
>>> asdict(LogEvent(event_id=2, timestamp=1234, message=b"foo"))
{'event_id': 2, 'timestamp': 1234, 'message': b'foo'}
fields accepts a class or instance — including hand-written ctypes types —
and returns a tuple of Field(name, type) records. asdict takes an instance
and returns its fields as a dict.
Licence
Metadata
Release files for ctypes-plus 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ctypes_plus-0.2.0.tar.gz | 5.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ctypes_plus-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.1 kB
Release files / ctypes_plus-0.2.0.tar.gz
| Download URL | ctypes_plus-0.2.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d75ef790347b0a7fbe6a1cdd31a4eaa40d117a796f3e463ccd1f850ce14a8ddf
|
|
BLAKE2b-256 checksum How to use checksums |
359b6e7269b47523bbb8ab36479ad931ff9ef5397ccefcdb69867fbc1964ce8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 29, 2026.
Transparency logRelease files / ctypes_plus-0.2.0-py3-none-any.whl
| Download URL | ctypes_plus-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d1dc49eefff1d19d2e59c9dcda777b1f642e46ff3041ac25206cf703b9cc7ea
|
|
BLAKE2b-256 checksum How to use checksums |
11667a78c7dab14c4102612c47e25db5072ae5817364bd436ed2d9ec6a6a9346
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 29, 2026.
Transparency log