Skip to main content

Infer schema from JSON or CSV data — output as TypeScript, Pydantic, or Markdown

Project description

sniff-schema

Infer schema from any JSON or CSV — instantly output as TypeScript, Pydantic, or Markdown.

PyPI version Python License: MIT Downloads

sniff-schema terminal screenshot

You get a JSON file or CSV from an API, a colleague, or a legacy system. No docs. No types. Just raw data. sniff-schema reads it and tells you exactly what's in it — field names, types, nullability, null percentages, and sample values — then outputs a ready-to-use TypeScript interface or Pydantic model.

No LLM. No cloud. No auth. Pure local analysis.


Install

pip install sniff-schema

Or run directly without installing:

pip install httpx "rich>=13" "typer>=0.12"
python sniff_schema.py data.json

Usage

# Rich terminal table (default)
sniff-schema data.json

# TypeScript interface
sniff-schema data.json --format typescript

# Pydantic v2 model
sniff-schema data.json --format pydantic

# Markdown table — save to file
sniff-schema data.json --format markdown --output schema.md

# Pipe directly from curl
curl https://api.example.com/users | sniff-schema - --format typescript

# CSV works too
sniff-schema report.csv --format pydantic

# Large files — sample just 100 rows
sniff-schema big_dataset.csv --sample 100

What it detects

Thing How
Integers, floats, booleans, strings Native Python types
ISO 8601 dates / datetimes Regex match (2024-01-15, 2024-01-15T10:30:00Z)
Numeric strings, boolean strings Pattern matching on string values
Nullable fields Counts null, missing keys, and empty strings
Mixed types Flags when a field contains more than one type
Nested JSON Flattens to dot-notation (user.address.city)
JSON arrays Handles root arrays, wrapped arrays (data, results, items)
NDJSON / JSON Lines Auto-detected line-by-line
CSV dialect Auto-sniffed (comma, tab, pipe, etc.)

Output formats

--format typescript

interface InferredSchema {
  id: number;
  name: string;
  age?: number | null;
  email?: string | null;
  score?: number | null;
  active: boolean;
  created_at: string;
  country: string;
  notes?: string | null;
}

// Inferred from 5 record(s)

--format pydantic

from pydantic import BaseModel
from typing import Optional


class InferredSchema(BaseModel):
    id: int
    name: str
    age: Optional[int] = None
    email: Optional[str] = None
    score: Optional[float] = None
    active: bool
    created_at: str
    country: str
    notes: Optional[str] = None

# Inferred from 5 record(s)

--format markdown

Outputs a GitHub-flavored Markdown table — paste directly into your wiki, Notion, or PR description.


All options

Arguments:
  SOURCE     Path to JSON/CSV file, or '-' to read from stdin.

Options:
  -f, --format   [table|typescript|pydantic|markdown]  Output format (default: table)
  -s, --sample   Max records to sample (default: 200, max: 100000)
  -o, --output   Write output to a file instead of stdout
  --help         Show this message and exit.

Where to install / publish this tool

Platform Command Notes
PyPI pip install sniff-schema Primary distribution
Homebrew (tap) brew install gitwingo/tap/sniff-schema macOS/Linux users who avoid pip
Conda-forge conda install sniff-schema Data science audience
GitHub Releases Single-file .py download For users who want zero install
pipx pipx install sniff-schema Isolated install, great for CLI tools

Recommended publishing order: PyPI first → GitHub Release (attach sniff_schema.py) → Conda-forge (after traction) → Homebrew tap.


Why conda-forge matters for this tool specifically

sniff-schema is uniquely well-suited for conda-forge because its primary audience — data scientists and ML engineers — overwhelmingly use conda environments. Submitting a conda-forge recipe makes it a first-class citizen in that ecosystem. See the conda-forge contribution docs to submit a recipe after publishing to PyPI.


Development

git clone https://github.com/gitwingo/sniff-schema
cd sniff-schema
pip install -e ".[dev]"

Support

If sniff-schema has been useful to you, consider supporting its development:

Buy Me a Ko-Fi

Connect


Made with 💖 by Gitwingo

License

MIT © gitwingo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sniff_schema-0.1.1.tar.gz (100.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sniff_schema-0.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file sniff_schema-0.1.1.tar.gz.

File metadata

  • Download URL: sniff_schema-0.1.1.tar.gz
  • Upload date:
  • Size: 100.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sniff_schema-0.1.1.tar.gz
Algorithm Hash digest
SHA256 de6b7ddc44b9fd5c63b5920ef1d9d9a97f5263cf167d2d24a22ea73e1e2760f9
MD5 cf5ecf82a91f22397aca672531e773f7
BLAKE2b-256 b9122718ba43ef6f849df6243c7823b0728705bad7a1f538a141249f195e0844

See more details on using hashes here.

Provenance

The following attestation bundles were made for sniff_schema-0.1.1.tar.gz:

Publisher: publish.yml on gitwingo/sniff-schema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sniff_schema-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sniff_schema-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sniff_schema-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b39aa35dcf1d7efd1237b4fdebf9590503692c7da631635af5ddd6d9864fd5b7
MD5 d9f3b6c5e2e4b3e9866208ea02064842
BLAKE2b-256 47e04218a0069649d0bb5bdfdac3a93a6d449bc39478f3facfcb0c97c2a35359

See more details on using hashes here.

Provenance

The following attestation bundles were made for sniff_schema-0.1.1-py3-none-any.whl:

Publisher: publish.yml on gitwingo/sniff-schema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page