py2xml


Namepy2xml JSON
Version 1.0.5 PyPI version JSON
download
home_pagehttps://github.com/am230/py2xml
SummaryWrite XML with Pythonic Code
upload_time2023-03-16 00:33:47
maintainer
docs_urlNone
authoram230
requires_python
licenseMIT Licence
keywords javascript convert translator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Writing XML with Pythonic code
==============================

.. image:: https://img.shields.io/github/license/mashape/apistatus.svg
   :target: http://opensource.org/licenses/MIT
.. image:: https://badge.fury.io/py/py2xml.svg
    :target: https://badge.fury.io/py/py2xml

Installation
------------

.. code:: bash

    $ pip install py2xml

Usage
-------

.. code:: python

    import py2xml

    # typing attributes
    @py2xml.to_element
    def note(id: int): ...


    messages = py2xml.Element("messages")
    to = py2xml.Element("to")
    from0 = py2xml.Element("from")
    heading = py2xml.Element("heading")
    body = py2xml.Element("body")
    print(
        messages[
            note(id=501)[
                to[
                    "Tove"
                ],
                from0[
                    "Jani"
                ],
                heading[
                    "Reminder"
                ],
                body[
                    "Don't forget me this weekend!"
                ]
            ],
            note(id=502)[
                to[
                    "Jani"
                ],
                from0[
                    "Tove"
                ],
                heading[
                    "Re: Reminder"
                ],
                body[
                    "I will not"
                ]
            ]
        ]
    )


<messages><note id="501"><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note><note id="502"><to>Jani</to><from>Tove</from><heading>Re: Reminder</heading><body>I will not</body></note></messages>

to xml ElementTree
------------------

.. code:: python

    Element.to_xml()

generate code
-------------

.. code:: python

    import py2xml

    print(py2xml.util.generate_code('''<messages>
    <note id="501">
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
    </note>
    <note id="502">
        <to>Jani</to>
        <from>Tove</from>
        <heading>Re: Reminder</heading>
        <body>I will not</body>
    </note>
    </messages>'''))


.. code:: python

    messages = py2xml.Element("messages")
    note = py2xml.Element("note")
    to = py2xml.Element("to")
    from0 = py2xml.Element("from")
    heading = py2xml.Element("heading")
    body = py2xml.Element("body")
    messages[
    note(id="501")[
    to[
    "Tove"
    ],
    from0[
    "Jani"
    ],
    heading[
    "Reminder"
    ],
    body[
    "Don't forget me this weekend!"
    ]
    ],
    note(id="502")[
    to[
    "Jani"
    ],
    from0[
    "Tove"
    ],
    heading[
    "Re: Reminder"
    ],
    body[
    "I will not"
    ]
    ]
    ]

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/am230/py2xml",
    "name": "py2xml",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "javascript,convert,translator",
    "author": "am230",
    "author_email": "am.230@outlook.jp",
    "download_url": "https://files.pythonhosted.org/packages/66/24/d78a3ff0e931780facd8af48b0b622e0323ea217bc5cba8033c32b063c91/py2xml-1.0.5.tar.gz",
    "platform": "any",
    "description": "Writing XML with Pythonic code\n==============================\n\n.. image:: https://img.shields.io/github/license/mashape/apistatus.svg\n   :target: http://opensource.org/licenses/MIT\n.. image:: https://badge.fury.io/py/py2xml.svg\n    :target: https://badge.fury.io/py/py2xml\n\nInstallation\n------------\n\n.. code:: bash\n\n    $ pip install py2xml\n\nUsage\n-------\n\n.. code:: python\n\n    import py2xml\n\n    # typing attributes\n    @py2xml.to_element\n    def note(id: int): ...\n\n\n    messages = py2xml.Element(\"messages\")\n    to = py2xml.Element(\"to\")\n    from0 = py2xml.Element(\"from\")\n    heading = py2xml.Element(\"heading\")\n    body = py2xml.Element(\"body\")\n    print(\n        messages[\n            note(id=501)[\n                to[\n                    \"Tove\"\n                ],\n                from0[\n                    \"Jani\"\n                ],\n                heading[\n                    \"Reminder\"\n                ],\n                body[\n                    \"Don't forget me this weekend!\"\n                ]\n            ],\n            note(id=502)[\n                to[\n                    \"Jani\"\n                ],\n                from0[\n                    \"Tove\"\n                ],\n                heading[\n                    \"Re: Reminder\"\n                ],\n                body[\n                    \"I will not\"\n                ]\n            ]\n        ]\n    )\n\n\n<messages><note id=\"501\"><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note><note id=\"502\"><to>Jani</to><from>Tove</from><heading>Re: Reminder</heading><body>I will not</body></note></messages>\n\nto xml ElementTree\n------------------\n\n.. code:: python\n\n    Element.to_xml()\n\ngenerate code\n-------------\n\n.. code:: python\n\n    import py2xml\n\n    print(py2xml.util.generate_code('''<messages>\n    <note id=\"501\">\n        <to>Tove</to>\n        <from>Jani</from>\n        <heading>Reminder</heading>\n        <body>Don't forget me this weekend!</body>\n    </note>\n    <note id=\"502\">\n        <to>Jani</to>\n        <from>Tove</from>\n        <heading>Re: Reminder</heading>\n        <body>I will not</body>\n    </note>\n    </messages>'''))\n\n\n.. code:: python\n\n    messages = py2xml.Element(\"messages\")\n    note = py2xml.Element(\"note\")\n    to = py2xml.Element(\"to\")\n    from0 = py2xml.Element(\"from\")\n    heading = py2xml.Element(\"heading\")\n    body = py2xml.Element(\"body\")\n    messages[\n    note(id=\"501\")[\n    to[\n    \"Tove\"\n    ],\n    from0[\n    \"Jani\"\n    ],\n    heading[\n    \"Reminder\"\n    ],\n    body[\n    \"Don't forget me this weekend!\"\n    ]\n    ],\n    note(id=\"502\")[\n    to[\n    \"Jani\"\n    ],\n    from0[\n    \"Tove\"\n    ],\n    heading[\n    \"Re: Reminder\"\n    ],\n    body[\n    \"I will not\"\n    ]\n    ]\n    ]\n",
    "bugtrack_url": null,
    "license": "MIT Licence",
    "summary": "Write XML with Pythonic Code",
    "version": "1.0.5",
    "split_keywords": [
        "javascript",
        "convert",
        "translator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6624d78a3ff0e931780facd8af48b0b622e0323ea217bc5cba8033c32b063c91",
                "md5": "95d4487acbb23112a778c3d02775e3e2",
                "sha256": "4fe63f16f18a0929554c3c45905d39b17568533229168efee27343aabb404e1e"
            },
            "downloads": -1,
            "filename": "py2xml-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "95d4487acbb23112a778c3d02775e3e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4572,
            "upload_time": "2023-03-16T00:33:47",
            "upload_time_iso_8601": "2023-03-16T00:33:47.338502Z",
            "url": "https://files.pythonhosted.org/packages/66/24/d78a3ff0e931780facd8af48b0b622e0323ea217bc5cba8033c32b063c91/py2xml-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-16 00:33:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "am230",
    "github_project": "py2xml",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "py2xml"
}
        
Elapsed time: 0.10430s