CPE: Common Platform Enumeration for Python

1.3.1 · active · verified Thu Apr 16

CPE (Common Platform Enumeration) is a standardized method for describing and identifying applications, operating systems, and hardware devices. The `cpe` Python library (version 1.3.1) provides functionality for parsing, representing, validating, and comparing CPE names across versions 1.1, 2.2, and 2.3 of the CPE specification. It is actively maintained with recent releases focusing on bug fixes and minor feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create CPE objects from different specification versions (URI and 2.2 formatted string) and access their components. It also shows a basic comparison between two CPE objects.

from cpe import CPE

# Create a CPE 2.3 URI-style object (default version if not specified)
cpe_uri_str = 'cpe:/a:hp:insight_diagnostics:8::~~online~win2003~x64~'
cpe_obj_uri = CPE(cpe_uri_str)

print(f"URI-style CPE: {cpe_obj_uri.as_uri()}")
print(f"Vendor: {cpe_obj_uri.get_vendor()}")
print(f"Product: {cpe_obj_uri.get_product()}")

# Create a CPE 2.2 object
cpe_2_2_str = 'cpe:/o:redhat:enterprise_linux:4:update4'
cpe_obj_2_2 = CPE(cpe_2_2_str, CPE.VERSION_2_2)

print(f"\nCPE 2.2 String: {cpe_obj_2_2.as_fs()}") # Formatted String representation
print(f"Operating System: {cpe_obj_2_2.get_part()}")
print(f"Version: {cpe_obj_2_2.get_version()}")

# Example of comparison (requires another CPE object for meaningful comparison)
cpe1 = CPE('cpe:/o:linux:linux_kernel:2.6.32')
cpe2 = CPE('cpe:/o:linux:linux_kernel:2.6.32')
print(f"\nCPE objects are equal: {cpe1 == cpe2}")

view raw JSON →