hynek/pem

PEM file parsing in Python.

Python

171

508 commits

updated Oct 5, 2026

See the code

README

pem: PEM file parsing for Python

Docs License: MIT No AI slop inside. PyPI - Version Downloads / Month OpenSSF Best Practices

pem is a Python module for parsing and splitting of PEM files, i.e. Base64-encoded DER keys and certificates.

It 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 Diffie–Hellman 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[0])
'-----BEGIN CERTIFICATE-----\n...'

Additionally to the vanilla parsing code, pem also contains helpers for Twisted that save a lot of boilerplate code.

Project Information

Credits

pem is written and maintained by Hynek Schlawack.

The development is kindly supported by my employer Variomedia AG and all my amazing GitHub Sponsors.

pem for Enterprise

Available as part of the Tidelift Subscription.

The maintainers of pem and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.

certificate
keys
pem
python
ssl
tls

hynek/pem

PEM file parsing in Python.

Python

171

508 commits

updated Oct 5, 2026

See the code

README

pem: PEM file parsing for Python

Docs License: MIT No AI slop inside. PyPI - Version Downloads / Month OpenSSF Best Practices

pem is a Python module for parsing and splitting of PEM files, i.e. Base64-encoded DER keys and certificates.

It 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 Diffie–Hellman 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[0])
'-----BEGIN CERTIFICATE-----\n...'

Additionally to the vanilla parsing code, pem also contains helpers for Twisted that save a lot of boilerplate code.

Project Information

Credits

pem is written and maintained by Hynek Schlawack.

The development is kindly supported by my employer Variomedia AG and all my amazing GitHub Sponsors.

pem for Enterprise

Available as part of the Tidelift Subscription.

The maintainers of pem and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.

certificate
keys
pem
python
ssl
tls

Project health

Overall

8.1/10

Maintained

5/10

Code review

0/10
OpenSSF Scorecard

PyPI

Latest release

23.1.0 · Jun 21, 2023

Releases this year

0

Significant stargazers

Seth Larson

946 followers · starred May 2023

Jürgen Hötzel

141 followers · starred Aug 2024

Ivan Levkivskyi

300 followers · starred Jun 2018

Jason Pearson

192 followers · starred Apr 2014