IrovanAI
A lightweight, dependency-free Python client for the Irovan AI API.
IrovanAI uses only the Python standard library and provides synchronous and asynchronous chat, persistent HTTP connections, automatic retries, concurrent requests, conversation sessions, and image support.
Features
- Zero third-party runtime dependencies
- Persistent HTTP connections with keep-alive support
- Automatic retries for network errors, HTTP 5xx responses, and rate limits
- Concurrent requests with
chat_many - Conversation sessions with message history
- Image analysis and image generation
- Asynchronous client support
- Command-line interface
- Response caching
- Compatible with Python 3.8 and newer
Installation
Install from PyPI:
pip install irovanai
Install directly from GitHub:
pip install git+https://github.com/irovan/irovanai.git
API Key
Create or manage your API key at Irovan AI.
You can provide the key directly or set the IROVAN_API_KEY environment variable.
Linux and macOS:
export IROVAN_API_KEY="YOUR_API_KEY"
Windows PowerShell:
$env:IROVAN_API_KEY = "YOUR_API_KEY"
Quick Start
from irovanai import Irovan
ai = Irovan(api_key="YOUR_API_KEY")
response = ai.chat("Hello!")
print(response.reply)
If the environment variable is configured, the key can be omitted:
from irovanai import Irovan
ai = Irovan()
print(ai.chat("What is Python?"))
For a one-line request:
from irovanai import ask
print(ask("Hello!", api_key="YOUR_API_KEY"))
Models
Choose a model per request or set a default when creating the client:
ai.chat("Hello!", model="slim")
ai.chat("Explain quantum computing.", model="plus")
Concurrent Requests
Send multiple messages concurrently with chat_many:
messages = [
"Hello!",
"What is Python?",
"Give me a programming tip."
]
responses = ai.chat_many(messages, workers=8)
for response in responses:
print(response.reply)
Responses preserve the order of the input messages. Set return_exceptions=True to return individual errors instead of stopping the operation.
Conversation Sessions
Use a session to maintain conversation history:
session = ai.session(system="You are a helpful assistant.")
print(session.send("My name is Alex.").reply)
print(session.send("What is my name?").reply)
session.reset()
The session history is included in each request because the API processes requests independently.
Image Support
Analyze an image:
response = ai.analyze_image(
"photo.png",
"What is shown in this image?"
)
print(response.reply)
Generate and save an image:
image = ai.generate_image("A fresh cucumber on a clean white background")
image.save("cucumber.png")
Asynchronous Usage
import asyncio
from irovanai import AsyncIrovan
async def main():
ai = AsyncIrovan(api_key="YOUR_API_KEY")
responses = await ai.chat_many([
"Hello!",
"How are you?"
])
for response in responses:
print(response.reply)
ai.close()
asyncio.run(main())
Response Caching
Enable an in-memory cache by setting cache_size:
ai = Irovan(
api_key="YOUR_API_KEY",
cache_size=100
)
Repeated text requests can then reuse cached responses.
Configuration
from irovanai import Irovan
ai = Irovan(
api_key="YOUR_API_KEY",
model="slim",
timeout=120,
retries=2,
cache_size=0
)
| Parameter | Description | Default |
|---|---|---|
api_key |
API key. Can also be provided through IROVAN_API_KEY. |
Environment variable |
model |
Default model for requests. | slim |
base_url |
Irovan API base URL. | https://chat.irovan.ir |
timeout |
Request timeout in seconds. | 120 |
retries |
Number of retry attempts. | 2 |
cache_size |
Maximum number of cached responses. 0 disables caching. |
0 |
Error Handling
IrovanAI provides specific exception classes for common API and network errors:
from irovanai import (
Irovan,
AuthenticationError,
RateLimitError,
NetworkError,
APIError
)
try:
ai = Irovan(api_key="YOUR_API_KEY")
response = ai.chat("Hello!")
print(response.reply)
except AuthenticationError:
print("The API key is missing or invalid.")
except RateLimitError:
print("The request limit has been reached.")
except NetworkError as error:
print(f"Network error: {error}")
except APIError as error:
print(f"API error: {error}")
print(f"HTTP status: {error.status_code}")
Command-Line Interface
Run a single request:
irovanai "Hello!" --model slim
Analyze an image:
irovanai "What is in this picture?" --model plus --image photo.png
Start an interactive session:
irovanai
You can also use the module entry point:
python -m irovanai "Hello!"
Welcome Message
The client displays Welcome irovanai once per process by default.
Disable the message by setting IROVAN_QUIET:
Linux and macOS:
export IROVAN_QUIET=1
Windows PowerShell:
$env:IROVAN_QUIET = "1"
Development and Tests
Clone the repository and install it in editable mode:
git clone https://github.com/irovan/irovanai.git
cd irovanai
pip install -e .
Run the test suite:
python -m unittest discover -s tests -v
Build the distribution packages:
python -m pip install --upgrade build
python -m build
License
IrovanAI is distributed under the MIT License. See LICENSE for details.
Links
- Website: irovan.ir
- AI Platform: chat.irovan.ir
- GitHub: github.com/irovan/irovanai
Metadata
Release files for irovanai 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| irovanai-0.2.2.tar.gz | 15.8 kB | Without provenance | Details for irovanai-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| irovanai-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for irovanai-0.2.2-py3-none-any.whl |
Total release size: 25.9 kB
Release files / irovanai-0.2.2.tar.gz
| Download URL | irovanai-0.2.2.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fbe3ce1636c0b42b5e49dbd1771758d26e7bd43b4a92f6a16ab305721598fa50
|
|
BLAKE2b-256 checksum How to use checksums |
836c8ae7ccdd2f31f4f00db62646ace71e72b24e785b6227b536a5c36821b928
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / irovanai-0.2.2-py3-none-any.whl
| Download URL | irovanai-0.2.2-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
310e4cc52d880ba6cafc6da40131597b881817a29502138ab8ec6b46645cf312
|
|
BLAKE2b-256 checksum How to use checksums |
1b5305092bcdb3deb7d58217b1a6919bf157dab38027ffe36a50848bd5f50347
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for irovanai 0.2.2
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.