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 AtomExpr, Document, GroupExpr, parse

source = """
; application plus shared includes
(app-jvm "billing-api"
  :main "billing.Main"
  :ports [8080 8443]
  :env {profile: prod, region: us-east-1}
)
(include "shared/logging.mu")
"""

doc = parse(source)
assert isinstance(doc, Document)
assert len(doc.exprs) == 2

app = doc.exprs[0]
assert isinstance(app, GroupExpr)
assert isinstance(app.values[0], AtomExpr)
assert app.values[0].value == "app-jvm"

Quickstart: Typed decoding

from dataclasses import dataclass

from mu import parse_one


@dataclass
class Http:
    port: int


@dataclass
class Worker:
    queue: str


@dataclass
class Service:
    name: str
    mode: Http | Worker


cfg = parse_one('(service "api" :mode (http :port 8080))', Service)
assert cfg == Service(name="api", mode=Http(port=8080))

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 ...)

  • Stable symbol reference is generated from code: docs/api-stable.md.
  • Main entry points:
    • parse, ParseError
    • parse_one, parse_many, decode
    • DecodeError, DecoderRegistry, Quoted

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

  • Experimental symbol reference is generated from code: docs/api-experimental.md.

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

python scripts/generate_api_docs.py --check
python scripts/check_docs_links.py
pytest -q tests/test_docs_snippets.py
codespell README.md docs CHANGELOG.md CONTRIBUTING.md --ignore-words=.codespell-ignore-words.txt
mkdocs build --strict
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.1.tar.gz (30.9 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.1-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lang_mu-0.2.1.tar.gz
  • Upload date:
  • Size: 30.9 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.1.tar.gz
Algorithm Hash digest
SHA256 148c251576465f1fc08bc3edb621f65165e8c8a852ea3e7c0996651489ab94d1
MD5 8eaaedea2fb0f95ee3b66cdfe5944308
BLAKE2b-256 53b537674819b827f9aadd53150ed287249a50b9b93dd9a515cdfc8ad8248981

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lang_mu-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 32.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5581993f42bcaa2e0511e73aed21ff9472ccbb1be7e148c3bc66b1aca589b1b7
MD5 39525aa3b378bcef233df9d00121b54b
BLAKE2b-256 3c70e9206213ca9985ae31845936f586c436f6bde12fd6ea51d08c4bebad32ac

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