The `pem` library is a Python module designed for parsing and splitting PEM (Privacy Enhanced Mail) files, which contain Base64-encoded DER keys and certificates. It is a lightweight tool with no external dependencies, focusing solely on file parsing without interpreting the certificate data itself. The current version is 23.1.0, and it maintains a steady, though not rapid, release cadence.
pip install pemVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a PEM file. It first creates a dummy `example.pem` file with a sample certificate, then uses `pem.parse_file()` to read and extract the PEM objects. The type and a truncated string representation of each found object are printed.
Store PEM files containing sensitive data outside of your repository, preferably in secure storage or environment variables, and load them at runtime. Use `.gitignore` to prevent accidental commits.
Concatenate all necessary certificates (server, intermediate, root) into a single PEM file. Tools like `openssl x509 -in cert.cer -inform DER -outform PEM >> combined.pem` can be used to convert DER and combine PEM files.
Ensure your files are correctly PEM-encoded (i.e., start with `-----BEGIN ...-----` and end with `-----END ...-----`). If you have DER files, convert them to PEM format before using `pem`.
Install the library using pip: `pip install pem`
Ensure the PEM file contains the expected number and type of blocks for the specific function being called. For general parsing with `pem.parse()` or `pem.parse_file()`, ensure the file contains valid PEM formatted data. If dealing with multiple blocks, iterate through the list returned by `pem.parse()` or use `pem.parse_file()` for individual files.
If you need to access detailed attributes of certificates or keys (like subject, issuer, expiry dates, or cryptographic details), use a dedicated cryptography library such as `cryptography` or `PyOpenSSL` to parse the string representation obtained from the `pem` objects.
No dependency data recorded yet.