ctypes.c_uint64 is the ctypes type for a 64-bit unsigned integer (C uint64_t), with a range of 0 to 18,446,744,073,709,551,615. Use it for timestamps, file sizes, hashes, IDs and any C parameter or struct field that is eight bytes wide.
Python integers have no size limit, so c_uint64 is only needed where the exact width and layout matter, such as C interop or binary formats.
c_uint64 holds its value in eight bytes, exposed through .value.
ctypes aliases the name to the C type of the same size: c_ulong on 64-bit Linux and macOS, and c_ulonglong on 64-bit Windows. That is why you should use c_uint64 instead of c_ulong in portable code.
Out-of-range values wrap silently to the low 64 bits instead of raising an error.
A useful application is a 64-bit hash with wrap-around. This FNV-1a variant keeps the state in a c_uint64:
Use from_buffer_copy for a native-order copy, or int.from_bytes for an explicit byte order.
For a shared buffer, from_buffer on a bytearray or mmap lets you modify the bytes through the ctypes object, as long as the object is large enough and properly aligned for your platform.
C uint64_t parameters need an explicit prototype. Without it ctypes would pass a 32-bit int and drop the high bits.
For your own shared library with a function such as uint64_t add(uint64_t a, uint64_t b):
With both lines set, values up to 2^64 - 1 pass through intact.
On Python 3.14 and later, add _layout_ = "ms" next to _pack_ to avoid a DeprecationWarning. The default layout pads the structure to 16 bytes so the 64-bit field is aligned. Use _pack_ = 1 only when the external format requires it, and never share a packed struct with C code compiled with default alignment.
| Type | Size | Notes |
|---|---|---|
c_uint32 | 4 bytes | 0 to 4,294,967,295 |
c_uint64 | 8 bytes | 0 to 2^64 - 1, fixed width on every platform |
c_ulong | 4 or 8 bytes | 8 on Linux and macOS 64-bit, 4 on Windows |
c_size_t | pointer size | Use for lengths and sizes |
Use c_size_t for sizes and c_uint64 for fixed-width data.
argtypes. ctypes then passes a Python int as a 32-bit C int, and values above 2,147,483,647 raise ArgumentError or lose their high bits.c_ulong in code that must run on Windows and Linux. It is 4 bytes on Windows, so a 64-bit field silently becomes 32 bits there.c_uint64 in a default structure sits on an 8-byte boundary, so the struct is larger than the sum of its fields.c_int64 for values that can be negative, such as offsets from an epoch.c_uint64(x).value == x is only true when x is in range.A quick sanity check is to print ctypes.sizeof of each type and structure and compare it with sizeof in the C program built for the same platform.
Same size, and ctypes maps it to c_ulong or c_ulonglong depending on the platform. Prefer c_uint64 in portable code.
No. It wraps to the low 64 bits.
No. Plain int is unlimited. Use c_uint64 only for C interop or exact 64-bit wrap-around.
Use value.to_bytes(8, "big") or struct.pack(">Q", value).
ctypes.c_uint64 is an eight-byte unsigned integer for uint64_t. It wraps on overflow, aligns to eight bytes in structures, and requires explicit argtypes and restype when calling C. Prefer it over c_ulong for portable code.