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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44951d83869eb4ce663fdf04d30af23e9d2895d5b9d54f41275204546e744667
|
|
| MD5 |
e4311a622dbea6e1d8ebff58a406f068
|
|
| BLAKE2b-256 |
7a039e6ca1357833e4bbfaa8bee735574837a12788aad80829ca7a0e7dcae5ac
|
Provenance
The following attestation bundles were made for ai_query-1.7.1.tar.gz:
Publisher:
release.yml on Abdulmumin1/ai-query
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_query-1.7.1.tar.gz -
Subject digest:
44951d83869eb4ce663fdf04d30af23e9d2895d5b9d54f41275204546e744667 - Sigstore transparency entry: 850134005
- Sigstore integration time:
-
Permalink:
Abdulmumin1/ai-query@2a9d6a8bbe1de14efa0a96c0055cc7b40b04c49a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Abdulmumin1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2a9d6a8bbe1de14efa0a96c0055cc7b40b04c49a -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
533addd53979330115021561195e5cb3491ca5974090d086eb6342920704d288
|
|
| MD5 |
dccabd0a93bb703042fae51b3c6e1b4d
|
|
| BLAKE2b-256 |
5dfff23417a2c660a3e0ae7cc1289ecafbe83e91f6a9faeb48130240e09a69aa
|
Provenance
The following attestation bundles were made for ai_query-1.7.1-py3-none-any.whl:
Publisher:
release.yml on Abdulmumin1/ai-query
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_query-1.7.1-py3-none-any.whl -
Subject digest:
533addd53979330115021561195e5cb3491ca5974090d086eb6342920704d288 - Sigstore transparency entry: 850134010
- Sigstore integration time:
-
Permalink:
Abdulmumin1/ai-query@2a9d6a8bbe1de14efa0a96c0055cc7b40b04c49a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Abdulmumin1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2a9d6a8bbe1de14efa0a96c0055cc7b40b04c49a -
Trigger Event:
push
-
Statement type: