Skip to main content

Mu configuration language parser and typed decoder for Python.

Project description

lang-mu

lang-mu is a Python distribution for the mu Python package, an implementation of the Mu configuration language. It provides:

  • A parser that preserves Mu syntax as an AST.
  • A typed decoder that maps Mu expressions into Python dataclasses and typing constructs.
  • An experimental runtime evaluator (mu.exec) for callable execution semantics.

Why this library

Mu configuration files can describe nested structures, tagged records, and mixed positional/named arguments. This package gives you a strict, testable way to parse and decode those configs into Python types.

Installation

pip install lang-mu

Quickstart: Parsing

from mu import Document, parse

doc = parse('(app-jvm "demo" :main "demo.Main")')
assert isinstance(doc, Document)
assert len(doc.exprs) == 1

Quickstart: Typed decoding

from dataclasses import dataclass
from typing import Annotated

from mu import ZeroOrMore, parse_one


@dataclass
class Demo:
    name: str
    aliases: Annotated[list[str], ZeroOrMore]


cfg = parse_one('(demo :name "x" :aliases "a" "b")', Demo)
assert cfg == Demo(name="x", aliases=["a", "b"])

Error handling

Typed decoding raises DecodeError with structured context:

  • path: decode path (for example $.field[0])
  • expected: human-readable expected target/type
  • got: actual Mu expression description
  • span: optional source span/token information
  • cause: optional underlying exception
from dataclasses import dataclass
from mu import DecodeError, parse_one


@dataclass
class Counter:
    value: int


try:
    parse_one('(counter :value "not-an-int")', Counter)
except DecodeError as e:
    print(e.path, e.expected, e.got)

API contract

Stable API (from mu import ...)

  • Parser: parse, ParseError
  • AST: Expr, Document, AtomExpr, StringExpr, GroupExpr, SequenceExpr, MappingExpr, MappingField
  • Typed decoding:
    • parse_one, parse_many, decode
    • DecodeError, DecodeContext
    • DecoderRegistry, DecoderFn, DecodeWith
    • FieldName, OptionalArg, ZeroOrMore, OneOrMore, tag
    • Quoted

Experimental API (from mu.exec import ...)

  • EvalContext
  • eval_expr
  • EvalNameError

The experimental runtime API is available but not considered stable yet. Non-exported internals (for example mu.arg_match and parser private helpers) are unsupported and may change without notice.

Python support

  • Python >=3.10

License

This project is licensed under AGPL-3.0-or-later. See LICENSE.md for full text.

Development and release checks

pytest -q
ruff check .
python -m build --sdist --wheel
python -m twine check dist/*
./scripts/check_wheel_contents.sh

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

lang_mu-0.2.0.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

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

lang_mu-0.2.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lang_mu-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ace05a1de1e02c56aa0029ceba2e5b2206287c6e60985a52cccf664064fda47d
MD5 784ffe38783ffa0f4333ebd7a20eb1f7
BLAKE2b-256 3717171bfc12a9d9d1718613851131b7c9cfe3eea6f86b4bd9ada7176d9dbd6f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for lang_mu-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 777aea888ebd602dba2346f8a28ec2690b1dcd5dd51f1cfba9edbed10ef16eb4
MD5 661ae4aa623969240a061e5c500a8599
BLAKE2b-256 9626a2ea551fbf80fff3c8b25b913db21104e3e6ba10a605c47d0694def7df2d

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