rstructor 0.3.2

Get structured, validated data out of LLMs as native Rust structs and enums. Derive a type and rstructor generates the JSON Schema, prompts the model, parses the reply, and retries on validation errors — across OpenAI, Anthropic Claude, Google Gemini, and xAI Grok. The Rust answer to Python's Pydantic + Instructor.
Documentation
[package]
name = "rstructor"
version = "0.3.2"
edition = "2024"
description = "Get structured, validated data out of LLMs as native Rust structs and enums. Derive a type and rstructor generates the JSON Schema, prompts the model, parses the reply, and retries on validation errors — across OpenAI, Anthropic Claude, Google Gemini, and xAI Grok. The Rust answer to Python's Pydantic + Instructor."
license = "MIT"
repository = "https://github.com/clifton/rstructor"
authors = ["Clifton King <cliftonk@gmail.com>"]
readme = "README.md"
documentation = "https://docs.rs/rstructor"
exclude = [
  # Release and development scripts
  "release.sh",
  "*.sh",
  # Documentation that shouldn't be in the crate
  "CLAUDE.md",
  "EXAMPLES.md",
  # GitHub workflows
  ".github/",
  # CI/CD configs
  ".gitignore",
  ".gitattributes",
  # Claude/LLM generated or temporary files
  ".claude/",
  # Temporary files directory (ad-hoc scripts, temporary markdown, etc.)
  "tmp/",
  # Backup files from sed/editors
  "*.orig",
  "*.bak",
]
keywords = ["llm", "structured-output", "json-schema", "openai", "anthropic"]
categories = [
  "api-bindings",
  "science",
  "parsing",
  "text-processing",
  "asynchronous",
]

[dependencies]
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
async-trait = "0.1.89"
tokio = { version = "1.52.1", features = [
  "rt",
  "macros",
  "rt-multi-thread",
  "io-std",
], optional = true }
reqwest = { version = "0.13.3", features = [
  "json",
  "query",
  "default-tls",
], default-features = false, optional = true }
thiserror = "2.0.18"
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = [
  "env-filter",
], optional = true }
tracing-futures = { version = "0.2.5", optional = true }
rstructor_derive = { version = "0.3.2", path = "./rstructor_derive", optional = true }
base64 = { version = "0.22.1", optional = true }
futures-util = { version = "0.3.31", default-features = false, optional = true }
async-stream = { version = "0.3.6", optional = true }

# Feature flags
[features]
default = ["openai", "anthropic", "grok", "gemini", "derive", "logging"]
# Each provider pulls in the shared networking + media stack via `_client`.
openai = ["_client"]
anthropic = ["_client"]
grok = ["_client"]
gemini = ["_client"]
derive = ["rstructor_derive"]
logging = ["tracing-subscriber", "tracing-futures"]
# Internal: the HTTP client + media stack shared by every networked provider.
# Not meant to be enabled directly — enable a provider feature instead. Disabling
# all providers yields a dependency-light, schema-only build (derive + schema, no
# tokio/reqwest) suitable for generating JSON Schema without making API calls.
_client = ["reqwest", "tokio", "base64"]
# Opt-in streaming: text (`generate_stream`), object snapshots
# (`materialize_stream`), and list streaming (`materialize_iter`). Enable a
# provider feature too for the HTTP stack.
streaming = ["_client", "reqwest/stream", "futures-util", "async-stream"]
# Opt-in tool/function calling (`Tool`, `Toolbox`, `client.with_tools(..).run(..)`).
# The agentic loop is implemented for all providers (OpenAI, Anthropic, Grok, Gemini).
tools = ["_client"]
# Opt-in in-memory mock client (`MockClient`) for offline unit testing. Pulls in no
# extra dependencies and works in schema-only builds (no `_client`); the streaming
# and tool overrides additionally require the `streaming` / `tools` features.
mock = []

[[example]]
name = "streaming_example"
required-features = ["streaming"]

[[example]]
name = "tool_calling_example"
required-features = ["tools", "openai"]

[[example]]
name = "mock_testing_example"
required-features = ["mock"]

[dev-dependencies]
# Used only by examples and tests (date/time fields, custom types); not part of
# the public dependency closure.
chrono = { version = "0.4.44", features = ["serde"] }
# Drives async tests/examples (e.g. for the `mock` feature, which does not itself
# pull in tokio). Dev-only — excluded from the public dependency closure.
tokio = { version = "1.52.1", features = ["rt", "macros", "rt-multi-thread"] }
# Local HTTP mock server for testing the real provider clients (request building,
# response parsing, retry/re-ask loop) offline, with no API key. Dev-only.
mockito = "1.7.0"

[workspace]
members = ["rstructor_derive"]