Skip to main content

SOAP MTOM-XOP Support for Python

This library adds SOAP MTOM-XOP support for python 3 using Python Zeep.

The library uses custom classes to override the behavior of Python Zeep, tranforming a basic SOAP message into a MTOM-XOP message before handling it back to Zeep to be sent in a POST request.

Its main actors are the MtomTransport and MtomAttachment classes.

MtomTransport inherits from Zeep's Transport class and overrides its post_xml method.

MtomAttachment is used to represent each file in the request body.

Installation

# from PyPI
pip install pymtom-xop

# or from github
pip install git+https://github.com/Gebrel07/pymtom-xop.git@main

How to use

Consider the following type definitions in a WSDL where the operation name is "UploadFile":

<xs:complexType name="uploadFileWs">
    <xs:sequence>
        <xs:element minOccurs="0" name="file" type="xs:base64Binary"/>
        <xs:element minOccurs="0" name="fileName" type="xs:string"/>
        <xs:element minOccurs="0" name="fileExtension" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

To use this Web Service we can use the MtomTransport and MtomAttachment classes like this:

from pymtom_xop import MtomAttachment, MtomTransport
from zeep import Client, Settings

# create a MtomAttachment instance to represent the file
# the "file" argument can be a file path or a BytesIO object, in this case, lets use a file stored in the "documents" folder
mtom_attachment = MtomAttachment(file="documents/python.pdf")

# use MtomTransport instead of Zeep's standard Tranport
mtom_transport = MtomTransport()
# use the add_files method to add files to the transport
# the "files" argument must be a list of MtomAttachment objects
mtom_transport.add_files(files=[mtom_attachment])

# set up a Client using MtomTransport
client = Client(wsdl="documents/UploadWSDL.wsdl", transport=mtom_transport)

# WARNING: namespace might change according to your Webservice's configuration
factory = client.type_factory(namespace="ns0")

# build SOAP Envelope normally using Zeep
# NOTE: use mtom_attachment's get_cid method to insert the attachment's Content-ID in the "file" field
arg0 = factory.uploadFileWs(
    file=mtom_attachment.get_cid(),
    fileName="python",
    fileExtension="pdf"
)

# call the service normally using Zeep
response = client.service.uploadFile(arg0)

Classes

MTOMAttachment:

The MTOMAttachment class is responsible for setting up all of the necessary information about the file before adding it to the request body.

When inserting a file in the SOAP Envelope, the get_cid method must be used in place of the file's binary data.

Methods

get_cid:

Returns cid without the < > parts

Returns:
    bytes: File's Content-ID

    Example: b"168954589437.10472.2748258243972472116@pymtom-xop"

MTOMTransport:

After calling the service's operation, Zeep will parse the SOAP message as it normally does. The SOAP message and HTTP headers will be passed on to the MTOMTransport class.

MTOMTransport uses its methods to transform the SOAP message into a MTOM-XOP message, adds the necessary HTTP headers and gives it back to Zeep to be sent as a POST request.

MTOMTransport objects will accept any of zeep Tranport arguments when initialized, such as: cache, timeout, operation_timeout, session etc...

Examples

  • See "documents" folder for examples of MTOM Request and Response in XML
  • See "demo.py" for demonstration of a request

References:

See https://docs.python-zeep.org/en/master/ for Python Zeep's official documentaion.

Metadata

Release files for pymtom-xop-fork 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymtom-xop-fork 0.0.3
File Size Uploaded
pymtom_xop_fork-0.0.3.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymtom-xop-fork 0.0.3
File Interpreter ABI Platform
pymtom_xop_fork-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.2 kB

Release files / pymtom_xop_fork-0.0.3.tar.gz

Download URL pymtom_xop_fork-0.0.3.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
596be5dfe0aad3abd05937fd8350ad4c50e6b7a65810be3649136afdfefbfec2
BLAKE2b-256 checksum
How to use checksums
8ced5d48390833658b8591e8a69ebfcd55f19cf07abd7ee817708e0357192c30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.

Transparency log

Release files / pymtom_xop_fork-0.0.3-py3-none-any.whl

Download URL pymtom_xop_fork-0.0.3-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2231d6d622a910c24e6943e1220c4dde1fe1d3ddfe7de7bc94e5cfd1ab919df
BLAKE2b-256 checksum
How to use checksums
939cb6c4a78f2acf8233e9a7489d774c5ec82732753591fa9964aadb41e0de9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page