py.typed


Overview

The `py.typed` file is a marker file used in Python packages to indicate that the package includes inline type hints or distributed type stub files (`.pyi`). Its primary purpose is to signal to type checkers (such as `mypy`, `pyright`, or PyCharm’s built-in type checker) that the package supports static type checking.

This file itself contains no executable code or definitions. Instead, it serves as a metadata file that enables the Python typing ecosystem to recognize that the package is **PEP 561 compliant** (i.e., it provides type information).


Purpose and Functionality


Implementation Details


Interaction with the System / Application


Usage Example

Since `py.typed` is a marker file, its usage is implicit:

  1. When you install a package that includes py.typed, your type checker automatically detects the package as typed.

  2. You can then use the package in your Python code with full type checking support, e.g.:

from orjson import dumps, loads

data = {"key": "value"}
json_bytes: bytes = dumps(data)
parsed_data: dict = loads(json_bytes)

Here, the type checker understands the types of `dumps` and `loads` because `orjson` includes `py.typed` and associated type hints.


Visual Diagram

Since `py.typed` is a simple marker file without classes or functions, a flowchart representing its role in the packaging and type checking workflow is appropriate:

flowchart TD
    A[Python Package Directory] --> B[Contains py.typed file]
    B --> C[Package marked as typed]
    C --> D[Type Checkers recognize typing info]
    D --> E[Static analysis & autocompletion enabled]
    A --> F[Includes .pyi files or inline annotations]
    F --> D
    style B fill:#f96,stroke:#333,stroke-width:2px
    style C fill:#bbf,stroke:#333,stroke-width:2px
    style D fill:#afa,stroke:#333,stroke-width:2px
    style E fill:#dfd,stroke:#333,stroke-width:2px

Summary

Aspect

Description

**File Type**

Marker file (empty or contains "partial")

**Purpose**

Indicate package provides type hints (PEP 561)

**Content**

Usually empty

**Effect**

Enables static type checking for the package

**Runtime Impact**

None

**Package Integration**

Placed inside Python package directory (`orjson/py.typed`)

**Tools Affected**

`mypy`, `pyright`, IDEs


References


This minimal but crucial file ensures that the `orjson` Python package is recognized as typed, enabling developers and tools to benefit from the comprehensive type annotations and improving code correctness and developer productivity.