Skip to main content

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: IChatSessionStore protocol with a built-in InMemoryChatSessionStore for 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

async def main():
    provider = GeminiGenAiProvider(
        api_key="YOUR_GEMINI_API_KEY",
        default_model="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

class CapitalCity(BaseModel):
    country: str
    capital: str
    population_millions: float

async def main():
    provider = GptGenAiProvider(
        api_key="YOUR_OPENAI_API_KEY",
        default_model="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, 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",
        default_model="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,
    GeminiGenAiProvider,
    GenAiChatMessage,
    GenAiChatMessageRole,
    InMemoryChatSessionStore,
)

async def main():
    provider = GeminiGenAiProvider(
        api_key="YOUR_GEMINI_API_KEY",
        default_model="gemini-2.5-flash",
    )
    chat_service = ChatSessionService(store=InMemoryChatSessionStore())
    session_id = chat_service.start_session()

    # First turn
    user_prompt = "Hello! My name is Alice."
    history = await chat_service.get_history(session_id)

    response = await provider.get_raw_text_response(
        user_prompt=user_prompt,
        messages=history,
    )
    print(f"Assistant: {response}")

    await chat_service.append_turn(
        session_id=session_id,
        user_message=GenAiChatMessage(role=GenAiChatMessageRole.USER, content=user_prompt),
        assistant_message=GenAiChatMessage(role=GenAiChatMessageRole.ASSISTANT, content=response),
    )

    # Follow-up turn with conversation history
    follow_up_prompt = "What is my name?"
    history = await chat_service.get_history(session_id)

    response = await provider.get_raw_text_response(
        user_prompt=follow_up_prompt,
        messages=history,
    )
    print(f"Assistant: {response}")

asyncio.run(main())

License

This project is licensed under the MIT License.

Metadata

Release files for simplified-genai 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simplified-genai 0.2.1
File Size Uploaded
simplified_genai-0.2.1.tar.gz 132.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simplified-genai 0.2.1
File Interpreter ABI Platform
simplified_genai-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 158.7 kB

Release files / simplified_genai-0.2.1.tar.gz

Download URL simplified_genai-0.2.1.tar.gz
Size 132.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4cf37bbe12477f2e5ba9a5c34698ec5466e4c3fcf8040df4b852a53f56a7bb25
BLAKE2b-256 checksum
How to use checksums
1bb326788ec4eeb9686883a5d4a02907c224810f7e20bbf507b693510e127d89
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 18, 2026.

Transparency log

Release files / simplified_genai-0.2.1-py3-none-any.whl

Download URL simplified_genai-0.2.1-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5dd5e1faaffb32d15f1415565a20ab466fa0bc04aee230ec761fb2ff2a3ed6cf
BLAKE2b-256 checksum
How to use checksums
a25f1e0f0b92df0c7fda2d45555a64c7df42400aa2060cde523d35c345095109
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 18, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page