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 XmlRoute
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 = XmlRoute
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.1.0.tar.gz
(10.8 kB
view details)
Built Distribution
File details
Details for the file fastapi_xml-1.1.0.tar.gz
.
File metadata
- Download URL: fastapi_xml-1.1.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc8ae5b1582dedda280ef33e071cebdd2301b23b4f266a996615a2f14bbffd3 |
|
MD5 | 8ef3d3172f3eded08b84672f6d02bd2e |
|
BLAKE2b-256 | 79299c247c4459e513d2f16b550a08930078b57b8a70dbe60c0ef8857a1ffb86 |
File details
Details for the file fastapi_xml-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: fastapi_xml-1.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e202ed48cae16e8364e71e0e70077727096af88addfc67600d4ab46a10ed9683 |
|
MD5 | ee0d226772527610a3a5b0157fce09c8 |
|
BLAKE2b-256 | f2d2e915f4bacd4cafa6f8470b662d91e48f163fa1a4c30ae5a8521c69df7c24 |