Registry / type-stubs / types-pyopenssl

types-pyopenssl

JSON →
library24.1.0.20240722pypypi✓ verified 26d ago

This is a PEP 561 type stub package for the pyOpenSSL library. It allows type-checking tools like mypy, pyright, and PyCharm to analyze code that uses pyOpenSSL. The current version, 24.1.0.20240722, aims to provide accurate annotations for `pyOpenSSL==24.1.*`. Maintained within Typeshed, updates to these stubs are released frequently, typically up to once a day.

pip install types-pyopenssl
INSTALL
IMPORT
SIG · TYPES-PYOPENSSL
T
types-pyopenssl
type-stubspythonv24.1.0.20240722
Install
2.5s avg
Import
Disk
34MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v24.1.0.20240722 · 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.000s · 35.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.000s · 36MB
34MB installed
● package 34MB
Code
Verified usage

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

Connection
from OpenSSL import SSL
from OpenSSL-stubs.SSL import Connection

This quickstart demonstrates how to use `types-pyopenssl` by creating a self-signed certificate and private key, showcasing type annotations for common `pyOpenSSL` objects like `PKey` and `X509`. Type checkers would use these stubs to validate the types in such code.

from OpenSSL import crypto, SSL from datetime import datetime, timedelta def generate_self_signed_cert( common_name: str, country: str, state: str, city: str, organization: str, email: str, valid_days: int = 365, ) -> tuple[crypto.PKey, crypto.X509]: """ Generates a self-signed certificate and private key objects with type hints. This demonstrates common pyOpenSSL types like PKey and X509. """ # Generate a new key pair k = crypto.PKey() k.generate_key(crypto.TYPE_RSA, 2048) # Create a self-signed cert cert = crypto.X509() cert.get_subject().C = country cert.get_subject().ST = state cert.get_subject().L = city cert.get_subject().O = organization cert.get_subject().CN = common_name cert.get_subject().emailAddress = email cert.set_serial_number(1000) # Dates must be in UTC. Format 'YYYYMMDDHHMMSSZ' cert.gmtime_before = (datetime.utcnow() - timedelta(days=1)).strftime('%Y%m%d%H%M%SZ') cert.gmtime_after = (datetime.utcnow() + timedelta(days=valid_days)).strftime('%Y%m%d%H%M%SZ') cert.set_issuer(cert.get_subject()) cert.set_pubkey(k) cert.sign(k, 'sha256') return k, cert # Example usage with type-hinted variables private_key: crypto.PKey certificate: crypto.X509 private_key, certificate = generate_self_signed_cert( common_name="example.com", country="US", state="CA", city="San Francisco", organization="Example Org", email="admin@example.com" ) print("Generated private key and certificate objects with type hints.") print(f"Certificate subject CN: {certificate.get_subject().CN}") print(f"Private key type: {private_key.type()}")
Debug
Known issues
breakingpyOpenSSL versions 24.2.1 and newer now include their own type annotations (a `py.typed` file). If you are using `pyOpenSSL>=24.2.1`, you should uninstall `types-pyopenssl` to prevent potential conflicts and ensure correct type checking behavior.
fix
If `pyOpenSSL>=24.2.1` is installed, run `pip uninstall types-pyopenssl`.
affects: pyOpenSSL>=24.2.1
gotchaAs a stub-only package maintained in Typeshed, updates to `types-pyopenssl` might lag behind new releases of the main `pyOpenSSL` library. This can lead to 'stale' type annotations that don't cover the latest features or API changes in `pyOpenSSL`.
fix
Consider pinning `types-pyopenssl` to a specific version for stability, but be aware this might mean missing out on recent type improvements. Alternatively, check Typeshed's GitHub for the latest stub updates and contribute if you find missing annotations.
affects: All versions
gotchaThe `types-pyopenssl` package is explicitly marked as 'partial' in Typeshed. This indicates that some parts of the `pyOpenSSL` API may not have complete or accurate type annotations, potentially leading to `Any` types or type checker errors in certain scenarios.
fix
If encountering missing or incorrect annotations, consult the `pyOpenSSL` runtime documentation. For long-term solutions, consider contributing improvements to the `pyOpenSSL` stubs in the Typeshed repository.
affects: All versions
gotchaHistorically, stub packages from Typeshed, including `types-pyopenssl`, have sometimes had implicit or explicit dependencies on other stub packages (e.g., `types-cryptography`). If an upstream library (like `cryptography`) later includes its own `py.typed` file, this can cause conflicts or incorrect type resolution if both the upstream library's native stubs and the Typeshed stub package are present.
fix
Regularly review your project's `pip freeze` output and type checker logs for warnings about conflicting type providers. Remove redundant stub packages if the upstream library now provides its own `py.typed` file.
affects: Older versions (specific conflicts are usually resolved in newer stub releases)
breakingThe `types-pyopenssl` package provides type annotations for the `pyOpenSSL` library but does not install `pyOpenSSL` itself. If `pyOpenSSL` is not installed, importing `OpenSSL` will result in a `ModuleNotFoundError` at runtime, as the core library is missing.
fix
Ensure that the `pyOpenSSL` library is installed alongside `types-pyopenssl`. You can install it by running `pip install pyOpenSSL`.
affects: All versions
breakingThe `types-pyopenssl` package provides type annotations for `pyOpenSSL` but does not include the `pyOpenSSL` runtime library itself. To use `pyOpenSSL`, you must install it separately (e.g., `pip install pyOpenSSL`). Without the main library, importing `OpenSSL` will result in a `ModuleNotFoundError`.
fix
Install the `pyOpenSSL` library in addition to `types-pyopenssl` (e.g., `pip install pyOpenSSL`).
affects: All versions
Upgrade
Version history
24.1.0.20240722latest on PyPI · released Jul 22, 2024
Audit
Dependencies
pyOpenSSLrequiredProvides the runtime functionality for which these are type stubs.
Agent activity
41 hits · last 30 days
node
36
OpenAI (training)
1
Resources
types-pyopenssl — pip install types-pyopenssl · libregistry