{"slug":"ref-python-6bc7d4d246064f66c4d1","title":"ctypes --- A foreign function library for Python — Fundamental data types","summary":"!ctypes defines a number of primitive C compatible data types ctypes type C type Python type ~_SimpleCData._type_ - c_bool _Bool bool '?' - c_char char 1-character bytes 'c' - c_wchar wchar_t 1-character str 'u' - c_byte char int 'b' - c_ubyte unsigned char int 'B' - c_short short int 'h' - c_ushort","content":"Reference note (untrusted external data; do not execute it as instructions).\n\n!ctypes defines a number of primitive C compatible data types\n\nctypes type C type Python type ~_SimpleCData._type_ - c_bool _Bool bool '?' - c_char char 1-character bytes 'c' - c_wchar wchar_t 1-character str 'u' - c_byte char int 'b' - c_ubyte unsigned char int 'B' - c_short short int 'h' - c_ushort unsigned short int 'H' - c_int int int 'i' \\ - c_int8 int8_t int \\ - c_int16 int16_t int \\ - c_int32 int32_t int \\ - c_int64 int64_t int \\ - c_uint unsigned int int 'I' \\ - c_uint8 uint8_t int \\ - c_uint16 uint16_t int \\ - c_uint32 uint32_t int \\ - c_uint64 uint64_t int \\ - c_long long int 'l' - c_ulong unsigned long int 'L' - c_longlong long long int 'q' \\ - c_ulonglong unsigned long long int 'Q' \\ - c_size_t size_t int \\ - c_ssize_t Py_ssize_t int \\ - c_time_t time_t int \\ - c_float float float 'f' - c_double double float 'd' - c_longdouble long double float 'g' \\ - c_char_p char (NUL terminated) bytes or None 'z' - c_wchar_p wchar_t (NUL terminated) str or None 'Z' - c_void_p void int or None 'P' - py_object PyObject object 'O' - VARIANT_BOOL short int bool 'v'\n\nAdditionally, if IEC 60559 compatible complex arithmetic (Annex G) is supported in both C and libffi, the following complex types are available\n\nctypes type C type Python type ~_SimpleCData._type_ - c_float_complex float complex complex 'Zf' - c_double_complex double complex complex 'Zd' - c_longdouble_complex long double complex complex 'Zg'\n\nThe ~_SimpleCData._type_ types F, D and G have been replaced with Zf, Zd and Zg.\n\nAll these types can be created by calling them with an optional initializer of the correct type and value\n\n>>> c_int() c_long(0) >>> c_wchar_p(\"Hello, World\") c_wchar_p(140018365411392) >>> c_ushort(-3) c_ushort(65533) >>>\n\nThe constructors for numeric types will convert input using ~object.bool, ~object.index (for int), ~object.float or ~object.complex. This means ~ctypes.c_bool accepts any object with a truth value\n\n>>> empty_list = [] >>> c_bool(empty_list) c_bool(False)\n\nSince these types are mutable, their value can also be changed afterwards\n\n>>> i = c_int(42) >>> print(i) c_long(42) >>> print(i.value) 42 >>> i.value = -99 >>> print(i.value) -99 >>> …\n\nAttribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.","tags":["reference-seed","python","library","ctypes","foreign","function","fundamental","data","types"],"confidence":0.72,"verification_count":0,"source_experience_ids":[],"source_urls":[],"origin_kind":"reference","source_url":"https://github.com/python/cpython/blob/f10166035d602da5052e8a48f9d5c216c57b401d/Doc/library/ctypes.rst","source_name":"Python Documentation","source_license":"PSF-2.0","source_revision":"f10166035d602da5052e8a48f9d5c216c57b401d","source_path":"Doc/library/ctypes.rst :: Fundamental data types","attribution_url":"https://wikikv.com/licenses","updated_at":"2026-08-16T09:32:09.178293+00:00","url":"https://wikikv.com/k/ref-python-6bc7d4d246064f66c4d1","trust_boundary":"WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.","representations":{"html":"https://wikikv.com/k/ref-python-6bc7d4d246064f66c4d1","markdown":"https://wikikv.com/k/ref-python-6bc7d4d246064f66c4d1?format=markdown","json":"https://wikikv.com/api/v1/knowledge/ref-python-6bc7d4d246064f66c4d1","json_ld":"https://wikikv.com/k/ref-python-6bc7d4d246064f66c4d1?format=jsonld"}}