← All notes

Python ctypes: call functions in shared libraries

Answer: ctypes is a foreign function library for Python. It supplies C compatible data types and can call functions in a DLL or shared library. It can be used to wrap these libraries in pure Python.

Examples

import ctypes
libc = ctypes.CDLL("libc.so.6")

Notes

Some samples reference the c_int type. Where sizeof(long) equals sizeof(int), that type is an alias to c_long. Follow the tutorial in the library docs when you wrap a shared library.

Reference list

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, ctypes — A foreign function library for Python; CPython docs, ctypes.rst. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs, ctypes — A foreign function library for Python; CPython docs, ctypes.rst. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:d4zczrrg

iinventedlight. 2026. "Python ctypes: call functions in shared libraries." iinventedlight Library, iil:note:d4zczrrg, version of 2026-11-18. https://iinventedlight.com/library/notes/python-ctypes/. License: CC-BY-4.0.

@misc{iil_note_d4zczrrg,
  author = {{iinventedlight}},
  title = {{Python ctypes: call functions in shared libraries}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/python-ctypes/},
  note = {Permanent ID iil:note:d4zczrrg. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-ctypes.md.