Type stubs for certifi

raw JSON →
2021.10.8.3 verified Tue May 12 auth: no python install: stale deprecated

types-certifi is a PEP 561 type stub package providing external type annotations for the `certifi` library, which itself provides Mozilla's carefully curated collection of Root Certificates for validating SSL certificates in Python applications. It is used by static type-checking tools like Mypy and Pyright to analyze code that uses `certifi`. This specific package version (2021.10.8.3) is an older snapshot from the `typeshed` project.

pip install types-certifi
error error: Library stubs not installed for "certifi"
cause Mypy cannot find the necessary type definitions for the `certifi` library, indicating that the `types-certifi` package might not be installed or accessible in the Mypy environment.
fix
Install types-certifi using pip: pip install types-certifi. Ensure your Mypy environment has access to the installed package.
error ModuleNotFoundError: No module named 'types_certifi'
cause The `types-certifi` package provides only type annotations for static analysis and is not meant to be imported at runtime. The actual runtime library that provides the functionality is `certifi`.
fix
Import directly from the certifi library: import certifi. The types-certifi package is automatically used by type checkers when importing certifi.
error error: Module "certifi" has no attribute "get_all_certificates"
cause The installed `types-certifi` package (version 2021.10.8.3) provides older type stubs that do not include definitions for attributes or functions (like `get_all_certificates`) present in a newer version of the runtime `certifi` library being used, or a hypothetical attribute not covered by the stubs.
fix
Upgrade types-certifi to its latest version (pip install --upgrade types-certifi) to ensure type stubs match your certifi runtime version. If no newer stubs are available, you may need to add # type: ignore comments or consider contributing updated stubs.
breaking The `types-certifi` package is obsolete for `certifi` versions 2022.5.18.1 and newer. Starting with `certifi==2022.5.18.1`, the `certifi` library itself includes inline type annotations. If you are using `certifi` 2022.5.18.1 or a newer version (e.g., `certifi==2026.2.25`), you MUST uninstall `types-certifi` to avoid type-checking conflicts and potential errors.
fix Uninstall `types-certifi`: `pip uninstall types-certifi`. Ensure your `certifi` package is up-to-date: `pip install --upgrade certifi`.
gotcha Type stub packages like `types-certifi` are solely for static type checking (e.g., with Mypy, Pyright, or IDEs) and should not be imported or used at runtime. Attempting to import symbols directly from `types_certifi` in your runtime code will result in an `ImportError`.
fix Always import symbols from the original runtime library (`certifi`), not from `types_certifi`. `types-certifi` works implicitly with your type checker.
gotcha Mismatched versions between `types-certifi` and the `certifi` runtime package can lead to incorrect or incomplete type-checking results. While `types-certifi` typically tracks `certifi`'s API, older stub versions may not reflect changes in newer runtime versions. This is particularly relevant given the deprecation mentioned above.
fix Ensure that if you *must* use `types-certifi` (i.e., with an older `certifi` without inline types), its version aligns with the `certifi` version it's stubbing. The safest approach for modern projects is to update `certifi` and remove `types-certifi`.
breaking The `certifi` package (the runtime library) is not installed. This will lead to an `ImportError` at runtime when attempting to import `certifi`.
fix Install `certifi`: `pip install certifi`.
breaking The `certifi` module was not found. This indicates that the `certifi` package itself is not installed in the environment. `certifi` is a fundamental runtime dependency for many Python applications needing TLS/SSL certificate verification.
fix Install `certifi`: `pip install certifi`. Make sure `certifi` is listed in your project's dependencies (e.g., `requirements.txt`).
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - - 17.8M
3.10 alpine (musl) - - - -
3.10 slim (glibc) wheel 1.4s - 18M
3.10 slim (glibc) - - - -
3.11 alpine (musl) wheel - - 19.6M
3.11 alpine (musl) - - - -
3.11 slim (glibc) wheel 1.6s - 20M
3.11 slim (glibc) - - - -
3.12 alpine (musl) wheel - - 11.5M
3.12 alpine (musl) - - - -
3.12 slim (glibc) wheel 1.4s - 12M
3.12 slim (glibc) - - - -
3.13 alpine (musl) wheel - - 11.2M
3.13 alpine (musl) - - - -
3.13 slim (glibc) wheel 1.4s - 12M
3.13 slim (glibc) - - - -
3.9 alpine (musl) wheel - - 17.3M
3.9 alpine (musl) - - - -
3.9 slim (glibc) wheel 1.7s - 18M
3.9 slim (glibc) - - - -

This quickstart demonstrates typical usage of the `certifi` library, for which `types-certifi` provides type stubs. The `certifi.where()` function returns the path to the CA certificate bundle. When `types-certifi` is installed alongside `certifi`, a type checker can statically analyze the usage of `certifi`'s functions and ensure type correctness.

import certifi
import requests
from typing import Text

# certifi.where() provides the path to the CA bundle.
# requests automatically uses certifi for SSL verification.
ca_bundle_path: Text = certifi.where()

def make_secure_request(url: str) -> requests.Response:
    """Makes a secure HTTP GET request using certifi's CA bundle."""
    # Requests typically finds certifi automatically,
    # but explicitly passing certifi.where() ensures its use and enables type checking.
    response: requests.Response = requests.get(url, verify=ca_bundle_path)
    
    response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
    return response

# Example usage:
try:
    secure_response = make_secure_request("https://www.google.com")
    print(f"Successfully connected to {secure_response.url} (Status: {secure_response.status_code})")
    # Type checkers (e.g., Mypy) would use types-certifi to validate
    # the types of `certifi.where()` and related calls here.
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")