Skip to main content

Token-efficient schema language for LLMs with fast Zig backend

Project description

SlimSchema

SlimSchema is a schema language optimized for LLM token efficiency that converts between YAML, Pydantic, and msgspec.

Core Features

  • Token Efficient: Compressed syntax (age: 18..120) saves context window and costs.
  • Deep Validation: Recursive validation for nested objects and dictionaries.
  • Universal Bridge: Convert between formats (Pydantic ↔ YAML ↔ msgspec).

Quick Start

uv pip install slimschema
pip install slimschema

Example

Define a schema with nested types and defaults, validate data, and get a validated Python object.

from slimschema import to_data, to_pydantic

# 1. Define a compact schema (with nested defaults!)
schema = """
user:
  name: str{3..50}
  role: admin | user | guest = "guest"
  settings:
    theme: str = "dark"
    notifications: bool = true
"""

# 2. Validate JSON data (string or dict/list)
# Input missing 'settings' -> defaults apply automatically
data, error = to_data('{"user": {"name": "Alice"}}', schema)

print(data)
# {
#   "user": {
#     "name": "Alice",
#     "role": "guest",
#     "settings": {"theme": "dark", "notifications": True}
#   }
# }

# 3. Convert to Pydantic for your app
UserModel = to_pydantic(schema)
instance = UserModel(**data)
print(instance.user.settings.theme) # "dark"

Full Spec

# Primitives
field: str | int | float | bool | obj

# Default generators
id: str = uuid                 # UUID v4 string
id_v7: str = uuid7             # UUID v7 (time-ordered)
id_ulid: str = ulid            # ULID (sortable)
id_xid: str = xid              # XID (compact, sortable)
id_nano: str = nanoid          # NanoID (URL-safe)
created: datetime = now        # Current datetime
day: date = today              # Current date
ts: int = epoch                # Unix timestamp (seconds)

# Format types
email: email
website: url
birthday: date
timestamp: datetime

# Collections
items: list[str]
tags: set[str]
coords: tuple[float, float]

# Constraints
name: str{3..50}        # Length 3-50
age: 18..120            # Range
code: /^[A-Z]{3}$/      # Regex

# Enums and Unions
status: active | pending | done    # Enum (Literal)
value: str | int                   # Union

# Typed dictionaries
scores: dict[str, int]             # Key-value types

# Inline objects
user: {name: str, age: int, email?: str}

# Optional vs Nullable
?optional_field: str    # Can omit field entirely
nullable_field: str?    # Field required, value can be null
?both: str?             # Optional AND nullable

Default Syntax

count: int = 0
name: str = "default"
items: list = []
created: str = now              # Current datetime
id: str = uuid                  # UUID v4
id2: str = uuid7                # UUID v7 (time-ordered)
id3: str = ulid                 # ULID (sortable)
id4: str = xid                  # XID (compact)
id5: str = nanoid               # NanoID (URL-safe)
ts: int = epoch                 # Unix timestamp (seconds)

API Functions

from slimschema import (
    parse_slimschema,  # YAML string → Schema IR
    to_schema,         # Any input → Schema IR
    to_data,           # JSON string/dict + schema → (data, error)
    to_pydantic,       # Schema → Pydantic model class
    to_msgspec,        # Schema → msgspec Struct class
    to_yaml,           # Schema → YAML string
    SchemaParseError,  # Exception for parse errors
)

Documentation

Guides

Integrations

  • Pydantic: Round-trip conversion and nested models.
  • msgspec: High-performance validation structs.

Reference

API Reference

  • to_data(data, schema): Validate JSON string or dict/list against schema.
  • to_schema(obj): Convert Pydantic/msgspec/YAML to SlimSchema IR.
  • to_yaml(schema): Convert Schema to compact YAML string.
  • to_pydantic(schema): Generate Pydantic models.
  • to_msgspec(schema): Generate msgspec structs.

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.dev4.tar.gz (18.4 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.dev4-py3-none-win_amd64.whl (15.0 kB view details)

Uploaded Python 3Windows x86-64

slimschema-0.0.1.dev4-py3-none-manylinux_2_17_x86_64.whl (14.8 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

slimschema-0.0.1.dev4-py3-none-macosx_11_0_arm64.whl (14.8 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: slimschema-0.0.1.dev4.tar.gz
  • Upload date:
  • Size: 18.4 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.dev4.tar.gz
Algorithm Hash digest
SHA256 2509f30e33615971b2af616e0a27a4ded98939ccb731facb4888a4cf67f934fe
MD5 299992ac8391efcf0ef80d3c7eee7cef
BLAKE2b-256 062ec91f9732177f2cc3db7f07dc9be017dbf363a8d05f43cd734ddc9cf075a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev4.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.dev4-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 235559a48162a69dcb823d8583db9d8681b9351a80dfd6f4026662dfdf7c25cc
MD5 34a5350b97f3c0ef7fb06e7fcae7a403
BLAKE2b-256 a94d5afa1a8c36c9c7fe9323d9a463ba0255fe071ac4552e1f7762a7cd42d86f

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev4-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.dev4-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev4-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 9cfed106d5cf214025e9f629eb66f62364b930582c1810910c88d661ebd8fcd7
MD5 e3eefdc3af917b0e8a1072b545e753ab
BLAKE2b-256 6178623c292552c093b7cc10eb5503392b36a97d13c56ee96b4054b15a2d7d96

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev4-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.dev4-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev4-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e58b5aa6265615beaac8f6cab5abbec3f804d8c879a1c76b967a6685c90417ae
MD5 e2f3fd1ee9227bae8d9fb47afbd4a78b
BLAKE2b-256 71be93202051ebd7b9710c057c80d5fab7de6762e3e766a9494578d962791f23

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev4-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