SchemaForge Python SDK
AI-Powered Data Structuring Tool
English | 中文
About
This is the official Python SDK for SchemaForge AI, a unified service for AI structured data processing using Pydantic models to define output formats, supporting multiple AI large language models.
Introduction
SchemaForge is a powerful Python SDK for quickly transforming unstructured data into structured formats and generating Pydantic models from text descriptions. It provides an intuitive API for:
- Structuring text data: Convert unstructured text into structured Pydantic models
- Generating models from sample data: Create Pydantic models based on sample data
- Async support: All operations support both synchronous and asynchronous calls
Installation
pip install schemaforge
Quick Start
Initialize Client
from schemaforge import SchemaForge
# Initialize client with API key
client = SchemaForge(api_key="your_secure_api_key_here")
# Or get API key from environment variable
# export SCHEMAFORGE_API_KEY=your_secure_api_key_here
client = SchemaForge()
Structure Text Data
from pydantic import BaseModel
# Define a Pydantic model
class Person(BaseModel):
name: str
age: int
occupation: str
# Structure text using the model
person = client.structure(
content="John is a 30-year-old software engineer",
model_class=Person
)
print(person)
Generate Model from Sample Data
# Sample JSON data
json_sample = '''
{
"product_id": "P12345",
"name": "Smart Watch",
"price": 199.99,
"in_stock": true,
"specifications": {
"screen_size": "6.5 inches",
"processor": "SnapDragon 8",
"storage": "128GB",
"camera": "48MP"
},
"colors": ["Black", "Silver", "Gold"],
"release_date": "2024-01-15"
}
'''
# Generate model from sample data
result = client.generate_model(
sample_data=json_sample,
model_name="Product",
description="Product information model with specifications"
)
if result.get("success"):
# Load the generated model
Product = client.load_model(result["model_code"])
print(Product)
Async Support
import asyncio
from schemaforge import SchemaForge
async def main():
client = SchemaForge(api_key="your_secure_api_key_here")
# Async structure text
person = await client.astructure(
content="Jane is a 25-year-old data scientist",
model_class=Person
)
print(person)
# Async generate model
result = await client.agenerate_model(
sample_data='{"name": "Laptop", "price": 999.99}',
model_name="Laptop",
description="Laptop information model"
)
if result.get("success"):
Laptop = client.load_model(result["model_code"])
print(Laptop)
asyncio.run(main())
Advanced Usage
Custom Configuration
from schemaforge import SchemaForge
# Create client with custom configuration
client = SchemaForge(
api_key="your_secure_api_key_here",
api_base="https://custom-endpoint.schemaforge.ai",
default_model="gpt-4",
timeout=60.0,
max_retries=3,
retry_delay=1.0,
retry_jitter=True,
verbose=True
)
Error Handling
from schemaforge import SchemaForge
from schemaforge.exceptions.api_error import SchemaForgeError
client = SchemaForge(api_key="your_secure_api_key_here")
try:
person = client.structure(
content="Invalid text",
model_class=Person
)
except SchemaForgeError as e:
print(f"Error: {e}")
Further Reading
For complete API documentation and more examples, visit the SchemaForge Documentation.
Metadata
Release files for schemaforge 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| schemaforge-0.1.1.tar.gz | 14.9 kB | Without provenance | Details for schemaforge-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| schemaforge-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for schemaforge-0.1.1-py3-none-any.whl |
Total release size: 31.1 kB
Release files / schemaforge-0.1.1.tar.gz
| Download URL | schemaforge-0.1.1.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b10184fac4f4fa13ffd3d7e968a56376d2aeffc5615e09d043c97b4f5c0d6fe
|
|
BLAKE2b-256 checksum How to use checksums |
16ab2bfdd0137b6f30444e6c49eb7506f28d62871817b253b37c43a5556bb00f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.6
|
Release files / schemaforge-0.1.1-py3-none-any.whl
| Download URL | schemaforge-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d0716c44401f26bb90f27f9eec43dfea69eedd26a846cd6cb7b3ffbd31620c1
|
|
BLAKE2b-256 checksum How to use checksums |
cac4bc3da48c6c79eb04852118b8477702116c95815d147512889aabdc94b3d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.6
|
Security for schemaforge 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.