Skip to main content

No project description provided

Project description

FastAPI Soap

This package helps to create Soap WebServices using FastAPI (What?!?!)

Motivation

I know, FastAPI is a REST micro framework, but sometimes is needed to expose a Soap Interface on a already running FastAPI application for an legacy client/application that only supports, well, the Soap protocol...

Installation and dependencies

Only FastAPI, Pydantic and Pydantic XML are required.

First steps

from fastapi import FastAPI
from pydantic_xml import element
from fastapi_soap import SoapRouter, XMLBody, SoapResponse
from fastapi_soap.models import BodyContent


class Operands(BodyContent, tag="Operands"):
    operands: list[float] = element(tag="Operand")

class Result(BodyContent, tag="Result"):
    value: float

soap = SoapRouter(name='Calculator', prefix='/Calculator')

@soap.operation(
    name="SumOperation",
    request_model=Operands,
    response_model=Result
)
def sum_operation(body: Operands = XMLBody(Operands)):
    """
    Receives an Operands object and returns a Result object.

    Args:
        body (Operands): Operands object with a list of operands
    """
    result = sum(body.operands)
    
    return SoapResponse(
        Result(value=result)
    )


app = FastAPI()

app.include_router(soap)

if __name__ == '__main__':
    import uvicorn  # Any Python ASGI web server can be used
    uvicorn.run("example.main:app")

(This script is complete, it should run "as is")

The WSDL is available on webservice root path for GET method.

GET http://localhost:8000/Calculator?wsdl

Examples

XML Request

<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <Operands>
            <!--Zero or more repetitions:-->
            <Operand>1</Operand>
            <Operand>2</Operand>
            <Operand>3</Operand>
        </Operands>
</soapenv:Envelope>

For this example, the sum_operation function will receive an Pydantic object as body

print(body)
# Output Operands(operands=[1.0, 2.0, 3.0])

print(body.operands)
# Output [1.0, 2.0, 3.0]

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_soap-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

fastapi_soap-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_soap-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_soap-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/6.2.0-31-generic

File hashes

Hashes for fastapi_soap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dda3e1e0d6f981ba5985903e6b545ad04addc2a1ab9d537ea32c14485ed2eb84
MD5 284eb8a2761da51c9f6751bb60eb78be
BLAKE2b-256 0695c8aa4dc0b0f44492da35dc4b71148e9f6db06ac61c9235b09fd9927b2237

See more details on using hashes here.

File details

Details for the file fastapi_soap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_soap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/6.2.0-31-generic

File hashes

Hashes for fastapi_soap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f57c90f8538b98bb85f7a1f62ec17e0687163b38ebacf58454a6b4643d76891
MD5 1b4f0739ddaecbda37d2ee356f921ebe
BLAKE2b-256 6d564e4659f1cc5dd0d5f0af033a0374bd48d4a6cbffced35e003ff14acda93e

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