Skip to main content

A gerernic tag format for serialization deserializatio

Project description

tagish

A generic SGML tag-based serializers that uses tags to encode nodes. It shares the xml syntax for tags and attributs 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 mirros json's dump and load including indenting support.

Controlling Tag Output: Names, Attributes and Sequences

A strict transformation rule, where simple types become attrbutes whereas complex ones tags generate documents with no tag contents, not the kind of documents we'd exepect. Taghish includes some common sense sense rules for these: where to get tag's content, when to use an attibute 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 configureed thouth TransformRules, namely:

  • Tag contents comes from the first attributes name present as defined in tag_contents (default valule, text and content)
  • Tag names will be generated from attributes names as defined in tag_names_from_attrs.
  • Sequnce items's tag names are the sequence atrribute 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_words or the direct maping by sequence_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

Taghish incluldes a cli:

# outputs the tagish enoded path, for json, toml and yaml files.
$ tagish <path> 
#  Ouptputs tagish to other formats
$ tagish <path> --format (json|tom)

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 Liecenced, and contributions are welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tagish-0.1.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tagish-0.1.2-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file tagish-0.1.2.tar.gz.

File metadata

  • Download URL: tagish-0.1.2.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

Hashes for tagish-0.1.2.tar.gz
Algorithm Hash digest
SHA256 77cae2fc22ee5d48e7e4acbe6725515efba629dcb0b7e55651c7e64da40ff13c
MD5 9c38fc24eab1b80fbf257f4836629079
BLAKE2b-256 306805359b3e77af2952a0c68d0fc993210a2013da833f115a7440d867526ffc

See more details on using hashes here.

File details

Details for the file tagish-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: tagish-0.1.2-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

Hashes for tagish-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 073f445657abecbed983791ab83881235771a142be11f374f79e21f43df410f9
MD5 931a9ed9262cbd784de9602e982f47b2
BLAKE2b-256 1083a60e247bf59dc906648c6fa96bd57b8761aa0bcd84321fb981a47702bde4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page