Skip to main content

Handle YAML data in FastAPI

Project description

Overview

Handle YAML requests with FastAPI.

Installation

pip install fastapi-yaml

Usage

FastAPI Code:

from fastapi import FastAPI
from fastapi_yaml import YamlRoute
from pydantic import BaseModel

app = FastAPI()
app.router.route_class = YamlRoute

class Person(BaseModel, extra='forbid'):
    name: str
    age: int

@app.post("/person")
def person(person: Person):
    return f"{person.name} is {person.age} years old"

HTTP Request:

curl --request POST \
  --url http://localhost:8000/person \
  --header "content-type: application/x-yaml" \
  --data "name: John Doe\nage: 42"

Tests

poetry run pytest --cov fastapi_yaml tests/

Coverage

---------- coverage: platform darwin, python 3.11.2-final-0 ----------
Name                       Stmts   Miss  Cover
----------------------------------------------
fastapi_yaml/__init__.py       1      0   100%
fastapi_yaml/main.py          20      0   100%
----------------------------------------------
TOTAL                         21      0   100%

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_yaml-0.1.2.tar.gz (1.8 kB view details)

Uploaded Source

Built Distribution

fastapi_yaml-0.1.2-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_yaml-0.1.2.tar.gz.

File metadata

  • Download URL: fastapi_yaml-0.1.2.tar.gz
  • Upload date:
  • Size: 1.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.2 Darwin/22.5.0

File hashes

Hashes for fastapi_yaml-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3fbc82ac99958e9aa1c524e839ae4ca471dd831bd27e0afd4d89803d9fdb3897
MD5 5f3be02050c4761b1c676f5c0f49d3de
BLAKE2b-256 ea5ddd2e1c0eab10a5925eaf659a212980b55708681208c3a2936f9c01e67503

See more details on using hashes here.

File details

Details for the file fastapi_yaml-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fastapi_yaml-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 2.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.2 Darwin/22.5.0

File hashes

Hashes for fastapi_yaml-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf412db8d4db1e119b6dec263816ab9b822ab34c418249d9b8764c98b6f22d09
MD5 9358eac4159acbb432890c4cdb83ff6c
BLAKE2b-256 f1415d8902e85a3d2bb8d5ebd5842bedbad76c32a55fd9a873360bb8e6012612

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page