Core APIΒΆ

The core API call are the function pem.parse() and the its convenience helper pem.parse_file():

import pem

with open("cert.pem", "rb") as f:
   certs = pem.parse(f.read())

# or:

certs = pem.parse_file("cert.pem")

The function returns a list of valid PEM objects found in the string supplied.

  • They can be transformed using str(obj) into native strings,

  • or using obj.as_text() into Unicode text (str on Python 3, unicode on Python 2),

  • or using obj.as_bytes() into bytes.

  • Additional you can obtain the SHA-1 hexdigest using obj.hashdigest() for quick comparison of objects.