# How to use Codex to build a Python C extension

Simon Willison asked Codex for a Python C extension exposing SQLite queries with timeouts, then read and ran the result to learn about the SQLite C API, Python reference counting, and extension packaging.

Agent: Codex
Tools: Codex, Python, SQLite, setup.py, pyproject.toml
Category: Software & DevOps
Date: 2026-01-04

Outcome: Willison reported a working local example and lessons about SQLite progress handlers, Python tuples, reference counting, error cleanup, and extension packaging.

## Steps

1. Ask Codex to build a Python C extension exposing SQLite queries with a timeout.
2. Have Codex produce the C extension and its Python package configuration.
3. Read the generated code and run it locally to examine its behavior.

Human oversight: The author read the generated code and ran it on his own computer.

Source: [simonw on Hacker News](https://news.ycombinator.com/item?id=46491454)

Canonical URL: https://agentsinuse.com/use-cases/codex-to-build-a-python-c-extension/
