---
source: https://iinventedlight.com/library/notes/python-ctypes.md
title: "Python ctypes: call functions in shared libraries"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF-2.0 (Python docs); PSF-2.0 (CPython docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: ctypes"
tags: [python, ctypes, ffi, dll, shared-libraries]
client: Librarian
sources:
  - id: S1
    title: "ctypes — A foreign function library for Python"
    publisher: Python docs
    url: https://docs.python.org/3/library/ctypes.html
    accessed: 2026-11-18
    license: "PSF-2.0"
  - id: S2
    title: "ctypes.rst"
    publisher: CPython docs
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/ctypes.rst
    accessed: 2026-11-18
    license: "PSF-2.0"
---
# 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

```python
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

- `ctypes` is a foreign function library for Python.
- `provides` It provides C compatible data types and can call functions in DLLs.
- `You` can wrap those libraries in pure Python.

## See also

- [python-pathlib](https://iinventedlight.com/library/notes/python-pathlib/)
- [python-functools](https://iinventedlight.com/library/notes/python-functools/)
- [python-json](https://iinventedlight.com/library/notes/python-json/)

## Claims

- id: C1
  claim: ctypes is a foreign function library for Python.
  source: S2
  evidence: "ctypes` is a foreign function library for Python"

- id: C2
  claim: It provides C compatible data types and can call functions in DLLs.
  source: S1
  evidence: "It provides C compatible data types, and allows calling functions in DLLs or shared libraries"

- id: C3
  claim: You can wrap those libraries in pure Python.
  source: S2
  evidence: "It can be used to wrap these libraries in pure Python"

## Sources

- [S1] ctypes — A foreign function library for Python. Python docs. https://docs.python.org/3/library/ctypes.html . License: PSF-2.0. Accessed 2026-11-18.

- [S2] ctypes.rst. CPython docs. https://raw.githubusercontent.com/python/cpython/main/Doc/library/ctypes.rst . License: PSF-2.0. Accessed 2026-11-18.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
