Lightweight Python AI client/router with async support, local tools, observability hooks, retries, and structured output.
Project description
JavaxFlash v4.0.0
JavaxFlash is a small Python library for sending prompts to multiple AI providers through one consistent client API.
It focuses on a few practical things:
- simple
client.flash(...)usage - lightweight provider routing between
flashanddeepseek - retry and fallback handling
- structured output parsing
- optional Tavily-backed
searchandextract - local tool injection
- async support
- lightweight session memory
This library is intentionally small. It does not include streaming, and it does not include agent mode in v4.0.0.
Who This Is For
JavaxFlash fits best if you want:
- one compact client for multiple providers
- a cleaner wrapper around prompt calls
- optional grounded answers with web search or extraction
- structured JSON-like output without a large framework
- a library that stays readable and easy to extend
Installation
Install the package:
pip install javaxflash
Optional for Tavily-based search and extract:
pip install tavily-python
Quick Start
from javaxFlash import Client
client = Client()
res = client.flash("Explain the difference between REST and GraphQL in simple terms.")
print(res.text)
print(res.provider)
print(res.model)
print(res.reason)
ask() is just an alias for flash():
res = client.ask("What is Python?")
The Main Idea
Most users only need this mental model:
- Create
Client() - Call
client.flash(...) - Optionally add
provider=,schema=,skills=, ortool_calls= - Read
res.textorres.data
If you start there, the rest of the library feels much simpler.
Core API
Client
Main sync client.
from javaxFlash import Client
client = Client()
res = client.flash("Summarize retry logic in API clients.")
print(res.text)
AsyncClient
Async wrapper for the same API.
import asyncio
from javaxFlash import AsyncClient
async def main() -> None:
client = AsyncClient()
res = await client.flash("Explain exponential backoff simply.")
print(res.text)
asyncio.run(main())
Session
Simple short-term conversation history.
from javaxFlash import Client
client = Client()
session = client.session(max_turns=6)
session.ask("My product is a Python SDK for AI providers.")
res = session.ask("Give me three tagline ideas.")
print(res.text)
Providers
Built-in providers:
flashdeepseek
Let the router choose:
res = client.flash("What is Python used for?")
print(res.provider)
Force a provider:
res = client.flash("Use the flash provider.", provider="flash")
res = client.flash("Analyze this architecture tradeoff.", provider="deepseek")
Routing modes:
fast = client.flash("Summarize HTTP status codes.", mode="fast")
reasoning = client.flash("Compare monolith vs microservices.", mode="reasoning")
Compatibility note:
provider="gemini"is accepted and mapped toflash
Configuration
Use Config when you want to control timeout, retries, fallback, search settings, or hooks.
from javaxFlash import Client, Config
cfg = Config(
timeout=20.0,
retries=3,
backoff=0.5,
backoff_rate=2.0,
backoff_max=8.0,
jitter=0.2,
fallback=True,
)
client = Client(cfg=cfg)
Common fields:
timeoutretriesbackoffbackoff_ratebackoff_maxjitterretry_codesprovidermodelmodelsfallbackfallback_providerauto_routerawauto_searchauto_toolstavily_keysearch_toolsearch_limitsearch_timeouthooks
Environment-based config is also supported:
from javaxFlash import Config
cfg = Config.from_env()
Useful environment variables:
JAVAXFLASH_TIMEOUTJAVAXFLASH_MAX_RETRIESJAVAXFLASH_BACKOFF_BASEJAVAXFLASH_BACKOFF_MULTIPLIERJAVAXFLASH_BACKOFF_MAXJAVAXFLASH_JITTERJAVAXFLASH_DEFAULT_PROVIDERJAVAXFLASH_DEFAULT_MODELJAVAXFLASH_FALLBACK_PROVIDERJAVAXFLASH_PROVIDER_MODELSJAVAXFLASH_AUTO_ROUTEJAVAXFLASH_AUTO_SEARCHJAVAXFLASH_TAVILY_API_KEYJAVAXFLASH_SEARCH_TOOL_NAMEJAVAXFLASH_SEARCH_MAX_RESULTSJAVAXFLASH_SEARCH_TIMEOUT
Retries And Fallback
from javaxFlash import Client, Config, RetryError, TimeoutError
client = Client(
cfg=Config(
timeout=20.0,
retries=3,
fallback=True,
)
)
try:
res = client.flash("Summarize retry strategies for HTTP clients.")
print(res.text)
print(res.retries)
except (TimeoutError, RetryError) as err:
print(err)
Fallback is provider-level. If the chosen provider fails and fallback is enabled, the client can retry the request on another provider.
Structured Output
Use Schema or a dataclass when you want parsed output in res.data.
With Schema
from javaxFlash import Client, Schema
task_schema = Schema(
name="task_summary",
fields={
"title": str,
"priority": str,
"items": [str],
},
)
client = Client()
res = client.flash(
"Turn this into a compact task plan.",
schema=task_schema,
)
print(res.data)
With a dataclass
from dataclasses import dataclass
from javaxFlash import Client
@dataclass
class Ticket:
title: str
priority: str
client = Client()
res = client.flash("Summarize this bug report.", schema=Ticket)
print(res.data.title)
Supported schema shapes include:
- basic Python types
- lists such as
[str] EnumLiteral- optional values such as
str | None - dataclass defaults
Important note:
- structured output depends on the upstream model actually returning valid JSON
- if the provider returns invalid JSON,
SchemaErroris raised
Tools And Skills
There are two different concepts:
1. Local tools
These are Python functions you register yourself.
from javaxFlash import Client
client = Client()
client.register_function(
"project_context",
lambda: {
"title": "Library focus",
"content": "This SDK focuses on multi-provider routing, retries, and structured output.",
},
)
res = client.flash(
"Write a short project summary.",
tool_calls={"project_context": {}},
)
print(res.text)
print(res.tools)
2. Skills
Skills are built-in prompt-grounding helpers currently backed by Tavily:
searchextract
Manual skill usage:
from javaxFlash import Client, Config
client = Client(cfg=Config(tavily_key="your-tavily-api-key"))
res = client.flash(
"What changed in the latest Python release?",
skills="search",
)
print(res.text)
print(res.searched)
print(res.search_query)
res = client.flash(
"Summarize this page: https://docs.python.org/3/whatsnew/",
skills=["extract"],
)
Direct tool-style helpers are also available:
client.use_tavily()
print(client.search("latest Python release", limit=3))
print(client.extract("https://docs.python.org/3/whatsnew/"))
Important behavior:
flash()does not automatically run search by default- manual
skills="search"andskills=["extract"]are supported use_search=Trueis also supported for explicit search usage- tool output is injected as context, and the returned result is still a normal AI response
- raw
ToolRes(...)objects are not returned fromflash(...)
auto_search and auto_tools exist for opt-in behavior, but for most users explicit skill usage is clearer and safer.
Observability Hooks
You can listen to client events through hooks.
from javaxFlash import Client, Config
def log_event(event: str, payload: dict) -> None:
print(event, payload)
client = Client(cfg=Config(hooks=(log_event,)))
res = client.flash("Summarize HTTP retries.")
Common emitted events include:
flash_requestedtool_calledfallback_triggeredresponse_received
Response Object
Each request returns Res.
Common fields:
res.text
res.provider
res.model
res.reason
res.retries
res.latency
res.data
res.skills
res.tools
res.searched
res.search_query
res.search_note
res.skill_note
res.think
res.caps
res.raw is included only when raw=True.
res.think is populated when a provider response contains a hidden <thinking>...</thinking> section and a clean final answer outside it.
Errors
Main exceptions:
ProviderErrorMissingProviderErrorTimeoutErrorRetryErrorSchemaErrorToolError
Example:
from javaxFlash import Client, ToolError
client = Client()
try:
res = client.flash("What is the latest Python release?", skills="search")
print(res.text)
except ToolError as err:
print(err)
Examples
Available examples:
examples/basic_usage.pyexamples/provider_selection.pyexamples/retry_config.pyexamples/structured_output.pyexamples/tavily_search.pyexamples/tool_registration.py
Note for new users:
- examples are meant to be run from the repository root
- examples that use real providers depend on network access
- Tavily examples also require
tavily-pythonand a valid Tavily API key - some structured-output examples may fail if the upstream provider does not return valid JSON for that prompt
Testing
Run tests:
./.venv/bin/pytest -q
Quick syntax check:
python3 -m compileall javaxFlash tests examples
Limitations
- no streaming support
- no built-in agent mode
- output quality still depends on upstream providers
- structured output reliability depends on model compliance
- Tavily-backed features require extra dependency and API access
Version
Current version: 4.0.0
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 javaxflash-4.0.0.tar.gz.
File metadata
- Download URL: javaxflash-4.0.0.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
727e83e58c063bca710b10272ba6674f4f498f2febd1df447058bce9a296fa29
|
|
| MD5 |
a5471dca3646bfa42e6f1fcd637fe31b
|
|
| BLAKE2b-256 |
4c0178c4da9e55513e761d2b61ff9be049aa569997e985400b6b15919ce6a607
|
File details
Details for the file javaxflash-4.0.0-py3-none-any.whl.
File metadata
- Download URL: javaxflash-4.0.0-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7daf813fa5305d9bd53c372ae2d8443519bd2129542a22b49e38087e7a5c335
|
|
| MD5 |
80d7757173e2b381c1c7eeb2f828d9ce
|
|
| BLAKE2b-256 |
cdb786559ef6c6e0d9666b620556228c55fdf37e004ddd850634289ebf954c37
|