Skip to main content

Python library for parsing and dumping MAXI schema + records

Project description

maxi-schema for Python

Python library for parsing and dumping MAXI schema + records.

Install

pip install maxi-format

API overview

Function Description
parse_maxi(input, **options) Parse MAXI text → MaxiParseResult (schema + raw records)
stream_maxi(input, **options) Parse schema eagerly, yield records lazily via async iterator
parse_maxi_as(input, class_map, **options) Parse + hydrate records into class instances
parse_maxi_auto_as(input, classes, **options) Same, with alias inferred from __maxi_schema__
dump_maxi(data, **options) Serialize objects / parse results → MAXI text
dump_maxi_auto(objects, **options) Same, with schema inferred from __maxi_schema__
define_maxi_schema(Cls, schema) Register a schema descriptor for a class
get_maxi_schema(ClsOrInstance) Look up a registered schema descriptor
MaxiModel Declarative base class for schema-annotated models

Quick start

Parse

import asyncio
from maxi import parse_maxi

input_text = """
U:User(id:int|name|email)
###
U(1|Julie|julie@maxi.org)
""".strip()

res = asyncio.run(parse_maxi(input_text))
print(res.records[0].values)  # [1, 'Julie', 'julie@maxi.org']

Parse into class instances

import asyncio
from maxi import parse_maxi_auto_as

class User:
    __maxi_schema__ = {
        "alias": "U",
        "fields": [{"name": "id", "typeExpr": "int"}, {"name": "name"}, {"name": "email"}],
    }
    def __init__(self, id=None, name=None, email=None):
        self.id = id
        self.name = name
        self.email = email

result = asyncio.run(parse_maxi_auto_as(input_text, [User]))
user_instance = result.data["U"][0]

print(isinstance(user_instance, User))  # True
print(user_instance.name)               # 'Julie'

Dump

Using MaxiModel for zero-config dumping:

from maxi import dump_maxi_auto
from maxi.models import MaxiModel, IntField, StrField

class User(MaxiModel, alias="U"):
    id = IntField(id=True)
    name = StrField()

maxi = dump_maxi_auto([User(id=1, name="Julie")])

Or with explicit types via dump_maxi:

from maxi import dump_maxi

maxi = dump_maxi([{"id": 1, "name": "Julie"}],
    default_alias="U",
    types=[{"alias": "U", "name": "User", "fields": [{"name": "id", "typeExpr": "int"}, {"name": "name"}]}],
)

Documentation

  • docs/parser.md — full parser guide: parse_maxi, stream_maxi, parse_maxi_as, parse_maxi_auto_as, hydration, MaxiModel, options
  • docs/dumper.md — full dumper guide: dump_maxi, dump_maxi_auto, schema-annotated classes, references, inheritance, options

MAXI format (quick reference)

U:User(id:int|name|email=unknown)   ← type definition
###                                  ← section separator
U(1|Julie|~)                         ← record  (~ = explicit null)
  • Omitted trailing fields use their declared default value.
  • See the MAXI spec for the full format definition.

Test

Requires pytest and pytest-asyncio.

pip install pytest pytest-asyncio
pytest

License

Released under the MIT License.

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

maxi_format-0.2.0.tar.gz (53.3 kB view details)

Uploaded Source

Built Distribution

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

maxi_format-0.2.0-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file maxi_format-0.2.0.tar.gz.

File metadata

  • Download URL: maxi_format-0.2.0.tar.gz
  • Upload date:
  • Size: 53.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for maxi_format-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2aadfe1cc69689d2f607aaa54dbdc785b3284d9c6c2a3158faa45f815be18890
MD5 2cc9b5803555f53883554e669c5aeb5a
BLAKE2b-256 a5b7250f7e8ed911bf5123e8ace9a6b48c9929b0f499966586f0c46d25e0fe1c

See more details on using hashes here.

File details

Details for the file maxi_format-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: maxi_format-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for maxi_format-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1833a68f514130ca3864ba95a72f7bbbe3120adfba3f84115c664c839b88e80
MD5 489f47ed2d83e9da2e26c3a5e4e85ecc
BLAKE2b-256 66d47cf1cdb750a40364039c320d042002ee0986cd326d780e493b0383edc8cb

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