simplified-genai
A streamlined, unified Generative AI abstraction layer for Python supporting Google Gemini, OpenAI GPT, and xAI Grok.
Features
- Unified Provider Interface (
IGenAiProvider): Switch seamlessly between Gemini, GPT, and Grok without rewriting code. - Structured Outputs: Direct type-safe deserialization into Pydantic models with schema enforcement.
- Python Function Calling / Tool Use (
ToolDefinition): Automatic JSON schema generation from standard Python functions and type hints. - Multimodal File Uploads: Uniform file uploading and handling across multimodal models.
- Decoupled Chat Sessions:
IChatSessionStoreprotocol with a built-inInMemoryChatSessionStorefor instant local usage or testing. - Provider Factory (
GenAiProviderFactory): Dynamic primary and fallback provider resolution.
Installation
pip install simplified-genai
Or using uv:
uv add simplified-genai
Quickstart
1. Basic Text Generation
import asyncio
from simplified_genai import GeminiGenAiProvider, GenAiModel
async def main():
provider = GeminiGenAiProvider(
api_key="YOUR_GEMINI_API_KEY",
supported_models=[GenAiModel.GEMINI_2_5_FLASH],
default_model=GenAiModel.GEMINI_2_5_FLASH,
)
response = await provider.get_raw_text_response(
user_prompt="Explain quantum computing in one sentence."
)
print(response)
asyncio.run(main())
2. Structured Output with Pydantic
import asyncio
from pydantic import BaseModel
from simplified_genai import GptGenAiProvider, GenAiModel
class CapitalCity(BaseModel):
country: str
capital: str
population_millions: float
async def main():
provider = GptGenAiProvider(
api_key="YOUR_OPENAI_API_KEY",
supported_models=[GenAiModel.GPT_5_NANO],
default_model=GenAiModel.GPT_5_NANO,
)
result = await provider.get_structured_response(
schema=CapitalCity,
user_prompt="What is the capital of France?",
)
print(f"{result.capital}, {result.country} (Pop: {result.population_millions}M)")
asyncio.run(main())
3. Tool Calling / Function Calling
import asyncio
from simplified_genai import GeminiGenAiProvider, GenAiModel, ToolDefinition
def get_weather(location: str) -> str:
"""Get the current weather for a given location."""
return f"Weather in {location} is 22°C and sunny."
weather_tool = ToolDefinition(
function=get_weather,
description="Get current weather in a city"
)
async def main():
provider = GeminiGenAiProvider(
api_key="YOUR_GEMINI_API_KEY",
supported_models=[GenAiModel.GEMINI_2_5_FLASH],
default_model=GenAiModel.GEMINI_2_5_FLASH,
)
response = await provider.get_raw_text_response(
user_prompt="What's the weather in Tokyo?",
tools=[weather_tool],
)
print(response)
asyncio.run(main())
4. Chat Session Management
import asyncio
from simplified_genai import (
ChatSessionService,
InMemoryChatSessionStore,
GenAiChatMessage,
GenAiChatMessageRole,
)
async def main():
# Use the built-in in-memory store, or implement IChatSessionStore for Redis/Postgres/Mongo
store = InMemoryChatSessionStore()
chat_service = ChatSessionService(store=store)
session_id = chat_service.start_session()
await chat_service.append_turn(
session_id=session_id,
user_message=GenAiChatMessage(role=GenAiChatMessageRole.USER, content="Hello!"),
assistant_message=GenAiChatMessage(role=GenAiChatMessageRole.ASSISTANT, content="Hi there! How can I help?"),
)
history = await chat_service.get_history(session_id)
for msg in history:
print(f"[{msg.role}]: {msg.content}")
asyncio.run(main())
License
This project is licensed under the MIT License.
Metadata
Release files for simplified-genai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simplified_genai-0.1.0.tar.gz | 153.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simplified_genai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 180.3 kB
Release files / simplified_genai-0.1.0.tar.gz
| Download URL | simplified_genai-0.1.0.tar.gz |
|---|---|
| Size | 153.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95bead3919319fcb335af46360aa4363c9f4858603eba3642f9add518e068ba2
|
|
BLAKE2b-256 checksum How to use checksums |
f806172d9384bdf4ffda229bc6d08674a136eaee53a7a4966ece57872a5043ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logRelease files / simplified_genai-0.1.0-py3-none-any.whl
| Download URL | simplified_genai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef43327823520cefad89c8533ebd6ce4ac9bb20077bc66151e647f49cd716f55
|
|
BLAKE2b-256 checksum How to use checksums |
be50151bebd133fc68eb19ee9a3f91f8c637d85cf8d1b2dc0bf88b5568e5680c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency log