Python SDK
Official Python SDK for Tenzro with both synchronous and asynchronous support. Perfect for data science, machine learning workflows, and backend applications.
PyPI package
Type hints
Async support
Jupyter ready
Installation
Install Python SDKbash
# Install with pip
pip install tenzro
# Install with async support
pip install tenzro[async]
# Install with all optional dependencies
pip install tenzro[all]
# Install from source
pip install git+https://github.com/tenzro/python-sdk.git
Quick Start
Basic Synchronous Usagepython
import tenzro
from tenzro import Tenzro
# Initialize the client
client = Tenzro(api_key="sk_your_key_here")
# Generate text with AI
response = client.cortex.generate(
prompt="Write a hello world function in Python",
model="gpt-4o",
max_tokens=1000
)
print(response.content)
print(f"Tokens used: {response.tokens_used}")
print(f"Cost: ${response.cost_estimate}")
Asynchronous Usage
Async/Await with Concurrent Requestspython
import asyncio
from tenzro import AsyncTenzro
async def main():
# Initialize async client
async_client = AsyncTenzro(api_key="sk_your_key_here")
try:
# Generate text asynchronously
response = await async_client.cortex.generate(
prompt="Explain quantum computing",
model="claude-3.5-sonnet",
max_tokens=1000
)
print(response.content)
# Multiple concurrent requests
tasks = [
async_client.cortex.generate(
prompt=f"Explain {topic}",
model="gpt-4o"
)
for topic in ["AI", "blockchain", "cloud computing"]
]
results = await asyncio.gather(*tasks)
for i, result in enumerate(results):
print(f"Topic {i+1}: {result.content[:100]}...")
finally:
await async_client.close()
# Run the async function
asyncio.run(main())
Data Science Integration
Pandas & Data Analysispython
import pandas as pd
from tenzro import Tenzro
client = Tenzro()
# Load dataset
df = pd.read_csv("sales_data.csv")
# Generate insights with AI
data_summary = df.describe().to_string()
response = client.cortex.generate(
prompt=f"""
Analyze this sales dataset and provide insights:
{data_summary}
Provide 3 key insights and recommendations for improvement.
""",
model="claude-3.5-sonnet",
max_tokens=1000
)
print("AI Analysis:")
print(response.content)
# Process each row with AI
insights = []
for index, row in df.head().iterrows():
insight = client.cortex.generate(
prompt=f"Analyze this sales record: {row.to_dict()}",
model="gpt-4o",
max_tokens=200
)
insights.append(insight.content)
# Add insights back to dataframe
df_sample = df.head().copy()
df_sample['ai_insights'] = insights
print(df_sample[['product', 'sales', 'ai_insights']])
Key Features
Async/Sync Support
Both synchronous and asynchronous APIs for maximum flexibility
Data Science Ready
Seamless integration with pandas, numpy, matplotlib, and Jupyter
ML Framework Compatible
Works with PyTorch, TensorFlow, scikit-learn, and Hugging Face
Type Hints
Complete type annotations for better IDE support and code quality
Streaming Support
Real-time streaming for chat, text generation, and live data
Robust Error Handling
Comprehensive error types with retry logic and rate limiting
Next Steps
Need help? Check out our Quick Start guide or contact support