Foamlib is an open-source Python package that provides a high-level, modern, object-oriented programming interface for working with OpenFOAM cases and their files. It is designed to simplify the development of workflows that involve running OpenFOAM simulations, as well as pre-and post-processing steps. foamlib understands OpenFOAM's file formats and case structures, and provides an ergonomic, Pythonic API for manipulating cases and files, including a full parser and in-place editor for the latter. It also includes support for running OpenFOAM cases asynchronously and on Slurm-based HPC clusters.