Skip to main content

Bisque Metadoc

Project description

ViQi Metadoc

Representation of hierarchical documents with various "rendering" and query options. For doc communication between server/clients.

Install

pip install bisque-metadoc

Usage

Metadoc provides a unified interface for working with hierarchical metadata in various formats (XML, JSON, Python dicts).

Creating a Metadoc

from bq.metadoc.formats import Metadoc

# Create a new document
doc = Metadoc(tag="resource", name="my_image", type="image")

# Add child tags
doc.add_tag("author", value="John Doe")
doc.add_tag("description", value="A sample image")

# Create from Natural XML
xml_str = '<resource name="test"><child>123</child></resource>'
doc = Metadoc.from_naturalxml(xml_str)

# Create from Python dictionary
data = {"resource": {"@name": "test", "child": "123"}}
doc = Metadoc.from_dict(data)

Accessing Data

Metadoc supports attribute-style access and automatic type conversion.

print(doc.tag)         # "resource"
print(doc.name)        # "test"
print(doc.child.value) # 123 (automatically converted to int if type is set)

# Iterating over children
for child in doc:
    print(child.tag, child.value)

Path Queries

Simplified path queries automatically handle the internal mapping of custom tags.

# Finds all tags named "author" anywhere in the document
authors = doc.path_query("//author")

Formats and Serialization

Metadoc supports multiple serialization formats:

  • Natural XML: Standard XML where data names are used as tags.
  • Tag XML: Bisque "System" XML where values are stored in attributes and generic <tag name="..."> elements are used for custom metadata.
  • Natural JSON: Idiomatic JSON dictionaries (attributes prefixed with @).
  • Ordered JSON: A round-trippable JSON structure that preserves element order using an @children list.
# To XML string
print(doc.to_naturalxml())
print(doc.to_tagxml())

# To JSON string or dict
print(doc.to_json())
print(doc.to_dict())

# To/From Ordered JSON (preserves order and mixed content)
ordered_json = doc.to_ordered_json()
doc2 = Metadoc.from_ordered_json(ordered_json)

Documentation

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

bisque_metadoc-0.6.6-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file bisque_metadoc-0.6.6-py3-none-any.whl.

File metadata

  • Download URL: bisque_metadoc-0.6.6-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for bisque_metadoc-0.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 754a1f8a32b5cfbc4a30c37cb75c7469352d29c3907cb3b90674a210685c1be1
MD5 b390fd4ae36a24036f949f5a777e40a8
BLAKE2b-256 af37f5ab1b7f4a528cf0fb7ee383d4d5ba7c36bd2b3835cdb168fa2c17ce0a0f

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