A gerernic tag format for serialization deserializatio
Project description
tagish
A generic SGML tag-based serializer that uses tags to encode nodes. It shares the xml syntax for tags and attributes but forgoes the xml specifics as namespaces, cdata, and so on. No tag nor attribute names carry special meaning.
{ "title": "tagish", "section": {"title": "Introduction", "p":"A generic SGML tag-based format."}
As tagish:
<document>
<title>tagish</title>
<section>
<title>Introduction</title>
<p>A generic SGML tag-based format.</p>
</section>
</document>
Produces well formed nodes and is parsable by regular xml parsers. The api mirrors json's dump and load including indenting support.
Controlling Tag Output: Names, Attributes and Sequences
A strict transformation rule, where simple types become attributes whereas complex ones tags generate documents with no tag contents, not the kind of documents we'd expect. Tagish includes some common sense rules for these: where to get tag's content, when to use an attribute as a tag name and how to name items in a sequences. While (hopefully) useful, these can be configured.
Basic Transformation Rules
By default, tagish follows these principles:
- Simple types (strings, numbers, booleans) become XML attributes
- Complex types (objects, arrays) become child elements
- All elements use generic tag names based on JSON keys
Additional rules can be configured through TransformRules, namely:
- Tag contents comes from the first attributes name present as defined in tag_contents (default value, text and content)
- Tag names will be generated from attributes names as defined in
tag_names_from_attrs. - Sequence items' tag names are the sequence attribute name in naive singular form, that is a final 's' if present is removed. For more finer-grained control you can customize this by defining
irregular_plurals,non_plural_wordsor the direct maping bysequence_items_names. See the the transform rules for the full details.
For example, the dict:
data = {
"books": ["To Kill a Mocking Bird", "If traveler on a Winter's Night a Traveler" ],
"button": {
"text": "click me" ,
"class": "active"
}
}
Serializes to
<document>
<book>To Kill a Mocking Bird</book>
<book>If a Traveler on a Winters Night</book>
<button class="active">click me</button>
</document>
The Cli
Tagish includes a cli:
# outputs the tagish encoded path, for json, toml and yaml files.
$ tagish <path>
# Outputs tagish to other formats
$ tagish <path> --format (json|toml)
Install
tagish is available on Pypi and can be installed as one would so hope:
pipx install tagish
pip install tagish
Project
It's MIT Licensed, and contributions are welcome.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tagish-1.0.0.tar.gz.
File metadata
- Download URL: tagish-1.0.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
946ccf1b147c12445bd68aeec18bd8757b0cc4a26caa5ca1cf29034c2c9518fc
|
|
| MD5 |
86c9ec87b76fdd7a8e141f10a7d42d6a
|
|
| BLAKE2b-256 |
0032ccf2d24bed63a2944f5614339b571cb5c203f86c49a0678c773db10075c0
|
File details
Details for the file tagish-1.0.0-py3-none-any.whl.
File metadata
- Download URL: tagish-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ad26ae874a6fd79bf41fb5baa298f3ca244ee8e5a6705e3cad237bad7bd3503
|
|
| MD5 |
b425c1dca6c4dcc9250c30f91a123da8
|
|
| BLAKE2b-256 |
e6284978fb04279488eb302272721df45da4f68f7454930a1512a3db4216dc63
|