Helps creating typed ctypes-based python library
Project description
exactypes
Helps creating typed ctypes-based python library.
Code examples can be found in examples.
Installation
Use pip or whatever package/project managers to install:
pip install exactypes
Features
Better typing support for functions
Defining external functions more conveniently with annotations.
>>> from exactypes import ccall, argtypes as A, restype as R
>>> from ctypes import CDLL
>>> libc = CDLL("libc.so.6") # find your own library
>>> @ccall(libc)
... def printf(fmt: A.c_char_p, *args: A.VaArgs) -> R.c_int:
... pass
...
>>> printf("The answer is %d.\n", 42)
The answer is 42.
18
Better typing support for structures and unions
Defining structures and/or unions like dataclasses.
>>> import ctypes
>>> import typing
>>> from exactypes import Ptr, cstruct
>>> from exactypes import datafield as D
>>> IntArr_8 = typing.Annotated[D.array_of("c_int"), 8]
>>> @cstruct
... class Example(ctypes.Structure):
... a: D.c_int = D.value()
... _padding: typing.ClassVar[D.c_int]
... b: D.c_double = D.value()
... m: Ptr["Example"] = D.value()
... n: IntArr_8 = D.value()
...
>>> a = Example(123, 246, Ptr())
>>> a.m = Ptr(a)
>>> a.m.contents.m.contents.b
246.0
>>> a.n[:]
[0, 0, 0, 0, 0, 0, 0, 0]
Better array interface
Playing with arrays.
>>> from exactypes import array
>>> a = array.of("c_int")(range(10))
>>> a[:]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exactypes-0.4.0.tar.gz.
File metadata
- Download URL: exactypes-0.4.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b0b177cdbcd02e7c22caab29a583eee2eff22757aa6fb98b6cc3a2339bfad19
|
|
| MD5 |
4c812113142ed8b69a8c8f2aed74be05
|
|
| BLAKE2b-256 |
571187b3eb5f9a36c4d196e11db9553e1906be1e8a3393d0dc687f8aceae68e3
|
Provenance
The following attestation bundles were made for exactypes-0.4.0.tar.gz:
Publisher:
python-publish.yml on NCBM/exactypes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
exactypes-0.4.0.tar.gz -
Subject digest:
6b0b177cdbcd02e7c22caab29a583eee2eff22757aa6fb98b6cc3a2339bfad19 - Sigstore transparency entry: 161658763
- Sigstore integration time:
-
Permalink:
NCBM/exactypes@39b6857980c3fb4d8895ba38f8bd43333a63165c -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/NCBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@39b6857980c3fb4d8895ba38f8bd43333a63165c -
Trigger Event:
push
-
Statement type:
File details
Details for the file exactypes-0.4.0-py3-none-any.whl.
File metadata
- Download URL: exactypes-0.4.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ed839195de945b725eea97475ba78db16ed5199b4b95c7fca2b9d461e77ee7e
|
|
| MD5 |
f937d8647d235c513b6ae219cbb3eac2
|
|
| BLAKE2b-256 |
e7903ff6918ee995f5832db5c0b61e529ee761aff763a5e0b187cbfacec9c56b
|
Provenance
The following attestation bundles were made for exactypes-0.4.0-py3-none-any.whl:
Publisher:
python-publish.yml on NCBM/exactypes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
exactypes-0.4.0-py3-none-any.whl -
Subject digest:
6ed839195de945b725eea97475ba78db16ed5199b4b95c7fca2b9d461e77ee7e - Sigstore transparency entry: 161658764
- Sigstore integration time:
-
Permalink:
NCBM/exactypes@39b6857980c3fb4d8895ba38f8bd43333a63165c -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/NCBM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@39b6857980c3fb4d8895ba38f8bd43333a63165c -
Trigger Event:
push
-
Statement type: