py.typed


Overview

The file **`py.typed`** is a special marker file used in Python projects to indicate that the package contains [type hints](https://www.python.org/dev/peps/pep-0561/) compliant with [PEP 561](https://www.python.org/dev/peps/pep-0561/). Its presence signals to type checkers (like `mypy`, `pyright`, or IDEs with type inference) that the package includes inline type annotations or stub files, enabling enhanced static type checking for consumers of the package.

Unlike typical Python source code files, `py.typed` is usually empty and does not contain executable code, classes, or functions. Instead, it serves as a metadata marker recognized by tooling in the Python ecosystem.


Purpose and Functionality


Usage Example

Suppose you publish a package named `example_pkg` with type annotations:

example_pkg/
├── __init__.py
├── module.py        # contains type hints in its functions and classes
└── py.typed         # marker file (empty)

Important Implementation Details


Interaction with Other Parts of the System


Diagram

Since this file is a simple marker file without classes or functions, a flowchart illustrating its role in the type checking workflow is more appropriate than a class or component diagram.

flowchart TD
    A[Python Package]
    B[py.typed file present?]
    C[Type Checker (mypy, pyright)]
    D[Enable static type checking]
    E[Assume untyped package]
    
    A --> B
    B -- Yes --> C
    B -- No --> E
    C --> D

Summary

Aspect

Description

File type

Marker file (empty or contains "partial")

Purpose

Indicate package contains type information

Location

Root directory of Python package

Usage

Enables type checkers to apply static analysis

Related PEP

PEP 561

Packaging Requirement

Must be included in distributed package


References


This concludes the comprehensive documentation for the `py.typed` file.