pkgconfig
Interface Python with pkg-config
What it is and what it does
pkgconfig is a Python wrapper around the pkg-config command-line tool that lets you query system package metadata programmatically. It exposes functions to check package existence, retrieve versions, extract compiler flags (CFLAGS) and linker flags (LDFLAGS), list all available packages, and parse multiple packages at once. The module is particularly useful in build scripts and setup.py files where you need to dynamically configure C extensions based on installed system libraries.
The package requires Python 3.9 or later and has no Python dependencies—it simply shells out to pkg-config or pkgconf on the system. It is licensed under MIT and marked as production/stable, with active maintenance and support for current Python versions through 3.14.
Use it for:
- Configure C extension builds in setup.py by querying CFLAGS and LDFLAGS for system libraries like GTK or GLib.
- Check whether required system packages are installed and meet version constraints before proceeding with installation or build.
- Discover all available pkg-config packages on a system and extract their metadata for dependency resolution.
- Parse multiple packages in one call to build a unified set of compiler and linker flags for complex multi-library projects.
- Extract custom variables defined in .pc files for packages that expose non-standard build metadata.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
pkgconfig wraps the pkg-config command-line tool to query system package metadata—versions, compiler flags, library paths—from Python code, typically for use in build scripts and extension configuration.
Yes. pkgconfig is a lightweight, stable, actively maintained wrapper with no Python dependencies and permissive licensing. Install it if you need to query system package metadata from Python—especially in build scripts or when configuring C extensions. The only prerequisite is that pkg-config or pkgconf be installed on the system; if that's not available, the module will raise an error at runtime.
Install
pkgconfig on PyPI
pip
pip install pkgconfiguv
uv add pkgconfigpoetry
poetry add pkgconfigInstalling pkgconfig
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of March 2026, supporting Python 3.9 through 3.14. Repository shows recent activity and the project is marked production/stable.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial or open-source projects with minimal restrictions—just retain the license notice.
Quickstart
import pkgconfig
# Check if a package exists
if pkgconfig.exists('glib-2.0'):
version = pkgconfig.modversion('glib-2.0')
cflags = pkgconfig.cflags('glib-2.0')
libs = pkgconfig.libs('glib-2.0')
print(f"Version: {version}, CFLAGS: {cflags}, LIBS: {libs}")
Requires pkg-config or pkgconf command-line tool to be installed and on PATH; raises EnvironmentError if not found.
Verify before relying
- Whether the package handles all edge cases in pkg-config output parsing across different versions of pkg-config and pkgconf.
- Performance characteristics when querying large numbers of packages or complex dependency trees.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0.0,>=3.9.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 161 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,648,684/month — #1,875 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pkgconfig-1.6.0-py3-none-any.whl
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
pkgconfpkgconf is a cross-platform Python package that…
permissive · top 15,000 on PyPI
colcon-pkg-configExtends colcon-core to configure environment…
permissive · top 15,000 on PyPI
distributeDistribute is a legacy compatibility wrapper…
permissive · top 15,000 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
mysqlclientmysqlclient provides a Python interface to…
copyleft · top 1,000 on PyPI
setuptools-git-versioningAutomatically generates PEP 440-compliant…
permissive · top 5,000 on PyPI
donfigDonfig provides a unified configuration system…
permissive · top 5,000 on PyPI
pyconfiguratorParses command-line arguments and INI…
permissive · top 15,000 on PyPI
setuptools-gitA setuptools plugin that automatically includes…
permissive · top 15,000 on PyPI
single-sourceExtracts your package version from…
permissive · top 15,000 on PyPI