Skip to main content

adds xml support to fastapi

Project description

FastAPI::XML

tests codecov license CodeFactor versions

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.

Swagger Example

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


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

Uploaded Source

Built Distribution

fastapi_xml-1.1.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for fastapi_xml-1.1.1.tar.gz
Algorithm Hash digest
SHA256 c7b4f185aed073f79c40f23f976881078ab6867574bebe87a64930fa323ba137
MD5 3c1490aa8feb57dd9a365a8b3bcd1c1d
BLAKE2b-256 e52d9c72b6a1139c4f2e30f391ee0e6721f8deb9d5e3c0278a2937e2a2504e44

See more details on using hashes here.

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

Hashes for fastapi_xml-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6830f853bd5b127039974409a89970414d460e94c4cb7873c119611efea45929
MD5 00073473c9667c805925d48e5de11876
BLAKE2b-256 4447c3b59cc878e6239f7ca2beeb0b3fe865017850b7fcb2a317c0d84e15ac8d

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