What am I
Py-xmler is a python package for converting python dictionaries into valid XML. Most XML conversion utilities out there don't seem to provide any namespace support, which was my main reason for creating this package. Inspiration was drawn from the current most popular dictionary to XML conversion utility dicttoxml.
Details
Py-xmler has a very specific api that it abides by and, for now, doesn't have very good error handling. Getting namespace support with python dictionaries is not easy so there may be some quirks.
To be used with this package your dictionary must be formatted in the following way:
from pyxmler import dict2xml
myDict = {
"RootTag": {
"@ns": "soapenv",
"@attrs": {
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/"
},
"childTag": {
"@attrs": {
"someAttribute": "colors are nice"
},
"grandchild": "This is a text tag"
}
}
}
print(dict2xml(myDict, pretty=True))
Which will return the following XML:
<soapenv:RootTag xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<childTag someAttribute="colors are nice">
<grandchild>This is a text tag</grandchild>
</childTag>
</soapenv:RootTag>
As you can see if a key is given a string rather than a dictionary it becomes a text tag.
API
Options
@ns
The namespace option. Adds the supplied namespace to the element.
Example:
Python input:
myDict = {
"RootTag": {
"@ns": "soapenv"
}
}
Pretty XML Output:
<soapenv:RootTag />
@attrs
The attributes option takes a dictionary of attributes. The key for each becomes the attribute itself, while the value becomes the attribute's value.
Example:
Python input:
myDict = {
"RootTag": {
"@ns": "soapenv",
"@attrs": {
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/"
}
}
}
Pretty XML Output:
<soapenv:RootTag xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" />
@name
Changes the name of the tag.
Example:
Python input:
myDict = {
"RootTag": {
"@ns": "soapenv",
"@attrs": {
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/"
},
"@name": "SomethingElse"
}
}
Pretty XML Output:
<soapenv:SomethingElse xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" />
@value
Allows you to give the tag a string value rather than having nested tags.
Example:
Python input:
myDict = {
"RootTag": {
"@ns": "soapenv",
"@attrs": {
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/"
},
"@value": "Namespace test",
"@name": "SomethingElse"
}
}
Pretty XML Output:
<soapenv:SomethingElse xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">Namespace test</soapenv:SomethingElse>
Tags
Tags are defined by using a key value for the dictionary that does not start with a @. For now no syntax checking is being done on tag names, so use this wisely.
The value of the dictionary key can be either a dictionary or a string. If a dictionary is used you can define a namespace, attributes, name, and value for the tag. If a string is supplied you can only have a basic tag with text content.
Example:
# The following two tags are exactly the same,
# but defined in a different way
myDict = {
"SomeTag": {
"@value": "Some value"
},
"SomeTag": "Some value"
}
Installation
Pyxmler is published to PyPi, so installing it is as easy as:
pip install pyxmler
Metadata
Release files for pyxmler 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyxmler-0.3.0.tar.gz | 9.2 kB | Without provenance | Details for pyxmler-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyxmler-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pyxmler-0.3.0-py3-none-any.whl |
Total release size: 18.5 kB
Release files / pyxmler-0.3.0.tar.gz
| Download URL | pyxmler-0.3.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89e7db8e8c25516b8b3caf1e26b006fe62046cbea1b2a713d674cce446a6800b
|
|
BLAKE2b-256 checksum How to use checksums |
9d046cac47519fe82ff8c7fd325f7d29a062b7dbe753560951936695609d01b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.7.5 Linux/5.7.14-1-MANJARO
|
Release files / pyxmler-0.3.0-py3-none-any.whl
| Download URL | pyxmler-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3ecb57a771250ea4b73fe6ddb9c93b9c1e59936b634ebc910388a6e19617e1a8
|
|
BLAKE2b-256 checksum How to use checksums |
10290402a6f774a39ace7adbf4201fbf819bbbf90f4c031d5ccddfbcee34ef8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.7.5 Linux/5.7.14-1-MANJARO
|
Security for pyxmler 0.3.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.