Skip to main content

SchemaForge Python SDK

Project description

SchemaForge Python SDK

AI-Powered Data Structuring Tool

GitHub · Documentation · Website

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

schemaforge-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

schemaforge-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file schemaforge-0.1.0.tar.gz.

File metadata

  • Download URL: schemaforge-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.6

File hashes

Hashes for schemaforge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d98cfdbcac10330fd85f3f7645b22398d7af4b7a2a440aa9281cd4cefdf17c69
MD5 b4bcc4410ec475b9b3dde4d8b6463c16
BLAKE2b-256 04c26d08f9cca4092095adbc0dcb28db544ae5bc567237b71dcf992830eacbaf

See more details on using hashes here.

File details

Details for the file schemaforge-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for schemaforge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0550426126be1a369e32120fadbe8a90b22cca6f490783a6144f485d9b89e26c
MD5 9f4210c01a7582f49698dc02e35541f9
BLAKE2b-256 922c4b80ac79fe19e3e0ee82e7be654c27e759dc6617baecee486cc63dd8904f

See more details on using hashes here.

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