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

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.0
File Size Uploaded
simplified_genai-0.2.0.tar.gz 132.3 kB Details

Built distribution (wheel)

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

Total release size: 158.6 kB

Release files / simplified_genai-0.2.0.tar.gz

Download URL simplified_genai-0.2.0.tar.gz
Size 132.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6d0cc6fc18745ce72ba2845f8a459219b14bb4934c8e7f80e9ab87871268961b
BLAKE2b-256 checksum
How to use checksums
2c8d114a030cf26967f4932c1e435ccc4b9db13ef76722efa66194e1e58c5a2c
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.0-py3-none-any.whl

Download URL simplified_genai-0.2.0-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
740d757559db5c467a631da614ec62ec8a02e50f1b56c8660489d3b61aec4e85
BLAKE2b-256 checksum
How to use checksums
74f66027394d0bb338d82f680a0bc0848f290e6b0a37a2a2ac18d7ad8e820b24
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

0.2.1

2 release files

This release

0.2.0 This release

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