Metadata-Version: 2.3
Name: schemify-cli
Version: 0.5.1
Summary: Build JSON Schemas interactively, and fill JSON data from them, from the command line.
Author: aaltatan
Author-email: aaltatan <a.altatan@gmail.com>
Requires-Dist: jsonschema>=4.26.0
Requires-Dist: questionary>=2.1.1
Requires-Dist: rich>=15.0.0
Requires-Dist: typer>=0.29.0
Requires-Dist: typer-di>=0.1.5
Requires-Dist: typer-swissknife>=0.1.1
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# schemify-cli

Build JSON Schemas interactively, and fill JSON data from them, from the command line.

Source: [github.com/aaltatan/schemify-cli](https://github.com/aaltatan/schemify-cli)

A web version runs at [schemify.surge.sh](https://schemify.surge.sh)
([source](https://github.com/aaltatan/schemify)): the same questions as fields, with the
schema updating as you type.

## Install

```bash
uv tool install schemify-cli
```

## Usage

```bash
schemify generate -t Person -o person.schema.json   # ask for the properties, write the schema
schemify fill person.schema.json -o person.json     # ask for one object matching it
schemify list person.schema.json -f python          # ask for a list of them
```

<!-- absolute URLs so the GIFs also show on PyPI -->
`generate`: a `Person` with `first`, `last` and an optional `age`

![schemify generate](https://raw.githubusercontent.com/aaltatan/schemify-cli/main/docs/demo/generate.gif)

`fill`: one object matching it

![schemify fill](https://raw.githubusercontent.com/aaltatan/schemify-cli/main/docs/demo/fill.gif)

`list`: several objects, printed as Python

![schemify list](https://raw.githubusercontent.com/aaltatan/schemify-cli/main/docs/demo/list.gif)

| Command | Alias | Does |
|---|---|---|
| `generate` | `g` | Asks for the properties of an object and builds its JSON Schema (Draft 2020-12) |
| `fill` | `f` | Asks for data matching a schema file, checked against it |
| `list` | `l` | Asks for a list of items, each matching the schema |

- `-o, --output` saves to a file (asks before overwriting); without it the result is printed.
- `-f, --format` picks the output of `fill` and `list`: `json`, `python` or `javascript`.

Types: `string`, `integer`, `number`, `boolean`, `array`, `object`, each with its constraints
(length, pattern, range, items, ...) and an optional default. A string can have a format
(`date`, `date-time`, `email`, `uuid`), and a string or number can be limited to choices.

## Reusing it in a typer app

`schemify.cli.dependencies.schema` exposes typer-di dependencies that load a schema file and ask
for its data: `FilledDataArgumentDI` and `FilledListArgumentDI` take the path as an argument,
`FilledDataOptionDI` and `FilledListOptionDI` as `--js`. When the path is optional or comes from
elsewhere, call `load_schema(path)` and `ask_or_abort(schema, ask_data)` directly: both report
failures as typer errors.

## Development

```bash
uv sync
uv run pytest
uv run ruff check . && uv run mypy src
```

The demo GIFs are recorded with [VHS](https://github.com/charmbracelet/vhs) (`scoop install vhs`
or `brew install vhs`) and PowerShell (`pwsh`), from the repository root, `generate` first since
the others use its schema:

```bash
vhs docs/demo/generate.tape && vhs docs/demo/fill.tape && vhs docs/demo/list.tape
```

After changing `generators.py` or `validators.py`, run `pnpm sync && pnpm check`
in [the schemify editor](https://github.com/aaltatan/schemify) so it stays in step.
