Python

Python plugin. Generate Python types (pydantic `BaseModel`s, `TypedDict`s and enums) from your GraphQL schema.

Version
0.0.2
Weekly downloads
687
License
MIT
Updated
Oct 29, 2026

Installation

          npm i -D @graphql-codegen/python
        

This plugin generates Python types based on your GraphQLSchema:

  • object & interface types become pydantic BaseModel classes (snake_case attributes; keys that differ from the GraphQL name are pinned with Field(alias=...))
  • input types become TypedDict
  • enums become class X(str, Enum)
  • scalars map to native Python types (ID/String → str, Int → int, Float → float, Boolean → bool, custom scalars → Any)

Given a schema:

type User {
  id: ID!
  name: String!
  email: String
}

The plugin generates:

from typing import Optional
from pydantic import BaseModel


class User(BaseModel):
    id: 'str'
    name: 'str'
    email: 'Optional[str]' = None

It is the base-types counterpart to python-operations, analogous to how typescript underpins typescript-operations.