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.3.tar.gz (1.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_yaml-0.1.3.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.6.0

File hashes

Hashes for fastapi_yaml-0.1.3.tar.gz
Algorithm Hash digest
SHA256 056f2fc002b356116c20255072c51c848ab6597e722c3f00f88be32b2dfb702b
MD5 c4971cab0a2b3d88c0a467cfff8eb7aa
BLAKE2b-256 1f2646752346eeb3225b4b1a29d8865383b3bde0684ae0a1d6ae82766dda791b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_yaml-0.1.3-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.6.0

File hashes

Hashes for fastapi_yaml-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0c0eab000aed03fd4a48473e5a2fc3edabfe619b3367a5a0de4e101e34460558
MD5 b7b4f945674001f22857bdcc733b1441
BLAKE2b-256 09da7a0b815cbc9a5c5b23d653047406986bed9db887e1262bba44fbf2f55b6e

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