Skip to main content

pem: PEM file parsing for Python

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.

Release Information

Removed

  • Support for Python 3.8 and 3.9 has been dropped. #140

Added

  • Support for Python 3.15. Use in default, too. #140 #141

Changed

  • pem.parse() doesn't use a single regular expression to match whole PEM objects anymore. That makes parsing time linear with the input size without needing extra memory for large objects.

    The prefixes -----BEGIN and ---- BEGIN, each followed by a space, must not appear inside a PEM body or header value. If pem.parse() finds either prefix there, it drops the current object. #145


Full Changelog →

Metadata

Release files for pem 26.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pem 26.1.0
File Size Uploaded Provenance Actions
pem-26.1.0.tar.gz 198.0 kB With provenance Details for pem-26.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pem 26.1.0
File Interpreter ABI Platform Actions
pem-26.1.0-py3-none-any.whl Python 3 none any Details for pem-26.1.0-py3-none-any.whl

Total release size: 207.1 kB

Release files / pem-26.1.0.tar.gz

Download URL pem-26.1.0.tar.gz
Size 198.0 kB
Tags Source
SHA-256 checksum
How to use checksums
98aa6b7581b782848a46e6a7429c46e1f30bc232558be43ebdc717b7f0fe18d5
BLAKE2b-256 checksum
How to use checksums
b0fa307b94eac6d8f595cef4a3f3a09d47ba32ca2304211d06de852e8a5b89c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / pem-26.1.0-py3-none-any.whl

Download URL pem-26.1.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
440a32eff595c324e2b0654b003183d764c88081c4dd16c95abfc48a7e2f2588
BLAKE2b-256 checksum
How to use checksums
06c73d5679ac24ea03dfd553d5e81ccd6accbf31c2fdbbb869656ba14733a03d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for pem 26.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pem-26.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page