Official repository of type stubs for Python standard library and third-party packages
pkg:git/github.com/python/typeshed
npx @tessl/cli install tessl/git-typeshed@0.1.0The official repository of type stubs for the Python standard library and third-party packages. Typeshed provides comprehensive type annotations that enable static type checking, code completion, and other developer tools to understand Python code without needing to execute it.
git clone https://github.com/python/typeshed.gitTypeshed is not directly imported - it provides type information consumed by type checkers:
# Type checkers automatically use typeshed for standard library
import os
import sys
from typing import Dict, List
# Third-party package stubs are installed via pip
# pip install types-requests types-flask
import requests
import flask# mypy configuration (mypy.ini)
[mypy]
python_version = 3.9
warn_return_any = True
warn_unused_configs = True
# pyright configuration (pyrightconfig.json)
{
"pythonVersion": "3.9",
"typeCheckingMode": "basic",
"useLibraryCodeForTypes": true
}# Install type stubs for specific packages
pip install types-requests # For requests library
pip install types-redis # For redis library
pip install types-flask # For Flask framework
# View available stub packages
pip search types-Typeshed is organized into two main directories:
The repository supports Python versions 3.9 through 3.14, with version-specific stubs managed through conditional imports and version checks.
Comprehensive type annotations for Python's built-in modules and packages, covering core functionality like data structures, I/O, networking, concurrency, and system interfaces.
# Examples of stdlib modules with type stubs:
import os # File system operations
import sys # System-specific parameters
import typing # Type hints and generics
import asyncio # Asynchronous programming
import collections # Specialized container datatypes
import functools # Higher-order functions and decorators
import itertools # Functions for creating iterators
import json # JSON encoder/decoder
import re # Regular expression operations
import threading # Thread-based parallelism
import urllib # URL handling modulesType stubs for popular Python packages maintained by the community, enabling type checking for external dependencies.
# Popular third-party packages with type stubs:
import requests # HTTP library
import flask # Web framework
import django # Web framework
import numpy # Scientific computing
import pandas # Data analysis
import matplotlib # Plotting library
import sqlalchemy # Database toolkit
import redis # Redis client
import boto3 # AWS SDK
import pydantic # Data validationAll stub files follow Python's .pyi format with type annotations but no implementation code.
# Example stub file structure (.pyi)
from typing import Any, Optional, Union, overload
from types import TracebackType
class ExampleClass:
def __init__(self, value: str) -> None: ...
@overload
def method(self, arg: str) -> str: ...
@overload
def method(self, arg: int) -> int: ...
def method(self, arg: Union[str, int]) -> Union[str, int]: ...
@property
def value(self) -> str: ...
def function(
required: str,
optional: Optional[int] = None,
*args: Any,
**kwargs: Any
) -> bool: ...Version-specific type information handled through conditional imports and version checks.
import sys
from typing import TYPE_CHECKING
if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias
if TYPE_CHECKING:
from typing_extensions import SelfAutomated testing and validation ensures stub accuracy and completeness.
# Test infrastructure capabilities:
# - Syntax validation for all .pyi files
# - Import testing against target Python versions
# - Consistency checks between stubs and runtime
# - Coverage analysis for public APIs
# - Performance regression testingMost type checkers bundle standard library stubs automatically:
# mypy (includes stdlib stubs)
pip install mypy
mypy your_code.py
# pyright/pylance (includes stdlib stubs)
npm install -g pyright
pyright your_code.pyInstall specific stub packages for external dependencies:
# Individual packages
pip install types-requests types-flask types-redis
# Multiple packages
pip install types-requests types-flask types-redis types-boto3
# Check installed stub packages
pip list | grep types-When type stubs are missing, type checkers may show warnings:
import some_library # type: ignore[import-untyped]
# Or install stub package if available:
# pip install types-some-libraryReport issues to typeshed when stubs don't match runtime behavior:
# If you encounter incorrect type annotations,
# report at: https://github.com/python/typeshed/issuesgit clone https://github.com/python/typeshed.git
cd typeshed
python -m pip install -r requirements-tests.txt# Run all tests
python tests/mypy_test.py
python tests/pyright_test.py
# Test specific stubs
python tests/stubtest_third_party.py requests... for function/method bodies