Skip to main content

adds xml support to fastapi

Project description

FastAPI::XML

tests codecov license languages 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 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


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)

Uploaded Source

Built Distribution

fastapi_xml-1.0.0b1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

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

Hashes for fastapi_xml-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 2258ac4da7215a76a64b351b8d9afe6462194af80578fe6d30e05fc12dfaeff3
MD5 3b8b03bef455787dae14bc3d40f3f40c
BLAKE2b-256 ccca472189b1ee493c29fec4c24cd9bafd198ec7f6d1fd6d9cab8a5af1887b55

See more details on using hashes here.

File details

Details for the file fastapi_xml-1.0.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_xml-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 42111be2efc83cd35d6b243e0ed8fa368da244f92cdff0b7a08ec035b3372ff2
MD5 b4cf765e474093c42ece74b033092103
BLAKE2b-256 0eb60f259654fc3b113a2fdcc11222c03bb793df3c90b801747985087938a5fd

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