Skip to main content

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

exactypes-0.4.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exactypes-0.4.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

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

Hashes for exactypes-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6b0b177cdbcd02e7c22caab29a583eee2eff22757aa6fb98b6cc3a2339bfad19
MD5 4c812113142ed8b69a8c8f2aed74be05
BLAKE2b-256 571187b3eb5f9a36c4d196e11db9553e1906be1e8a3393d0dc687f8aceae68e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for exactypes-0.4.0.tar.gz:

Publisher: python-publish.yml on NCBM/exactypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for exactypes-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ed839195de945b725eea97475ba78db16ed5199b4b95c7fca2b9d461e77ee7e
MD5 f937d8647d235c513b6ae219cbb3eac2
BLAKE2b-256 e7903ff6918ee995f5832db5c0b61e529ee761aff763a5e0b187cbfacec9c56b

See more details on using hashes here.

Provenance

The following attestation bundles were made for exactypes-0.4.0-py3-none-any.whl:

Publisher: python-publish.yml on NCBM/exactypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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