Observed since 20 Oct, 21:13 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
LLM API library for students utilizing local agents or remote APIs
A simple, student-friendly procedural Python library providing a uniform interface to LLMs. afsar prioritizes installed local coding agents (claude-code, antigravity) so students can use their existing agents and tools, and smoothly falls back to remote cloud APIs (Gemini, OpenAI).
Install via pip:
pip install afsar
import afsar
# Setup is explicit and required once before asking
afsar.setup()
answer = afsar.ask("How do you define a function in Python?")
print(answer)
@dataclassYou don't need Pydantic to get typed objects. Standard Python dataclasses work out of the box:
from dataclasses import dataclass
import afsar
@dataclass
class QuizQuestion:
question: str
points: int
topic: str
afsar.setup()
quiz = afsar.ask("Create a beginner Python question.", schema=QuizQuestion)
print(quiz.question)
print(f"Points: {quiz.points}")
print(f"Topic: {quiz.topic}")
If you just want a JSON-formatted string:
import afsar
afsar.setup()
raw_json = afsar.ask("List 3 Python data structures.", format="json")
print(raw_json) # Returns clean JSON string
When using local agents (claude or agy), afsar defaults to tools=["python", "files"]. This allows asking the agent to write and test code locally:
import afsar
afsar.setup()
response = afsar.ask(
"Write a solution to check if a word is a palindrome, save it to palindrome.py, run it with python, and show the result."
)
print(response)
Remote models do not support local file or execution tools. When connecting to remote APIs, explicitly pass tools=[]:
import afsar
# Using Gemini
afsar.setup(provider="gemini", api_key="YOUR_GEMINI_KEY", tools=[])
# Or using OpenAI
afsar.setup(provider="openai", api_key="YOUR_OPENAI_KEY", tools=[])
answer = afsar.ask("Explain recursion in simple terms.")
print(answer)
Calling afsar.setup() without arguments automatically searches for available providers in this order:
claude) in PATHagy) in PATHGEMINI_API_KEY in environment)OPENAI_API_KEY in environment)You can override the provider explicitly in code:
afsar.setup(provider="agy")
Or via the AFSAR_PROVIDER environment variable:
export AFSAR_PROVIDER=agy
NotSetupError: Raised if afsar.ask() is called before afsar.setup().UnsupportedFeatureError: Raised if requesting local tools (tools=["python", "files"]) on remote API providers.ModelNotFoundError: Raised if no supported local CLI or remote API key is discovered.ExecutionError: Raised if a CLI command or remote API request fails.Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0 | 13 Oct 2026 | 6 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 21:13 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:2041c9cfc84832828599c087404508e44d178016fd48d596a870b83b9f52f6ce