# How to generate an OpenAPI document with Pydantic V2
Source: https://speakeasy.com/openapi/frameworks/pydantic

[Pydantic](https://docs.pydantic.dev/latest/) is considered by many API developers to be the best data validation library for Python, and with good reason. By defining an application's models in Pydantic, developers benefit from a vastly improved development experience, runtime data validation and serialization, and automatic OpenAPI document generation.

However, many developers don't realize they can generate OpenAPI documents from their Pydantic models, which they can then use to create SDKs, documentation, and server stubs.

In this guide, you'll learn how to create new Pydantic models, generate an OpenAPI document from them, and use the generated schema to create an SDK for your API. We'll start with the simplest possible Pydantic model and gradually add more features to show how Pydantic models translate to OpenAPI documents.

## Prerequisites

Before we get started, make sure you have [Python](https://www.python.org/downloads/) 3.8 or higher installed on your machine. Check your Python version by running the following command:

```bash filename="Terminal"
python --version
```

We use Python 3.13.3 in this guide, but any version of Python 3.8 or higher should work.

## Creating a new Python project

First, create a new Python project and install the Pydantic library:

```bash filename="Terminal"