{"library":"types-cffi","code":"import os\nfrom cffi import FFI\n\n# Initialize FFI\nffi = FFI()\n\n# Declare C functions (e.g., from the standard C library)\nffi.cdef(\"\"\"int puts(const char* s);\"\"\")\n\n# Load the C library (None on Unix-like systems typically opens libc)\ntry:\n    libc = ffi.dlopen(None) # type: ignore\nexcept OSError:\n    print(\"Could not load libc. This example might not run on all systems.\\n\"\\\n          \"Ensure a C standard library is available and discoverable.\")\n    exit(1)\n\n# Call a C function with type checking (implicitly using types-cffi)\nmessage = ffi.new(\"char[]\", b\"Hello from C via CFFI and types-cffi!\")\nreturn_code = libc.puts(message)\n\nprint(f\"C puts() returned: {return_code}\")\n\n# Example of type checking at development time:\n# If you misspelled 'puts' or passed an int instead of bytes, \n# a type checker (like MyPy) would flag it due to types-cffi.","lang":"python","description":"This quickstart demonstrates a basic usage of `cffi` to call a C standard library function, `puts`. When `types-cffi` is installed, a static type checker will provide type hints for `ffi`, `lib`, and other `cffi` objects, helping to catch type-related errors at development time. The example intentionally avoids platform-specific library loading to be more general, using `ffi.dlopen(None)` for Unix-like systems to access the standard C library.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}