from __future__ import annotations from collections.abc import Callable from typing import Any # Built from frontends/mizan-rust with `maturin develop --features pyo3`. from mizan_rust import PyMizanClient, PyContextSubscription from .types import * # noqa: F401, F403 from .types import BaseModel # re-import for the synthesized ContextData classes class MizanClient: """Typed Python facade over the PyO3 mizan-rust kernel.""" def __init__(self, base_url: str, *, session: bool = False, csrf_cookie_name: str = "csrftoken", csrf_header_name: str = "X-CSRFToken") -> None: self._inner = PyMizanClient( base_url, session=session, csrf_cookie_name=csrf_cookie_name, csrf_header_name=csrf_header_name, ) {% for ctx in contexts %} def fetch_{{ ctx.snake }}_context(self{% for p in ctx.params %}, {{ p.ident }}: {{ p.ty }}{% if !p.required %} | None = None{% endif %}{% endfor %}) -> "{{ ctx.data_class }}": raw = self._inner.fetch_context("{{ ctx.name }}", {{ "{" }}{% for p in ctx.params %}{% if !loop.first %}, {% endif %}"{{ p.raw_name }}": {{ p.ident }}{% endfor %}{{ "}" }}) return {{ ctx.data_class }}(**raw) def subscribe_{{ ctx.snake }}_context(self{% for p in ctx.params %}, {{ p.ident }}: {{ p.ty }}{% if !p.required %} | None = None{% endif %}{% endfor %}, callback: Callable[[dict[str, Any]], None]) -> PyContextSubscription: return self._inner.subscribe_context("{{ ctx.name }}", {{ "{" }}{% for p in ctx.params %}{% if !loop.first %}, {% endif %}"{{ p.raw_name }}": {{ p.ident }}{% endfor %}{{ "}" }}, callback) {% if !loop.last %} {% endif %}{% endfor %} {% for call in calls %} def call_{{ call.snake }}(self{% match call.input %}{% when CallInput::Typed with (t) %}, args: {{ crate::emit::casing::pascal_case(t) }}{% when CallInput::Absent %}{% endmatch %}) -> {{ call.output }}{% if call.nullable %} | None{% endif %}: raw = self._inner.call("{{ call.wire_name }}", {% match call.input %}{% when CallInput::Typed with (t) %}args.model_dump(){% when CallInput::Absent %}{}{% endmatch %}) return {{ call.output }}(**raw){% if call.nullable %} if raw is not None else None{% endif %} {% if !loop.last %} {% endif %}{% endfor %} def invalidate(self, context: str) -> None: self._inner.invalidate(context) def invalidate_scoped(self, context: str, params: dict[str, Any]) -> None: self._inner.invalidate_scoped(context, params) {% for dc in data_classes %}class {{ dc.class_name }}(BaseModel): """Bundled return of fetch_{{ dc.snake }}_context.""" {% for f in dc.fields %} {{ f.ident }}: {{ f.ty }}{% if f.nullable %} | None{% endif %} {% endfor %}{% if !loop.last %} {% endif %}{% endfor %}