or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdstdlib-stubs.mdthird-party-stubs.md
tile.json

tessl/git-typeshed

Official repository of type stubs for Python standard library and third-party packages

Workspace
tessl
Visibility
Public
Created
Last updated
Describes

pkg:git/github.com/python/typeshed

To install, run

npx @tessl/cli install tessl/git-typeshed@0.1.0

index.mddocs/

Typeshed

The 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.

Package Information

  • Package Name: typeshed
  • Package Type: Git Repository
  • Language: Python Type Stubs (.pyi files)
  • Repository: git clone https://github.com/python/typeshed.git
  • Usage: Bundled with type checkers (mypy, pyright, PyCharm)

Core Imports

Typeshed 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

Basic Usage

Using with Type Checkers

# 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
}

Installing Third-party Stubs

# 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-

Architecture

Typeshed is organized into two main directories:

  • stdlib/: Type stubs for Python standard library modules (742+ .pyi files)
  • stubs/: Type stubs for 188+ third-party packages, each in separate directories
  • tests/: Test infrastructure ensuring stub accuracy and completeness
  • scripts/: Automation tools for maintenance and validation

The repository supports Python versions 3.9 through 3.14, with version-specific stubs managed through conditional imports and version checks.

Capabilities

Standard Library Type Stubs

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 modules

Standard Library Stubs

Third-party Package Stubs

Type 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 validation

Third-party Stubs

Type Stub Structure

All 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 Support

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 Self

Quality Assurance

Automated 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 testing

Installation Methods

Type Checker Integration

Most 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.py

Third-party Stub Installation

Install 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-

Error Handling

Missing Stubs

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-library

Stub Inconsistencies

Report issues to typeshed when stubs don't match runtime behavior:

# If you encounter incorrect type annotations,
# report at: https://github.com/python/typeshed/issues

Contributing

Development Setup

git clone https://github.com/python/typeshed.git
cd typeshed
python -m pip install -r requirements-tests.txt

Running Tests

# Run all tests
python tests/mypy_test.py
python tests/pyright_test.py

# Test specific stubs
python tests/stubtest_third_party.py requests

Stub Guidelines

  • Follow PEP 484, 585, 586, 612, 613 type hinting standards
  • Match runtime behavior exactly
  • Use ... for function/method bodies
  • Provide complete type information for public APIs
  • Support multiple Python versions when applicable