Type stubs for certifi

2021.10.8.3 · deprecated · verified Sun Mar 29

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →