Skip to content

Archive

Import System

1 articles
Python 09 Sep 2026 14 min read

Detect Python Packages with inspect.ispackage

Python tools often need to answer a deceptively simple question: is this imported object a package or an ordinary module? That distinction matters to plugin loaders, documentation generators, test discovery systems, command-line frameworks, code indexers, and developer tools. A package can contain importable children. An ordinary module cannot be traversed in the same way. Python 3.14 adds inspect.ispackage(), a small predicate that gives this question a standard-library name. import inspect import json import pathlib print(inspect.ispackage(json)) # True print(inspect.ispackage(pathlib)) # False The API is tiny. The surrounding import semantics are not.