pymtom-xop


Namepymtom-xop JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummarySOAP MTOM-XOP Support for Python
upload_time2024-03-14 01:39:23
maintainer
docs_urlNone
author
requires_python>=3.10
licenseMIT License Copyright (c) 2023 Gabriel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords soap mtom-xop webservice
VCS
bugtrack_url
requirements attrs bleach build certifi cffi charset-normalizer colorama cryptography docutils exceptiongroup idna importlib-metadata iniconfig isodate jaraco.classes jeepney keyring lxml markdown-it-py mdurl more-itertools packaging pkginfo platformdirs pluggy pycparser Pygments pyproject_hooks pytest pytz PyYAML readme-renderer requests requests-file requests-toolbelt responses rfc3986 rich SecretStorage six tomli twine types-PyYAML urllib3 webencodings zeep zipp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # **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**
``` bash
# 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":

``` xml
<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:

``` python
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:**

- inspired by pymtom by zvolsky (https://github.com/pyutil/pymtom)
- based on requests made with SOAPUI

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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pymtom-xop",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "SOAP,MTOM-XOP,WebService",
    "author": "",
    "author_email": "Gabriel Santos <gabrielsantosm2019@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/17/d4/8f49a087c15a1177202a0e0c76ec72471f42bf020e01cf378247926891e0/pymtom_xop-0.0.2.tar.gz",
    "platform": null,
    "description": "# **SOAP MTOM-XOP Support for Python**\n\nThis library adds SOAP MTOM-XOP support for python 3 using Python Zeep. \n\nThe 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.\n\nIts main actors are the MtomTransport and MtomAttachment classes.\n\n**MtomTransport** inherits from Zeep's Transport class and overrides its post_xml method.\n\n**MtomAttachment** is used to represent each file in the request body.\n\n## **Installation**\n``` bash\n# from PyPI\npip install pymtom-xop\n\n# or from github\npip install git+https://github.com/Gebrel07/pymtom-xop.git@main\n```\n\n## **How to use**\n\nConsider the following type definitions in a WSDL where the operation name is \"UploadFile\":\n\n``` xml\n<xs:complexType name=\"uploadFileWs\">\n    <xs:sequence>\n        <xs:element minOccurs=\"0\" name=\"file\" type=\"xs:base64Binary\"/>\n        <xs:element minOccurs=\"0\" name=\"fileName\" type=\"xs:string\"/>\n        <xs:element minOccurs=\"0\" name=\"fileExtension\" type=\"xs:string\"/>\n    </xs:sequence>\n</xs:complexType>\n```\n\nTo use this Web Service we can use the **MtomTransport** and **MtomAttachment** classes like this:\n\n``` python\nfrom pymtom_xop import MtomAttachment, MtomTransport\nfrom zeep import Client, Settings\n\n# create a MtomAttachment instance to represent the file\n# the \"file\" argument can be a file path or a BytesIO object, in this case, lets use a file stored in the \"documents\" folder\nmtom_attachment = MtomAttachment(file=\"documents/python.pdf\")\n\n# use MtomTransport instead of Zeep's standard Tranport\nmtom_transport = MtomTransport()\n# use the add_files method to add files to the transport\n# the \"files\" argument must be a list of MtomAttachment objects\nmtom_transport.add_files(files=[mtom_attachment])\n\n# set up a Client using MtomTransport\nclient = Client(wsdl=\"documents/UploadWSDL.wsdl\", transport=mtom_transport)\n\n# WARNING: namespace might change according to your Webservice's configuration\nfactory = client.type_factory(namespace=\"ns0\")\n\n# build SOAP Envelope normally using Zeep\n# NOTE: use mtom_attachment's get_cid method to insert the attachment's Content-ID in the \"file\" field\narg0 = factory.uploadFileWs(\n    file=mtom_attachment.get_cid(),\n    fileName=\"python\",\n    fileExtension=\"pdf\"\n)\n\n# call the service normally using Zeep\nresponse = client.service.uploadFile(arg0)\n```\n\n## **Classes**\n\n### **MTOMAttachment:**\n\nThe **MTOMAttachment** class is responsible for setting up all of the necessary information about the file before adding it to the request body.\n\nWhen inserting a file in the SOAP Envelope, the get_cid method must be used in place of the file's binary data.\n\n**Methods**\n\nget_cid:\n\n    Returns cid without the < > parts\n\n    Returns:\n        bytes: File's Content-ID\n\n        Example: b\"168954589437.10472.2748258243972472116@pymtom-xop\"\n\n### **MTOMTransport:**\n\nAfter 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.\n\n**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.\n\nMTOMTransport objects will accept any of zeep Tranport arguments when initialized, such as: cache, timeout, operation_timeout, session etc...\n\n## **Examples**\n\n- See \"documents\" folder for examples of MTOM Request and Response in XML\n- See \"demo.py\" for demonstration of a request \n\n\n## **References:**\n\n- inspired by pymtom by zvolsky (https://github.com/pyutil/pymtom)\n- based on requests made with SOAPUI\n\nSee https://docs.python-zeep.org/en/master/ for Python Zeep's official documentaion.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Gabriel  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "SOAP MTOM-XOP Support for Python",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/Gebrel07/pymtom-xop.git"
    },
    "split_keywords": [
        "soap",
        "mtom-xop",
        "webservice"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "117362671388675ff737b99a190a6a46e6730f5a7631864d6aa72339ef6a98ca",
                "md5": "f62c60c45d215521c8a3779818896d2c",
                "sha256": "c053040341c534d682e5c55ea7e5ce298b7bd0e94474522b6d961d4817f989fe"
            },
            "downloads": -1,
            "filename": "pymtom_xop-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f62c60c45d215521c8a3779818896d2c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10405,
            "upload_time": "2024-03-14T01:39:21",
            "upload_time_iso_8601": "2024-03-14T01:39:21.138098Z",
            "url": "https://files.pythonhosted.org/packages/11/73/62671388675ff737b99a190a6a46e6730f5a7631864d6aa72339ef6a98ca/pymtom_xop-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17d48f49a087c15a1177202a0e0c76ec72471f42bf020e01cf378247926891e0",
                "md5": "efcae1f4b910cda0eeae1679b59b5565",
                "sha256": "281460deb89ea2909be6b5060839e2be95ee5863d3acdcf0b8c3fcddac866073"
            },
            "downloads": -1,
            "filename": "pymtom_xop-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "efcae1f4b910cda0eeae1679b59b5565",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 12381,
            "upload_time": "2024-03-14T01:39:23",
            "upload_time_iso_8601": "2024-03-14T01:39:23.183184Z",
            "url": "https://files.pythonhosted.org/packages/17/d4/8f49a087c15a1177202a0e0c76ec72471f42bf020e01cf378247926891e0/pymtom_xop-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-14 01:39:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Gebrel07",
    "github_project": "pymtom-xop",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "attrs",
            "specs": [
                [
                    "==",
                    "23.1.0"
                ]
            ]
        },
        {
            "name": "bleach",
            "specs": [
                [
                    "==",
                    "6.0.0"
                ]
            ]
        },
        {
            "name": "build",
            "specs": [
                [
                    "==",
                    "0.10.0"
                ]
            ]
        },
        {
            "name": "certifi",
            "specs": [
                [
                    "==",
                    "2023.5.7"
                ]
            ]
        },
        {
            "name": "cffi",
            "specs": [
                [
                    "==",
                    "1.15.1"
                ]
            ]
        },
        {
            "name": "charset-normalizer",
            "specs": [
                [
                    "==",
                    "3.2.0"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    "==",
                    "0.4.6"
                ]
            ]
        },
        {
            "name": "cryptography",
            "specs": [
                [
                    "==",
                    "41.0.2"
                ]
            ]
        },
        {
            "name": "docutils",
            "specs": [
                [
                    "==",
                    "0.20.1"
                ]
            ]
        },
        {
            "name": "exceptiongroup",
            "specs": [
                [
                    "==",
                    "1.1.2"
                ]
            ]
        },
        {
            "name": "idna",
            "specs": [
                [
                    "==",
                    "3.4"
                ]
            ]
        },
        {
            "name": "importlib-metadata",
            "specs": [
                [
                    "==",
                    "6.8.0"
                ]
            ]
        },
        {
            "name": "iniconfig",
            "specs": [
                [
                    "==",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "isodate",
            "specs": [
                [
                    "==",
                    "0.6.1"
                ]
            ]
        },
        {
            "name": "jaraco.classes",
            "specs": [
                [
                    "==",
                    "3.3.0"
                ]
            ]
        },
        {
            "name": "jeepney",
            "specs": [
                [
                    "==",
                    "0.8.0"
                ]
            ]
        },
        {
            "name": "keyring",
            "specs": [
                [
                    "==",
                    "24.2.0"
                ]
            ]
        },
        {
            "name": "lxml",
            "specs": [
                [
                    "==",
                    "4.9.3"
                ]
            ]
        },
        {
            "name": "markdown-it-py",
            "specs": [
                [
                    "==",
                    "3.0.0"
                ]
            ]
        },
        {
            "name": "mdurl",
            "specs": [
                [
                    "==",
                    "0.1.2"
                ]
            ]
        },
        {
            "name": "more-itertools",
            "specs": [
                [
                    "==",
                    "9.1.0"
                ]
            ]
        },
        {
            "name": "packaging",
            "specs": [
                [
                    "==",
                    "23.1"
                ]
            ]
        },
        {
            "name": "pkginfo",
            "specs": [
                [
                    "==",
                    "1.9.6"
                ]
            ]
        },
        {
            "name": "platformdirs",
            "specs": [
                [
                    "==",
                    "3.8.1"
                ]
            ]
        },
        {
            "name": "pluggy",
            "specs": [
                [
                    "==",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "pycparser",
            "specs": [
                [
                    "==",
                    "2.21"
                ]
            ]
        },
        {
            "name": "Pygments",
            "specs": [
                [
                    "==",
                    "2.15.1"
                ]
            ]
        },
        {
            "name": "pyproject_hooks",
            "specs": [
                [
                    "==",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "7.4.0"
                ]
            ]
        },
        {
            "name": "pytz",
            "specs": [
                [
                    "==",
                    "2023.3"
                ]
            ]
        },
        {
            "name": "PyYAML",
            "specs": [
                [
                    "==",
                    "6.0"
                ]
            ]
        },
        {
            "name": "readme-renderer",
            "specs": [
                [
                    "==",
                    "40.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "requests-file",
            "specs": [
                [
                    "==",
                    "1.5.1"
                ]
            ]
        },
        {
            "name": "requests-toolbelt",
            "specs": [
                [
                    "==",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "responses",
            "specs": [
                [
                    "==",
                    "0.23.1"
                ]
            ]
        },
        {
            "name": "rfc3986",
            "specs": [
                [
                    "==",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "rich",
            "specs": [
                [
                    "==",
                    "13.4.2"
                ]
            ]
        },
        {
            "name": "SecretStorage",
            "specs": [
                [
                    "==",
                    "3.3.3"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    "==",
                    "1.16.0"
                ]
            ]
        },
        {
            "name": "tomli",
            "specs": [
                [
                    "==",
                    "2.0.1"
                ]
            ]
        },
        {
            "name": "twine",
            "specs": [
                [
                    "==",
                    "4.0.2"
                ]
            ]
        },
        {
            "name": "types-PyYAML",
            "specs": [
                [
                    "==",
                    "6.0.12.10"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.0.3"
                ]
            ]
        },
        {
            "name": "webencodings",
            "specs": [
                [
                    "==",
                    "0.5.1"
                ]
            ]
        },
        {
            "name": "zeep",
            "specs": [
                [
                    "==",
                    "4.2.1"
                ]
            ]
        },
        {
            "name": "zipp",
            "specs": [
                [
                    "==",
                    "3.16.2"
                ]
            ]
        }
    ],
    "lcname": "pymtom-xop"
}
        
Elapsed time: 0.20347s