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={"examples": ["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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_xml-1.1.1.tar.gz.
File metadata
- Download URL: fastapi_xml-1.1.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7b4f185aed073f79c40f23f976881078ab6867574bebe87a64930fa323ba137
|
|
| MD5 |
3c1490aa8feb57dd9a365a8b3bcd1c1d
|
|
| BLAKE2b-256 |
e52d9c72b6a1139c4f2e30f391ee0e6721f8deb9d5e3c0278a2937e2a2504e44
|
File details
Details for the file fastapi_xml-1.1.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_xml-1.1.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6830f853bd5b127039974409a89970414d460e94c4cb7873c119611efea45929
|
|
| MD5 |
00073473c9667c805925d48e5de11876
|
|
| BLAKE2b-256 |
4447c3b59cc878e6239f7ca2beeb0b3fe865017850b7fcb2a317c0d84e15ac8d
|