mirror of
https://github.com/tanrax/python-api-frameworks-benchmark
synced 2026-01-09 06:43:38 +01:00
- Introduced a mapping for endpoint URLs to descriptive names for better clarity in graphs. - Updated the graph generation functions to utilize the new display names. - Adjusted sorting of endpoints and frameworks in the combined graph. - Modified benchmark results in `BENCHMARK_RESULTS.md` to reflect updated performance metrics. - Changed data import in FastAPI, Litestar, Django, and Ninja APIs to use `test_data` instead of `shared.data` for consistency.
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import dataclasses
|
|
from enum import Enum
|
|
|
|
import pydantic
|
|
|
|
|
|
class Species(str, Enum):
|
|
DOG = "Dog"
|
|
CAT = "Cat"
|
|
MONKEY = "Monkey"
|
|
PIG = "Pig"
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class PetDataclass:
|
|
name: str
|
|
age: float
|
|
species: Species = Species.MONKEY
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class PersonDataclass:
|
|
first_name: str
|
|
last_name: str
|
|
id: str
|
|
optional: str | None
|
|
complex: dict[str, list[dict[str, str]]]
|
|
pets: list[PetDataclass]
|
|
|
|
|
|
class PetPydantic(pydantic.BaseModel):
|
|
name: str
|
|
age: float
|
|
species: Species = Species.MONKEY
|
|
|
|
|
|
class PersonPydantic(pydantic.BaseModel):
|
|
first_name: str
|
|
last_name: str
|
|
id: str
|
|
optional: str | None
|
|
complex: dict[str, list[dict[str, str]]]
|
|
pets: list[PetPydantic] = pydantic.Field(len=1)
|
|
|
|
|
|
def load(raw_data: dict) -> tuple[list[PersonPydantic], list[PersonDataclass]]:
|
|
pydantic_data = pydantic.parse_obj_as(list[PersonPydantic], raw_data)
|
|
dataclass_data = []
|
|
for person_data in raw_data:
|
|
kwargs = {**person_data}
|
|
if person_data["pets"]:
|
|
kwargs["pets"] = [PetDataclass(**pet) for pet in person_data["pets"]]
|
|
dataclass_data.append(PersonDataclass(**kwargs))
|
|
return pydantic_data, dataclass_data
|