SchemaForge Python SDK
Project description
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.
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 Distribution
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 schemaforge-0.1.1.tar.gz.
File metadata
- Download URL: schemaforge-0.1.1.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b10184fac4f4fa13ffd3d7e968a56376d2aeffc5615e09d043c97b4f5c0d6fe
|
|
| MD5 |
7c92724d2492184b613b52461e3d6c0c
|
|
| BLAKE2b-256 |
16ab2bfdd0137b6f30444e6c49eb7506f28d62871817b253b37c43a5556bb00f
|
File details
Details for the file schemaforge-0.1.1-py3-none-any.whl.
File metadata
- Download URL: schemaforge-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d0716c44401f26bb90f27f9eec43dfea69eedd26a846cd6cb7b3ffbd31620c1
|
|
| MD5 |
2eaafd8c8d52b0c97ac949471c517e5a
|
|
| BLAKE2b-256 |
cac4bc3da48c6c79eb04852118b8477702116c95815d147512889aabdc94b3d6
|