skillfed

pkgconfig

Interface Python with pkg-config

pkgconfig v1.6.0 6.6M downloads/30d#1,875 on PyPI64
Permissive license MIT Active released

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 pkgconfig

uv

uv add pkgconfig

poetry

poetry add pkgconfig

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Software Development :: Build Tools

Tags

pkg-config wrapper pythonquery system libraries metadatacflags ldflags from pythonbuild extension configurationcheck installed package versionsparse pkg-config outputsystem package discovery
build-toolssystem-integration

More Build Tools packages