Registry / auth-security / pyopenssl

pyopenssl

JSON →
library26.4.0pypypi✓ verified 27d ago

PyOpenSSL is a Python wrapper around the OpenSSL library, providing a high-level interface for cryptographic operations. The current version is 26.0.0, with releases following a regular cadence to incorporate updates and fixes.

pip install pyopenssl
INSTALL
IMPORT
SIG · PYOPENSSL
P
pyopenssl
auth-securitypythonv26.4.0
Install
2.7s avg
Import
330ms
Disk
34MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v26.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.338s · 35.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.322s · 36MB
34MB installed
● package 34MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenSSL.crypto
from OpenSSL import crypto
Ensure correct import path to access cryptographic functionalities.

This script demonstrates how to generate a new RSA key pair and create a self-signed certificate using PyOpenSSL.

from OpenSSL import crypto # Generate a new RSA key pair key = crypto.PKey() key.generate_key(crypto.TYPE_RSA, 2048) # Create a self-signed certificate cert = crypto.X509() cert.set_version(2) cert.set_serial_number(1000) cert.get_subject().CN = 'example.com' cert.set_issuer(cert.get_subject()) cert.set_pubkey(key) cert.sign(key, 'sha256') # Save the private key and certificate to files with open('private_key.pem', 'wb') as key_file: key_file.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, key)) with open('certificate.pem', 'wb') as cert_file: cert_file.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert)) print('Private key and certificate have been generated and saved.')
Debug
Known issues
breakingPyOpenSSL version 23.0.0 is incompatible with cryptography version 39.0.0 due to the removal of the 'x509' module.
fix
Upgrade PyOpenSSL to a version compatible with cryptography 39.0.0 or later.
affects: 23.0.0
deprecatedThe 'load_pkcs12' function in PyOpenSSL is deprecated and may be removed in future versions.
fix
Use alternative methods for handling PKCS12 files.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'OpenSSL'
The pyopenssl library (which provides the OpenSSL package) is not installed or not accessible in the current Python environment.
fix
pip install pyopenssl
OpenSSL.SSL.Error: [('PEM routines', 'PEM_read_bio', 'no start line')]
The file or data provided for loading a certificate or private key does not contain valid PEM-encoded data, missing the expected 'BEGIN' line.
fix
Ensure the certificate or key data is correctly formatted as PEM, starting with `-----BEGIN...` and ending with `-----END...`.
TypeError: argument of type 'str' is not iterable
Functions like `OpenSSL.crypto.load_certificate` expect byte strings for certificate/key data, but a regular string was provided.
fix
Encode the certificate/key string to bytes before passing it:
```python
cert_string = "..."
cert_bytes = cert_string.encode('utf-8')
cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert_bytes)
```
AttributeError: module 'OpenSSL.SSL' has no attribute 'TLSv1_2_METHOD'
Direct protocol methods like `TLSv1_2_METHOD` are deprecated in newer pyopenssl versions; use `TLS_METHOD` with explicit version settings.
fix
Use the generic `TLS_METHOD` and then set the minimum/maximum protocol versions on the context:
```python
context = OpenSSL.SSL.Context(OpenSSL.SSL.TLS_METHOD)
context.set_min_proto_version(OpenSSL.SSL.TLS1_2_VERSION)
context.set_max_proto_version(OpenSSL.SSL.TLS1_2_VERSION)
```
Upgrade
Version history
26.4.0latest on PyPI · released Aug 1, 2026
Audit
Dependencies
cryptographyrequiredProvides cryptographic recipes and primitives; required for PyOpenSSL to function properly.
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
pyopenssl — pip install pyopenssl · libregistry