Metadata-Version: 2.4
Name: schema-guess-lite
Version: 0.1.1
Summary: Turn sample JSON, JSON Lines or CSV into a JSON Schema, Pydantic and TypedDict. CLI and MCP server. Runs locally.
Author: Tidy Byte Tools
License-Expression: MIT
Project-URL: Homepage, https://tidybytetools.com/tools/json-schema-generator/
Project-URL: Documentation, https://tidybytetools.com/tools/json-schema-generator/
Project-URL: Source, https://github.com/tidybytetools/schema-guess-lite
Project-URL: Issues, https://github.com/tidybytetools/schema-guess-lite/issues
Project-URL: Changelog, https://github.com/tidybytetools/schema-guess-lite/blob/main/CHANGELOG.md
Keywords: json-schema,schema,pydantic,typeddict,json,csv,infer-schema,structured-output,llm,cli,mcp,mcp-server
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp<2,>=1.10
Dynamic: license-file

<p>
  <a href="https://github.com/tidybytetools">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tidybytetools/schema-guess-lite/main/assets/tidybytetools-lockup-dark.png">
      <img alt="Tidy Byte Tools" src="https://raw.githubusercontent.com/tidybytetools/schema-guess-lite/main/assets/tidybytetools-lockup-light.png" height="44">
    </picture>
  </a>
</p>

# schema-guess-lite

[![Tests](https://github.com/tidybytetools/schema-guess-lite/actions/workflows/tests.yml/badge.svg)](https://github.com/tidybytetools/schema-guess-lite/actions/workflows/tests.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/tidybytetools/schema-guess-lite/blob/main/LICENSE)

Free tool that turns sample JSON, JSON Lines or CSV into a JSON Schema, Pydantic classes and TypedDict classes.

Need more than 50 records, or TypeScript, Zod, a strict schema for AI tool calls, or a drift report? See the pay-per-use version: **[JSON Schema generator](https://tidybytetools.com/tools/json-schema-generator/)**.

## Example

Input (`customers.json`):

```json
[{"id": 1, "name": "Ann", "email": "ann@example.com", "address": {"city": "Austin"}},
 {"id": 2, "name": "Bo", "email": "bo@example.com", "address": null, "phone": "555"}]
```

Run:

```
schema-guess-lite customers.json
```

You get three files. `customers.models.py` looks like this:

```python
from pydantic import BaseModel


class Address(BaseModel):
    city: str


class Customers(BaseModel):
    id: int
    name: str
    email: str
    address: Address | None
    phone: str | None = None
```

`phone` is optional because it is missing from one record. `address` can be null because one record has null. `customers.schema.json` is the matching JSON Schema, and `customers.typed_dicts.py` has TypedDict classes.

Plain code, not AI, so the same samples always give the same answer. Runs on your own computer. MIT license. Python 3.10 or newer, on Windows, Mac and Linux.

Also searched as: json to json schema, json to pydantic model, generate schema from sample data, csv to json schema, infer json schema

<!-- mcp-name: io.github.tidybytetools/schema-guess-lite -->
<!-- mcp-name: com.tidybytetools/schema-guess-lite -->

## Install

```
pip install schema-guess-lite
```

Not on PyPI yet? Install from GitHub: `pip install git+https://github.com/tidybytetools/schema-guess-lite`

## Use it

```
schema-guess-lite FILE...                 # saves FILE.schema.json, FILE.models.py, FILE.typed_dicts.py
schema-guess-lite data.json -n Customer   # name the top-level class
schema-guess-lite reply.json -p data.items  # the records are inside the JSON at data.items
schema-guess-lite data.json --print pydantic
cat sample.json | schema-guess-lite - --json   # one JSON object, for scripts and AI agents
```

Python:

```python
from schema_guess_lite import guess
r = guess(open("customers.json").read(), "Customer")
r["jsonSchema"], r["pydantic"], r["typedDict"]
```

## For AI agents (MCP)

Start the MCP server with `uvx schema-guess-lite mcp`. Two tools:
- `guess_schema` (read only): sample text or a file path in, schema and code out.
- `save_schema_files`: writes the three files into a folder you name.

Example config for Claude Desktop or Cursor:

```json
{"mcpServers": {"schema-guess-lite": {"command": "uvx", "args": ["schema-guess-lite", "mcp"]}}}
```

## What the free tier does and does not do

| | Free (this tool) | Pay per use ([Apify](https://tidybytetools.com/tools/json-schema-generator/)) |
|---|---|---|
| Records read | first 50 | up to 500,000, from files, links or datasets |
| JSON Schema, Pydantic, TypedDict | yes | yes |
| Optional and nullable fields, mixed types | yes | yes |
| Dates, emails, UUIDs as `format` | no | yes |
| Short lists of values as `enum` | no | yes |
| TypeScript and Zod | no | yes |
| Strict schema for AI structured output and tool calls | no | yes |
| Drift report against an old schema | no | yes |

## FAQ

**Does it use AI?** No. It reads the samples and follows fixed rules.

**Does it send my data anywhere?** No. It runs on your computer and never uses the internet.

**Why is a field optional?** It was missing from at least one record.

**Why `number` and not `integer`?** At least one value had decimals.

**It only saw `null` for a field. What type is it?** Open: `Any` in Pydantic, and no type in the schema. Add a sample with a real value.

## Links

- Website: [tidybytetools.com/tools/json-schema-generator](https://tidybytetools.com/tools/json-schema-generator/)
- Source and issues: [github.com/tidybytetools/schema-guess-lite](https://github.com/tidybytetools/schema-guess-lite)
- More free tools: [github.com/tidybytetools](https://github.com/tidybytetools)
