Skip to main content

A unified Python SDK for querying AI models from multiple providers

Project description

ai-query

A unified Python SDK for querying AI models from multiple providers with a consistent interface.

Installation

uv add ai-query
# or
pip install ai-query

For MCP (Model Context Protocol) support:

uv add ai-query[mcp]
# or
pip install ai-query[mcp]

Quick Start

import asyncio
from ai_query import generate_text
from ai_query.providers import openai

async def main():
    result = await generate_text(
        model=openai("gpt-4o"),
        prompt="What is the capital of France?"
    )
    print(result.text)

asyncio.run(main())

Streaming

from ai_query import stream_text
from ai_query.providers import google

async def main():
    result = stream_text(
        model=google("gemini-2.0-flash"),
        prompt="Write a short story."
    )

    async for chunk in result.text_stream:
        print(chunk, end="", flush=True)

    usage = await result.usage
    print(f"\nTokens: {usage.total_tokens}")

Stateful Agents

ai-query provides a powerful Actor-based Agent class for building stateful AI applications that maintain memory and identity.

from ai_query.agents import Agent, SQLiteStorage
from ai_query.providers import openai

async def main():
    # Persistent agent with SQLite storage
    agent = Agent(
        "my-assistant",
        model=openai("gpt-4o"),
        storage=SQLiteStorage("agents.db")
    )

    async with agent:
        # Agent remembers conversation history automatically
        response = await agent.chat("Hi, I'm Alice!")
        print(response)

        response = await agent.chat("What's my name?")
        print(response) # "Your name is Alice."

asyncio.run(main())

Tool Calling

Define tools using the @tool decorator. The library handles the execution loop automatically.

from ai_query import generate_text, tool, Field
from ai_query.providers import google

@tool(description="Get the current weather for a location")
async def get_weather(
    location: str = Field(description="City name")
) -> str:
    return f"Weather in {location}: 72°F, Sunny"

async def main():
    result = await generate_text(
        model=google("gemini-2.0-flash"),
        prompt="What's the weather in Paris?",
        tools={"weather": get_weather},
    )
    print(result.text)

asyncio.run(main())

MCP (Model Context Protocol) Support

Connect to any MCP server and use its tools seamlessly.

from ai_query import generate_text
from ai_query.providers import google
from ai_query.mcp import mcp

async def main():
    async with mcp("npx", "-y", "@modelcontextprotocol/server-fetch") as server:
        result = await generate_text(
            model=google("gemini-2.0-flash"),
            prompt="Fetch and summarize https://example.com",
            tools=server.tools,
        )
        print(result.text)

asyncio.run(main())

Modular Imports

The library is divided into clean modules:

  • ai_query: Core generation functions (generate_text, stream_text, embed, tool, Field).
  • ai_query.agents: Stateful orchestration (Agent, AgentServer, MemoryStorage, SQLiteStorage).
  • ai_query.providers: Model gateways (openai, anthropic, google, deepseek, groq, etc.).
  • ai_query.mcp: Model Context Protocol integration.
  • ai_query.types: Data models and types.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_query-1.7.1.tar.gz (587.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_query-1.7.1-py3-none-any.whl (71.2 kB view details)

Uploaded Python 3

File details

Details for the file ai_query-1.7.1.tar.gz.

File metadata

  • Download URL: ai_query-1.7.1.tar.gz
  • Upload date:
  • Size: 587.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_query-1.7.1.tar.gz
Algorithm Hash digest
SHA256 44951d83869eb4ce663fdf04d30af23e9d2895d5b9d54f41275204546e744667
MD5 e4311a622dbea6e1d8ebff58a406f068
BLAKE2b-256 7a039e6ca1357833e4bbfaa8bee735574837a12788aad80829ca7a0e7dcae5ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_query-1.7.1.tar.gz:

Publisher: release.yml on Abdulmumin1/ai-query

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_query-1.7.1-py3-none-any.whl.

File metadata

  • Download URL: ai_query-1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 71.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_query-1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 533addd53979330115021561195e5cb3491ca5974090d086eb6342920704d288
MD5 dccabd0a93bb703042fae51b3c6e1b4d
BLAKE2b-256 5dfff23417a2c660a3e0ae7cc1289ecafbe83e91f6a9faeb48130240e09a69aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_query-1.7.1-py3-none-any.whl:

Publisher: release.yml on Abdulmumin1/ai-query

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page