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
- Syntax Guide: Primitives, constraints, and inline objects.
- Validation Guide: How
to_datavalidates and reports errors. - Defaults Guide: Handling partial data with scalar and nested defaults.
Integrations
Reference
- API Reference: Complete function signatures.
- Error Handling: Validation and parsing errors.
- FAQ: Common questions.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2509f30e33615971b2af616e0a27a4ded98939ccb731facb4888a4cf67f934fe
|
|
| MD5 |
299992ac8391efcf0ef80d3c7eee7cef
|
|
| BLAKE2b-256 |
062ec91f9732177f2cc3db7f07dc9be017dbf363a8d05f43cd734ddc9cf075a4
|
Provenance
The following attestation bundles were made for slimschema-0.0.1.dev4.tar.gz:
Publisher:
on-release-main.yml on botassembly/slimschema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slimschema-0.0.1.dev4.tar.gz -
Subject digest:
2509f30e33615971b2af616e0a27a4ded98939ccb731facb4888a4cf67f934fe - Sigstore transparency entry: 798857398
- Sigstore integration time:
-
Permalink:
botassembly/slimschema@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Branch / Tag:
refs/tags/v0.0.1dev4 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Trigger Event:
release
-
Statement type:
File details
Details for the file slimschema-0.0.1.dev4-py3-none-win_amd64.whl.
File metadata
- Download URL: slimschema-0.0.1.dev4-py3-none-win_amd64.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
235559a48162a69dcb823d8583db9d8681b9351a80dfd6f4026662dfdf7c25cc
|
|
| MD5 |
34a5350b97f3c0ef7fb06e7fcae7a403
|
|
| BLAKE2b-256 |
a94d5afa1a8c36c9c7fe9323d9a463ba0255fe071ac4552e1f7762a7cd42d86f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slimschema-0.0.1.dev4-py3-none-win_amd64.whl -
Subject digest:
235559a48162a69dcb823d8583db9d8681b9351a80dfd6f4026662dfdf7c25cc - Sigstore transparency entry: 798857399
- Sigstore integration time:
-
Permalink:
botassembly/slimschema@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Branch / Tag:
refs/tags/v0.0.1dev4 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Trigger Event:
release
-
Statement type:
File details
Details for the file slimschema-0.0.1.dev4-py3-none-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: slimschema-0.0.1.dev4-py3-none-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cfed106d5cf214025e9f629eb66f62364b930582c1810910c88d661ebd8fcd7
|
|
| MD5 |
e3eefdc3af917b0e8a1072b545e753ab
|
|
| BLAKE2b-256 |
6178623c292552c093b7cc10eb5503392b36a97d13c56ee96b4054b15a2d7d96
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slimschema-0.0.1.dev4-py3-none-manylinux_2_17_x86_64.whl -
Subject digest:
9cfed106d5cf214025e9f629eb66f62364b930582c1810910c88d661ebd8fcd7 - Sigstore transparency entry: 798857402
- Sigstore integration time:
-
Permalink:
botassembly/slimschema@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Branch / Tag:
refs/tags/v0.0.1dev4 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Trigger Event:
release
-
Statement type:
File details
Details for the file slimschema-0.0.1.dev4-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: slimschema-0.0.1.dev4-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e58b5aa6265615beaac8f6cab5abbec3f804d8c879a1c76b967a6685c90417ae
|
|
| MD5 |
e2f3fd1ee9227bae8d9fb47afbd4a78b
|
|
| BLAKE2b-256 |
71be93202051ebd7b9710c057c80d5fab7de6762e3e766a9494578d962791f23
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slimschema-0.0.1.dev4-py3-none-macosx_11_0_arm64.whl -
Subject digest:
e58b5aa6265615beaac8f6cab5abbec3f804d8c879a1c76b967a6685c90417ae - Sigstore transparency entry: 798857404
- Sigstore integration time:
-
Permalink:
botassembly/slimschema@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Branch / Tag:
refs/tags/v0.0.1dev4 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@f0b22c7eebd625a10f389f7f10135ea8ac1a988d -
Trigger Event:
release
-
Statement type: