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, 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.2

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.1.2
File Size Uploaded
simplified_genai-0.1.2.tar.gz 153.3 kB Details

Built distribution (wheel)

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

Total release size: 180.4 kB

Release files / simplified_genai-0.1.2.tar.gz

Download URL simplified_genai-0.1.2.tar.gz
Size 153.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5a3ebceacbe6d370aeaa0e4750c34ffc8401c503441725736513f53e8871aead
BLAKE2b-256 checksum
How to use checksums
b556747e4206500b887094bbf61cbfa649768d8147ddd2623907cc05a12ad429
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

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

Download URL simplified_genai-0.1.2-py3-none-any.whl
Size 27.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab20f7f5f1e71a7ebbf8a234b4c2f8def60f5efa0048586cc87423e6f7344c20
BLAKE2b-256 checksum
How to use checksums
0b99a18be81dbf8ec972fa9d5158eba230cc5a5b976015bc4c8b70f2da362b82
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

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.2 This release

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