Skip to main content

Token-efficient schema language for LLMs with fast Zig backend

Project description

SlimSchema

SlimSchema is a schema toolkit with two entry points:

  • SlimSchema YAML (Zig-first): a compact, YAML-shaped schema language for token-efficient prompts and interop.
  • Spec API (typed-first): derive JSON Schema + validation from language types:
    • Python: @spec decorator on dataclasses
    • Zig: Spec(T) for comptime schema generation

Both surfaces are intended to share the same core concepts (constraints, formats, defaults, error paths) while targeting different workflows.

Python Quickstart (@spec)

uv pip install slimschema
pip install slimschema
from typing import Annotated

from slimschema import Alias, Len, Range, spec


@spec
class User:
    user_name: Annotated[str, Alias("userName"), Len(1, 50)]
    age: Annotated[int, Range(0, 120)]

# Load from JSON (mirrors json.loads)
user = User.loads('{"userName": "Alice", "age": 30}')
assert user.user_name == "Alice"
assert user.age == 30

# Dump to JSON (mirrors json.dumps)
json_str = user.dumps()

# Load from dict (mirrors json.load)
user2 = User.load({"userName": "Bob", "age": 25})

# Dump to dict (mirrors dataclasses.asdict)
data = user2.dump()
assert data == {"userName": "Bob", "age": 25}

Zig Quickstart (YAML + Spec(T))

YAML DSL:

const slimschema = @import("slimschema");

const yaml =
    \\name: str{1..50}
    \\age: 0..120
;

Typed spec:

const slimschema = @import("slimschema");

const User = struct { name: []const u8, age: i64 };
pub const user_json_schema = slimschema.jsonSchemaFromType(User);

SlimSchema YAML (Full Spec)

# Primitives
name: str                    # string
age: int                     # integer
score: float                 # floating point number
active: bool                 # boolean (true/false)
meta: obj                    # any object/dict
anything: any                # any JSON value

# Format types (validated)
email: email                 # email address
website: url                 # URL (http/https)
birthday: date               # date (YYYY-MM-DD)
timestamp: datetime          # ISO datetime
user_id: uuid                # UUID format

# Constraints
username: str{3..50}         # string length 3-50 chars
age_range: 18..120           # integer range 18-120
code: /^[A-Z]{3}$/           # regex pattern match

# Collections
tags: list[str]              # array of strings
unique_ids: set[int]         # array of unique integers
coords: tuple[float, float]  # fixed-length tuple [x, y]
scores: dict[str, int]       # object with string keys, int values

# Enums and Unions
status: active | pending     # enum: one of these values
value: str | int             # union: string OR integer

# Optional vs Nullable
?nickname: str               # ? prefix: field can be omitted
rating: float?               # ? suffix: value can be null
?notes: str?                 # both: omittable AND nullable

# Hidden fields (excluded from LLM prompts)
_internal_id: str            # _ prefix: hidden field
_?debug_info: str            # hidden + optional

# Default values
count: int = 0               # literal default
role: str = "user"           # quoted string default
items: list = []             # empty list default
config: dict = {}            # empty dict default

# Default generators (auto-generated if omitted)
id: uuid = uuid              # UUID v4
id_v7: uuid = uuid7          # UUID v7 (time-ordered)
id_ulid: str = ulid          # ULID (sortable, 26 chars)
id_xid: str = xid            # XID (compact, 20 chars)
id_nano: str = nanoid        # NanoID (URL-safe, 21 chars)
created: datetime = now      # current UTC datetime
day: date = today            # current UTC date
ts: int = epoch              # unix timestamp (seconds)

# Nested objects (indentation-based)
user:                        # parent field with nested structure
  name: str                  # child field
  age: int
  address:                   # deeply nested
    street: str
    city: str
    zip: str{5..10}

# Inline objects (single-line syntax)
point: {x: float, y: float}  # compact object definition

# YAML list syntax (array of objects)
issues:                      # parent field becomes array
  - file: str                # first field on dash line
    line: int                # additional fields indented
    severity: str
    message: str

# Complex example: API response schema
response:
  success: bool
  data:
    total: int
    page: 1..100
    items:                   # nested list
      - id: uuid
        name: str{1..100}
        ?tags: list[str]
        created: datetime
  ?error: str

Documentation

  • docs/README.md (start here)
  • docs/WHY.md (architecture decisions: Python/Zig split, when to use each API)
  • docs/python/README.md (Python @spec)
  • docs/zig/README.md (Zig YAML + Spec(T))
  • docs/dev-guide.md (development workflow)
  • DOCS_INVENTORY.md (doc gaps + migration plan)

Development

make build
make test
make coverage

Zig tests:

cd zig && zig build test

License

MIT

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

slimschema-0.0.1.dev7.tar.gz (36.3 kB view details)

Uploaded Source

Built Distributions

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

slimschema-0.0.1.dev7-py3-none-win_amd64.whl (21.7 kB view details)

Uploaded Python 3Windows x86-64

slimschema-0.0.1.dev7-py3-none-manylinux_2_17_x86_64.whl (1.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

slimschema-0.0.1.dev7-py3-none-macosx_11_0_arm64.whl (680.3 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file slimschema-0.0.1.dev7.tar.gz.

File metadata

  • Download URL: slimschema-0.0.1.dev7.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slimschema-0.0.1.dev7.tar.gz
Algorithm Hash digest
SHA256 c20d892bc46931a49ad47eed0fc5ba7388778e7ced388a2c2e0455650b48fc2b
MD5 bfee3584af8da4f4e4a91804d823675c
BLAKE2b-256 ead78ff303710e25ed4e026836b3c31a7aeca74aa4652fa1a8c2882da4710c18

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev7.tar.gz:

Publisher: on-release-main.yml on botassembly/slimschema

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

File details

Details for the file slimschema-0.0.1.dev7-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev7-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ca60596b7ab54c49aae72ad9da834e2488a2e33c0d84753411e5c0a38296a0e2
MD5 5da851b44ab8b39329ab8075da4d896f
BLAKE2b-256 1468889504827076e98858ce525277be148b87ad772680a3262204af803bb332

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev7-py3-none-win_amd64.whl:

Publisher: on-release-main.yml on botassembly/slimschema

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

File details

Details for the file slimschema-0.0.1.dev7-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev7-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 7afdab5ae602306aa7b5ab03461da230c4c16f879007fe94c7b22d47296cde9f
MD5 10e3cf4c14ef52ca45727df025424ab1
BLAKE2b-256 35897a679b2a109995f0ab245d3aa990301bb2767075f3b23dc4bdbd5fb0ba00

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev7-py3-none-manylinux_2_17_x86_64.whl:

Publisher: on-release-main.yml on botassembly/slimschema

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

File details

Details for the file slimschema-0.0.1.dev7-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev7-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec4ed3cf8e3a8aa9325c3a6cc33d5868ef7d8f1ded9b09e76597ad6093200b95
MD5 048ab2235eb5daa05b2748f03bb49e3d
BLAKE2b-256 c81b37a0f46fdb2c6c9cad3b4ce25b6258ee7bd224410b3feb06a3023a0e37b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev7-py3-none-macosx_11_0_arm64.whl:

Publisher: on-release-main.yml on botassembly/slimschema

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