pem: Easy PEM file parsing in Python.¶
Release v21.2.0 (What’s new?).
It runs on Python 2.7, and 3.5+, has no dependencies, and does not attempt to interpret the certificate data in any way.
It’s born from the need to load keys, certificates, trust chains, and DH parameters from various certificate deployments: some servers (like Apache) expect them to be a separate file, others (like nginx) expect them concatenated to the server certificate and finally some (like HAProxy) expect key, certificate, and chain to be in one file. With pem, your Python application can cope with all of those scenarios:
>>> import pem >>> certs = pem.parse_file("chain.pem") >>> certs [<Certificate(PEM string with SHA-1 digest '...')>, <Certificate(PEM string with SHA-1 digest '...')>] >>> str(certs) '-----BEGIN CERTIFICATE-----\n...'
Additionally to the vanilla parsing code, pem also contains helpers for Twisted that save a lot of boilerplate code.