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.

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. Learn more.

Release Information

Removed

  • Support for Python 2.7, 3.5, and 3.6 has been dropped.

Added

  • Support for RFC 4880 OpenPGP private & public keys: pem.OpenPGPPublicKey and pem.OpenPGPPrivateKey. #72
  • Support for intra-payload headers like the ones used in OpenPGP keys using the meta_headers property. #75
  • pem.parse_file() now accepts also pathlib.Path objects.
  • pem.parse() now also accepts str.
  • Added text_payload, bytes_payload and decoded_payload properties to all PEM objects that allow to directly access the payload without the envelope and possible headers. #74

→ Full Changelog

Metadata

Release files for pem 23.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 23.1.0
File Size Uploaded
pem-23.1.0.tar.gz 43.8 kB Details

Built distribution (wheel)

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

Total release size: 53.0 kB

Release files / pem-23.1.0.tar.gz

Download URL pem-23.1.0.tar.gz
Size 43.8 kB
Tags Source
SHA-256 checksum
How to use checksums
06503ff2441a111f853ce4e8b9eb9d5fedb488ebdbf560115d3dd53a1b4afc73
BLAKE2b-256 checksum
How to use checksums
058616c0b6789816f8d53f2f208b5a090c9197da8a6dae4d490554bb1bedbb09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.4

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

Download URL pem-23.1.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78bbb1e75b737891350cb9499cbba31da5d59545f360f44163c0bc751cad55d3
BLAKE2b-256 checksum
How to use checksums
c9978299a481ae6c08494b5d53511e6a4746775d8a354c685c69d8796b2ed482
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

23.1.0 This release

2 release files

21.1.0

2 release files

19.3.0

2 release files

19.1.0

2 release files

18.1.0

2 release files

17.1.0

2 release files

15.0.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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