Metadata-Version: 2.4
Name: cjm-fasthtml-jsonschema
Version: 0.0.2
Summary: Library for genearating FastHTML user interfaces from JSON Schema configurations.
Home-page: https://github.com/cj-mills/cjm-fasthtml-jsonschema
Author: Christian J. Mills
Author-email: 9126128+cj-mills@users.noreply.github.com
License: Apache Software License 2.0
Keywords: nbdev jupyter notebook python
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastcore
Requires-Dist: python-fasthtml
Requires-Dist: cjm-fasthtml-daisyui
Requires-Dist: jsonschema
Provides-Extra: dev
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# cjm-fasthtml-jsonschema


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Install

``` bash
pip install cjm_fasthtml_jsonschema
```

## Demo Application

Run the demo to see the library in action:

``` bash
python demo_app.py
```

Then visit:

- http://localhost:5001/ - Demo page with example form from
  \`./test_files/

``` bash
$ python ./demo_app.py -h
usage: demo_app.py [-h] [--schema SCHEMA] [--port PORT] [--host HOST]

JSON Schema to UI Demo Application

options:
  -h, --help       show this help message and exit
  --schema SCHEMA  Path to the JSON schema file (default: test_files/voxtral_config_schema.json)
  --port PORT      Port to run the server on (default: 5001)
  --host HOST      Host to run the server on (default: 0.0.0.0)
```

## Project Structure

    nbs/
    ├── components/ (1)
    │   └── fields.ipynb  # Field component generators for different JSON Schema types.
    ├── core/ (2)
    │   ├── parser.ipynb  # JSON Schema parsing utilities.
    │   └── types.ipynb   # Type definitions for JSON Schema elements.
    └── generators/ (1)
        └── form.ipynb  # Main form generator that creates UI from JSON Schema.

Total: 4 notebooks across 3 directories

## Module Dependencies

``` mermaid
graph LR
    components_fields[components.fields<br/>fields]
    core_parser[core.parser<br/>parser]
    core_types[core.types<br/>types]
    generators_form[generators.form<br/>form]

    components_fields --> core_types
    core_parser --> core_types
    generators_form --> components_fields
    generators_form --> core_parser
```

*4 cross-module dependencies detected*

## CLI Reference

No CLI commands found in this project.

## Module Overview

Detailed documentation for each module in the project:

### fields (`fields.ipynb`)

> Field component generators for different JSON Schema types.

#### Import

``` python
from cjm_fasthtml_jsonschema.components.fields import (
    create_label,
    create_description,
    create_string_field,
    create_enum_field,
    create_number_field,
    create_range_field,
    create_boolean_field,
    create_field
)
```

#### Functions

``` python
def create_label(
    prop: SchemaProperty  # SchemaProperty object
) -> FT:  # Label component
    "Create a label for a field."
```

``` python
def create_description(
    prop: SchemaProperty  # SchemaProperty object
) -> Optional[FT]:  # P component with description or None
    "Create a description/help text for a field."
```

``` python
def create_string_field(
    prop: SchemaProperty,  # SchemaProperty object
    value: Any = None  # Current value
) -> FT:  # Div containing the field
    "Create a string input field."
```

``` python
def create_enum_field(
    prop: SchemaProperty,  # SchemaProperty object
    value: Any = None  # Current value
) -> FT:  # Div containing the field
    "Create an enum select dropdown field."
```

``` python
def create_number_field(
    prop: SchemaProperty,  # SchemaProperty object
    value: Any = None  # Current value
) -> FT:  # Div containing the field
    "Create a number input field."
```

``` python
def create_range_field(
    prop: SchemaProperty,  # SchemaProperty object
    value: Any = None  # Current value
) -> FT:  # Div containing the field
    "Create a range slider field."
```

``` python
def create_boolean_field(
    prop: SchemaProperty,  # SchemaProperty object
    value: Any = None  # Current value
) -> FT:  # Div containing the field
    "Create a boolean toggle field."
```

``` python
def create_field(
    prop: SchemaProperty,  # SchemaProperty object
    value: Any = None  # Current value
) -> FT:  # Div containing the field
    "Create an appropriate field based on the property type."
```

### form (`form.ipynb`)

> Main form generator that creates UI from JSON Schema.

#### Import

``` python
from cjm_fasthtml_jsonschema.generators.form import (
    generate_form_ui
)
```

#### Functions

``` python
def generate_form_ui(
    schema: Dict[str, Any],
    values: Optional[Dict[str, Any]] = None,
    show_title: bool = True,  # Whether to show the schema title
    show_description: bool = True,  # Whether to show schema description
    compact: bool = False,  # Use compact layout (less spacing)
    card_wrapper: bool = True  # Wrap the form in a card component
) -> FT
    "Generate a FastHTML form UI from a JSON Schema."
```

### parser (`parser.ipynb`)

> JSON Schema parsing utilities.

#### Import

``` python
from cjm_fasthtml_jsonschema.core.parser import (
    SchemaParser
)
```

#### Classes

``` python
class SchemaParser:
    def __init__(
        self,
        schema: Dict[str, Any]  # JSON Schema dictionary
    )
    "Parse JSON Schema and extract property information."
    
    def __init__(
            self,
            schema: Dict[str, Any]  # JSON Schema dictionary
        )
        "Initialize parser with a JSON Schema."
    
    def get_property(
            self,
            name: str  # Property name
        ) -> Optional[SchemaProperty]:  # SchemaProperty object or None if not found
        "Get a specific property by name."
    
    def get_required_properties(
            self
        ) -> List[SchemaProperty]:  # TODO: Add return description
        "Get all required properties."
    
    def get_optional_properties(
            self
        ) -> List[SchemaProperty]:  # TODO: Add return description
        "Get all optional properties."
```

### types (`types.ipynb`)

> Type definitions for JSON Schema elements.

#### Import

``` python
from cjm_fasthtml_jsonschema.core.types import (
    SchemaProperty
)
```

#### Classes

``` python
@dataclass
class SchemaProperty:
    "Represents a single property in a JSON Schema."
    
    name: str
    schema: Dict[str, Any]
    required: bool = False
    value: Any
    
    def type(
            self
        ) -> str:  # TODO: Add return description
        "Get the property type."
    
    def is_nullable(
            self
        ) -> bool:  # TODO: Add return description
        "Check if property allows null values."
    
    def default(
            self
        ) -> Any:  # TODO: Add return description
        "Get default value if specified."
    
    def description(
            self
        ) -> Optional[str]:  # TODO: Add return description
        "Get property description."
    
    def enum_values(
            self
        ) -> Optional[List[Any]]:  # TODO: Add return description
        "Get enum values if property is an enum."
    
    def examples(
            self
        ) -> Optional[List[Any]]:  # TODO: Add return description
        "Get example values if provided."
    
    def minimum(
            self
        ) -> Optional[Union[int, float]]:  # TODO: Add return description
        "Get minimum value for numeric types."
    
    def maximum(
            self
        ) -> Optional[Union[int, float]]:  # TODO: Add return description
        "Get maximum value for numeric types."
    
    def min_length(
            self
        ) -> Optional[int]:  # TODO: Add return description
        "Get minimum length for string types."
    
    def max_length(
            self
        ) -> Optional[int]:  # TODO: Add return description
        "Get maximum length for string types."
    
    def pattern(
            self
        ) -> Optional[str]:  # TODO: Add return description
        "Get regex pattern for string validation."
    
    def format(
            self
        ) -> Optional[str]:  # TODO: Add return description
        "Get format hint (e.g., 'email', 'uri', 'date')."
```
