Skip to content

pythogen
Generator of python HTTP-clients from OpenApi specification based on httpx and pydantic.

tests coverage pypi python

Overview

Installation

with pip

pip install pythogen

with docker

docker pull artsmolin/pythogen

Generation

  • path/to/input — path to the directory with openapi.yaml;
  • path/to/output — the path to the directory where the generated client will be saved;

Generate a client using the installed library

pythogen path/to/input/openapi.yaml path/to/output/client.py
or via Docker
docker run \
-v ./path/to/input:/opt/path/to/input \
-v ./path/to/output:/opt/path/to/output \
artsmolin/pythogen \
path/to/input/openapi.yaml \
path/to/output/client.py

Usage

Use the generated client. Below is an example of using a client generated for Petstore OpenAPI.

from petstore.client_async import Client
from petstore.client_async import Pet
from petstore.client_async import EmptyBody
from petstore.client_async import FindPetsByStatusQueryParams

pets: list[Pet] | EmptyBody = await client.findPetsByStatus(
  query_params=FindPetsByStatusQueryParams(status="available"),
)

Examples