lawsynth/deploy/quickstart/wsgi_gateway.py
caelum0x 7087e7925e feat(product): symbolic simplify (egraph), model compose/edit, hosted-deploy
Wave 11 — the three candidates:
CLI — lawsynth simplify (egraph equality saturation extracts the lowest-cost
EQUIVALENT law; proves equivalence by simulating both worlds, deviation ~0;
honest 'already minimal' on sparse discovered worlds); lawsynth compose (union
two worlds into a coupled system, namespacing collisions) and lawsynth edit
(immutable rename/set-param/drop-law/scale-law, re-validated).

SDK — lawsynth.simplify / World.simplify (stdlib expand/fold/combine +
equivalence verify), lawsynth.compose, World.rename/set_parameter/drop_law/
scale_law. Two runnable examples.

Deploy — a verifiable hosted-deploy story: deploy/quickstart (config-validated
minimal api+gateway) + docs/self-hosting/quickstart.md (real curl/Client run
loop), after fixing genuine drift in the compose files (SQLite URL the API
actually accepts, correct token env, object root, health endpoints, native
build step) — verified end-to-end from source.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-18 01:08:14 +03:00

31 lines
1.2 KiB
Python

"""Gunicorn entrypoint: the LawSynth admission gateway wrapping the API.
The gateway (:mod:`lawsynth_gateway`) is an in-process WSGI admission layer —
it enforces body/header limits, a per-client rate window, and CORS origin
policy, then calls a backend WSGI application in-process. Here the backend is
the co-located API (``lawsynth_api.main:application``). Point it elsewhere with
``LAWSYNTH_GATEWAY_BACKEND=module:attribute`` if you ever split the two.
Rate-limit, body-limit, and allowed-origin settings are read from the
``LAWSYNTH_GATEWAY_*`` environment variables by
``GatewaySettings.from_environment`` inside ``create_gateway``.
"""
from __future__ import annotations
import importlib
import os
from lawsynth_gateway.app import create_gateway
_target = os.environ.get("LAWSYNTH_GATEWAY_BACKEND", "lawsynth_api.main:application")
_module_name, _, _attribute = _target.partition(":")
if not _module_name or not _attribute:
raise RuntimeError("LAWSYNTH_GATEWAY_BACKEND must use module:attribute syntax")
_backend = getattr(importlib.import_module(_module_name), _attribute)
if not callable(_backend):
raise RuntimeError("LAWSYNTH_GATEWAY_BACKEND must resolve to a WSGI callable")
application = create_gateway(_backend)