Aiven Client Library
The aiven-client library provides both a command-line client (`avn`) and a Python API for interacting with Aiven.io services. It's actively maintained with frequent minor releases, currently at version 4.13.0, introducing new features and deprecating older ones regularly.
Common errors
-
ModuleNotFoundError: No module named 'aiven'
cause The `aiven-client` library is not installed or the Python environment is incorrect.fixInstall the library using `pip install aiven-client`. Ensure you are running your script with the Python interpreter where the library was installed. -
aiven.client.client.AivenError: Authentication required
cause The AivenClient was initialized without a valid API token, or the provided token is expired/incorrect.fixSet the `AIVEN_TOKEN` environment variable with your Aiven API token before running your script, or pass a valid `auth_token` directly to the `AivenClient` constructor. -
AttributeError: 'AivenClient' object has no attribute 'get_teams'
cause You are trying to call a method that was part of a deprecated feature (`teams`) and has been removed from the client library.fixRefer to the Aiven documentation for current methods of managing user access and permissions, which no longer involve 'teams' functionality programmatically in the client library.
Warnings
- breaking Python 3.9 support was dropped. Ensure your environment uses Python 3.10 or newer.
- breaking The `teams` commands and related API methods have been removed.
- breaking Python 3.8 support was dropped. Ensure your environment uses Python 3.9 or newer.
- breaking Support for InfluxDB services was dropped.
- breaking Aiven Redis services were replaced with Aiven Valkey services. While many operations remain similar, some Redis-specific commands or attributes may have changed.
- gotcha API token authentication is mandatory for programmatic access. Using an invalid or expired token will result in authentication errors.
Install
-
pip install aiven-client
Imports
- AivenClient
from aiven.client import AivenClient
Quickstart
import os
from aiven.client import AivenClient
aiven_api_token = os.environ.get("AIVEN_TOKEN", "")
if not aiven_api_token:
print("Please set the AIVEN_TOKEN environment variable with your Aiven API token.")
else:
try:
client = AivenClient(auth_token=aiven_api_token)
projects = client.get_projects()
print(f"Successfully connected to Aiven. Found {len(projects)} projects:")
for project in projects:
print(f" - {project['project_name']}")
except Exception as e:
print(f"Error connecting or listing projects: {e}")