adds xml support to fastapi
Project description
FastAPI::XML
pip install fastapi-xml
A bridge between FastAPI and xsdata. Together, fastapi handles xml data structures using dataclasses generated by xsdata. Whilst, fastapi handles the api calls, xsdata covers xml serialisation and deserialization. In addition, openapi support works as well.
from dataclasses import dataclass, field
from fastapi import FastAPI
from fastapi_xml import add_openapi_extension
from fastapi_xml import NonJsonRoute
from fastapi_xml import XmlAppResponse
from fastapi_xml import XmlBody
@dataclass
class HelloWorld:
message: str = field(metadata={"example": "Foo","name": "Message", "type": "Element"})
app = FastAPI(title="FastAPI::XML", default_response_class=XmlAppResponse)
app.router.route_class = NonJsonRoute
add_openapi_extension(app)
@app.post("/echo", response_model=HelloWorld, tags=["Example"])
def echo(x: HelloWorld = XmlBody()) -> HelloWorld:
x.message += " For ever!"
return x
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_xml-1.0.0b1.tar.gz
(14.9 kB
view details)
Built Distribution
File details
Details for the file fastapi_xml-1.0.0b1.tar.gz
.
File metadata
- Download URL: fastapi_xml-1.0.0b1.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2258ac4da7215a76a64b351b8d9afe6462194af80578fe6d30e05fc12dfaeff3 |
|
MD5 | 3b8b03bef455787dae14bc3d40f3f40c |
|
BLAKE2b-256 | ccca472189b1ee493c29fec4c24cd9bafd198ec7f6d1fd6d9cab8a5af1887b55 |
File details
Details for the file fastapi_xml-1.0.0b1-py3-none-any.whl
.
File metadata
- Download URL: fastapi_xml-1.0.0b1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42111be2efc83cd35d6b243e0ed8fa368da244f92cdff0b7a08ec035b3372ff2 |
|
MD5 | b4cf765e474093c42ece74b033092103 |
|
BLAKE2b-256 | 0eb60f259654fc3b113a2fdcc11222c03bb793df3c90b801747985087938a5fd |