{"library":"types-pyopenssl","title":"Typing stubs for pyOpenSSL","description":"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.","status":"active","version":"24.1.0.20240722","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","pyopenssl","security","cryptography","typeshed"],"install":[{"cmd":"pip install types-pyopenssl","lang":"bash","label":"Install types-pyopenssl"}],"dependencies":[{"reason":"Provides the runtime functionality for which these are type stubs.","package":"pyOpenSSL","optional":false}],"imports":[{"symbol":"Connection","correct":"from OpenSSL.SSL import Connection"},{"symbol":"X509","correct":"from OpenSSL.crypto import X509"},{"symbol":"PKey","correct":"from OpenSSL.crypto import PKey"},{"symbol":"Context","correct":"from OpenSSL.SSL import Context"}],"quickstart":{"code":"from OpenSSL import crypto, SSL\nfrom datetime import datetime, timedelta\n\ndef generate_self_signed_cert(\n    common_name: str,\n    country: str,\n    state: str,\n    city: str,\n    organization: str,\n    email: str,\n    valid_days: int = 365,\n) -> tuple[crypto.PKey, crypto.X509]:\n    \"\"\"\n    Generates a self-signed certificate and private key objects with type hints.\n    This demonstrates common pyOpenSSL types like PKey and X509.\n    \"\"\"\n    # Generate a new key pair\n    k = crypto.PKey()\n    k.generate_key(crypto.TYPE_RSA, 2048)\n\n    # Create a self-signed cert\n    cert = crypto.X509()\n    cert.get_subject().C = country\n    cert.get_subject().ST = state\n    cert.get_subject().L = city\n    cert.get_subject().O = organization\n    cert.get_subject().CN = common_name\n    cert.get_subject().emailAddress = email\n    cert.set_serial_number(1000)\n    # Dates must be in UTC. Format 'YYYYMMDDHHMMSSZ'\n    cert.gmtime_before = (datetime.utcnow() - timedelta(days=1)).strftime('%Y%m%d%H%M%SZ')\n    cert.gmtime_after = (datetime.utcnow() + timedelta(days=valid_days)).strftime('%Y%m%d%H%M%SZ')\n    cert.set_issuer(cert.get_subject())\n    cert.set_pubkey(k)\n    cert.sign(k, 'sha256')\n\n    return k, cert\n\n# Example usage with type-hinted variables\nprivate_key: crypto.PKey\ncertificate: crypto.X509\nprivate_key, certificate = generate_self_signed_cert(\n    common_name=\"example.com\",\n    country=\"US\",\n    state=\"CA\",\n    city=\"San Francisco\",\n    organization=\"Example Org\",\n    email=\"admin@example.com\"\n)\n\nprint(\"Generated private key and certificate objects with type hints.\")\nprint(f\"Certificate subject CN: {certificate.get_subject().CN}\")\nprint(f\"Private key type: {private_key.type()}\")","lang":"python","description":"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."},"warnings":[{"fix":"If `pyOpenSSL>=24.2.1` is installed, run `pip uninstall types-pyopenssl`.","message":"pyOpenSSL 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.","severity":"breaking","affected_versions":"pyOpenSSL>=24.2.1"},{"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.","message":"As 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`.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Historically, 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.","severity":"gotcha","affected_versions":"Older versions (specific conflicts are usually resolved in newer stub releases)"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}