Skip to main content

askai-python 🚀

A minimal Python SDK to switch between LLM providers in one line.
No frameworks. No servers. No overengineering.

PyPI version License: MIT GitHub


⚡ Quick Start (5 seconds)

pip install "askai-python[openai,groq]"

Provider SDKs are optional. Install the extras you need:

  • pip install "askai-python[openai]" for OpenAI, Azure, and OpenRouter.
  • pip install "askai-python[anthropic]", pip install "askai-python[google]", or pip install "askai-python[groq]" for those providers.
  • pip install "askai-python[all]" for every provider SDK.
from ask_ai import OpenAI, Groq

# Auto-detects OPENAI_API_KEY from environment
print(OpenAI().ask("Explain black holes like I'm 5").text)

# Switch provider instantly
print(Groq().ask("Explain black holes like I'm 5").text)

🧐 Why askai-python?

  • One function: Just call .ask()
  • Multiple providers: OpenAI, Anthropic, Google Gemini, Groq, Azure, OpenRouter
  • Zero config: Keys are pulled from the environment automatically
  • SDK-first, not a framework: It stays out of your way.

🚫 What this project is NOT

❌ Not an AI framework
❌ Not an API gateway
❌ Not an agent memory system

It does one thing perfectly: Simplifying the API call to LLMs.


🛠️ Advanced Usage

🧰 Developer QoL Utilities (Auto-Parsing)

askai-python features parsing banner

Stop writing Regex to clean up model outputs! `askai-python` comes with built-in text processing flags:
from ask_ai import OpenAI
ai = OpenAI()

# 1. Clean Markdown (Removes ```json and ``` tags)
# Perfect for extracting raw data from models that wrap everything in markdown
clean_text = ai.ask("Write JSON", clean=True).text

# 2. Extract Code (Returns ONLY the code block, ignores conversational filler)
# Great for automation pipelines
code = ai.ask("Write a python ping script", code=True).text

# 3. Strip Tags (Removes <think> blocks and HTML)
# Essential for reasoning models like DeepSeek-R1
answer_only = ai.ask("What is 1+1?", strip=True).text

# 4. Enforce & Parse JSON (Directly returns a Parsed Python Dictionary)
# Adds JSON instructions to the prompt and safely runs json.loads()
data_dict = ai.ask("Extract user info", json=True).json
print(data_dict['name'])

🚀 Built-in Resiliency (Retries & Timeouts)

askai-python resiliency banner

Build reliable apps without writing your own loops. askai-python handles rate limits (429) and network drops via an internal exponential backoff.

from ask_ai import OpenAI

ai = OpenAI()

# Automatically retries up to 3 times on transient errors, with a 15-second timeout
response = ai.ask(
    "Write a complex python script", 
    retry=3, 
    timeout=15 
)

🎨 Media Generation (Image & Audio)

Generate images or speech with compatible providers:

from ask_ai import OpenAI

ai = OpenAI()

# Generate an Image (DALL-E)
img_response = ai.ask("A majestic lion in a neon city", output_type="image")
img_response.save("lion.png")

# Generate Speech (TTS)
audio_response = ai.ask("Hello, this is a voice.", output_type="audio")
audio_response.save("welcome.mp3")

🔗 Provider Fallback

Never experience downtime by supplying fallback providers:

from ask_ai import OpenAI, Groq

ai = OpenAI()
response = ai.ask("Explain quantum physics", providers=[ai, Groq])
print(response.text)

📋 Structured Output (Pydantic Support)

Force LLMs to strictly respond matching a Pydantic schema:

from pydantic import BaseModel
from ask_ai import OpenAI

class User(BaseModel):
    name: str
    age: int

ai = OpenAI()
response = ai.ask("Extract name: Alice is 30.", response_model=User)
user = response.pydantic
print(user.name)  # "Alice"

🔌 Supported Providers

Provider Class Capabilities
OpenAI OpenAI Text, Images (DALL-E), Vision
Anthropic Anthropic Text, Vision (Claude 3.5)
Google Google Text, Vision
Groq Groq Ultra-fast Llama 3 & Mixtral
Azure Azure Enterprise-grade OpenAI
OpenRouter OpenRouter 100+ community models

Conversation Sessions

Sessions provide optional in-memory conversation history:

session = OpenAI().session(max_messages=20)
session.ask("My name is Ada.")
print(session.ask("What is my name?").text)

Session state is not persisted, and session requests do not support response_model validation yet.

🗺️ Roadmap

🚀 Roadmap 2.0 (Active)

  • Provider Fallback chaining & Pydantic Structured Output support
  • Optional in-memory conversation sessions
  • Multi-Modal Vision input (image to text) for all key providers
  • Native support for tools/function calling execution

🏁 Roadmap 1.0 (Completed)

  • [x] Baseline multiple providers
  • [x] Automated Retry & Timeout controls
  • [x] Async API (await ask_async)
  • [x] Streaming Support (ask_stream / ask_stream_async)
  • [x] Provider Fallback (fallback=[Groq()])
  • [x] Structured Outputs (Pydantic Support)

Metadata

Release files for askai-python 0.6.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 askai-python 0.6.0
File Size Uploaded Provenance Actions
askai_python-0.6.0.tar.gz 57.7 kB Without provenance Details for askai_python-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for askai-python 0.6.0
File Interpreter ABI Platform Actions
askai_python-0.6.0-py3-none-any.whl Python 3 none any Details for askai_python-0.6.0-py3-none-any.whl

Total release size: 102.4 kB

Release files / askai_python-0.6.0.tar.gz

Download URL askai_python-0.6.0.tar.gz
Size 57.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0176631e97d6e6eae050ccc754ed6188cf7499dd8c1e9415ea54fe56fef84aa9
BLAKE2b-256 checksum
How to use checksums
be574e4e6be70e51b48abd1d1a95048c530045817fb75d2d2434dd060e2aa8b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / askai_python-0.6.0-py3-none-any.whl

Download URL askai_python-0.6.0-py3-none-any.whl
Size 44.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2add7644b09a5cfebb8591ae7d57bde9cd187a76c232457a14c771b40b720211
BLAKE2b-256 checksum
How to use checksums
0100d407dae52f9e203a1c42ec7c8d9add4da2472655e97c8207a6c174401d8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for askai-python 0.6.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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