Metadata-Version: 2.5
Name: front
Version: 0.1.102
Summary: Getting from python objects to UIs exposing them
Project-URL: Homepage, https://github.com/i2mint/front
License: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: dill
Requires-Dist: dol
Requires-Dist: i2
Requires-Dist: meshed
Requires-Dist: pydantic>=2
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx-rtd-theme>=1.0; extra == 'docs'
Requires-Dist: sphinx>=6.0; extra == 'docs'
Description-Content-Type: text/markdown

# front

Compile a Python function's configuration into a runnable UI (web app, CLI, GUI...) without writing framework glue by hand.

To install: `pip install front`

## Quick example

`front` itself is not a UI framework: it's the core library concrete `front` frameworks (e.g. [streamlitfront](https://github.com/i2mint/streamlitfront/)) build on. A minimal in-memory framework, whose "app" is a container rendering each function's docstring:

```python
from collections.abc import Callable
from front import SpecMakerBase, APP_KEY, OBJ_KEY, RENDERING_KEY, ELEMENT_KEY, AppMaker
from front.elements import FrontContainerBase, FrontComponentBase
from front.util import dflt_trans


class App(FrontContainerBase):
    def render(self):
        return {child.name: child() for child in self.children}


class Doc(FrontComponentBase):
    def render(self):
        return self.obj.__doc__


class SpecMaker(SpecMakerBase):
    @property
    def _dflt_convention(self):
        return {
            APP_KEY: {"title": "Untitled"},
            OBJ_KEY: {"trans": dflt_trans},
            RENDERING_KEY: {ELEMENT_KEY: App, Callable: {ELEMENT_KEY: Doc}},
        }


def foo(a, b):
    "Adds a and b."
    return a + b


app_maker = AppMaker(spec_maker_factory=SpecMaker)
app = app_maker.mk_app([foo], config={APP_KEY: {"title": "My App"}})
app.name
# 'My App'
app()
# {'foo': 'Adds a and b.'}
```

## The three-step workflow

1. `SpecMakerBase.mk_spec` compiles a short-language configuration (plus a convention of defaults) into a long-language `FrontSpec` (`app_spec`, `obj_spec`, `rendering_spec`).
2. `ElementTreeMaker.mk_tree` builds a composite tree of `FrontElementBase` elements from the rendering spec: a root container (e.g. `FrontContainerBase`) with one child per object, built from `FrontComponentBase`/`InputBase`/`OutputBase` subclasses.
3. `AppMaker.mk_app` chains the two and returns the root element, callable as the app.

To implement a concrete `front` framework, subclass `SpecMakerBase` to supply the concrete element classes as the default convention, and hand it to `AppMaker` (see the example above, and [streamlitfront](https://github.com/i2mint/streamlitfront/) for a real one).

## Crudifying functions

`Crudifier`/`prepare_for_crude_dispatch` (in `front.crude`) let functions with complex arguments (objects that don't fit in a text box or URL) be dispatched through string keys into stores instead — the "CRUD-Execution" pattern. `front.dag` applies the same crudification to the variable nodes of a `meshed` DAG.

## Docs

[Rendered documentation](https://i2mint.github.io/front/) · [flat `front.md`](https://i2mint.github.io/front/front.md) for a single-file view.

<!-- epythet:agentic-readme:start -->
## For AI agents

`front` publishes its documentation in forms made for coding agents. If you are one, start here.

**The documentation, machine-readable**: [`llms.txt`](https://i2mint.github.io/front/llms.txt) indexes every page; [`front.md`](https://i2mint.github.io/front/front.md) is the whole documentation in one file; every page has a `.md` twin; [`objects.inv`](https://i2mint.github.io/front/objects.inv) maps symbols to URLs.

If you are a control freak, the rest of this README is written for you, starting at the top of the page.
<!-- epythet:agentic-readme:end -->
