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.

Version: 0.1.0

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.1.0.tar.gz (51.9 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.1.0-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for maxi_format-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0d26ce79435fa693e73e8ed9bc02640ba29ef85de57ec1e75f84d6c8fdb67d2b
MD5 8fec8c2358240c3f91f25a664a777c83
BLAKE2b-256 dce4f66b7e89286c413aee6ca7f44177de2a02a23a85d1b9a5a9724f8788b08c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for maxi_format-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d90b91fd46ad0750c67c2433a07703bd5838a1742cd9b0d855db57a7a6403dc7
MD5 35480556688397c27933a696e35a0f71
BLAKE2b-256 b9ab09d7c430c110b4d8bd4b97f2b54b94f2d7542e874cbb40625a0e481482aa

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